Small fixes after full file review

- Remove unnecessary field 'project' from GQl and regenerate
- Add newlines to file ends
- Fix command-line manager user addition
This commit is contained in:
Christoph Kluge 2023-02-23 12:33:14 +01:00
parent a7d2d2666a
commit 8bd72ce807
17 changed files with 18 additions and 79 deletions

View File

@ -161,7 +161,6 @@ type Count {
type User {
username: String!
name: String!
project: String
email: String!
}

View File

@ -72,7 +72,7 @@ func main() {
flag.BoolVar(&flagMigrateDB, "migrate-db", false, "Migrate database to supported version and exit")
flag.BoolVar(&flagLogDateTime, "logdate", false, "Set this flag to add date and time to log messages")
flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`")
flag.StringVar(&flagNewUser, "add-user", "", "Add a new user. Argument format: `<username>:[admin,support,api,user]:<password>`")
flag.StringVar(&flagNewUser, "add-user", "", "Add a new user. Argument format: `<username>:[admin,support,manager,api,user]:<password>`")
flag.StringVar(&flagDelUser, "del-user", "", "Remove user by `username`")
flag.StringVar(&flagGenJWT, "jwt", "", "Generate and print a JWT for the user specified by its `username`")
flag.StringVar(&flagImportJob, "import-job", "", "Import a job. Argument format: `<path-to-meta.json>:<path-to-data.json>,...`")
@ -141,9 +141,8 @@ func main() {
log.Fatal("invalid argument format for user creation")
}
var emptyPrj []string
if err := authentication.AddUser(&auth.User{
Username: parts[0], Projects: emptyPrj, Password: parts[2], Roles: strings.Split(parts[1], ","),
Username: parts[0], Projects: make([]string, 0), Password: parts[2], Roles: strings.Split(parts[1], ","),
}); err != nil {
log.Fatalf("adding '%s' user authentication failed: %v", parts[0], err)
}

View File

@ -169,7 +169,7 @@ func (auth *Authentication) RemoveRole(ctx context.Context, username string, rol
}
if role == RoleManager && len(user.Projects) != 0 {
return fmt.Errorf("Cannot remove role 'manager' while user %s still has an assigned project(s) : %v", username, user.Projects)
return fmt.Errorf("Cannot remove role 'manager' while user %s still has assigned project(s) : %v", username, user.Projects)
}
var exists bool

View File

@ -256,7 +256,6 @@ type ComplexityRoot struct {
User struct {
Email func(childComplexity int) int
Name func(childComplexity int) int
Project func(childComplexity int) int
Username func(childComplexity int) int
}
}
@ -1308,13 +1307,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.User.Name(childComplexity), true
case "User.project":
if e.complexity.User.Project == nil {
break
}
return e.complexity.User.Project(childComplexity), true
case "User.username":
if e.complexity.User.Username == nil {
break
@ -1560,7 +1552,6 @@ type Count {
type User {
username: String!
name: String!
project: String
email: String!
}
@ -3904,8 +3895,6 @@ func (ec *executionContext) fieldContext_Job_userData(ctx context.Context, field
return ec.fieldContext_User_username(ctx, field)
case "name":
return ec.fieldContext_User_name(ctx, field)
case "project":
return ec.fieldContext_User_project(ctx, field)
case "email":
return ec.fieldContext_User_email(ctx, field)
}
@ -6049,8 +6038,6 @@ func (ec *executionContext) fieldContext_Query_user(ctx context.Context, field g
return ec.fieldContext_User_username(ctx, field)
case "name":
return ec.fieldContext_User_name(ctx, field)
case "project":
return ec.fieldContext_User_project(ctx, field)
case "email":
return ec.fieldContext_User_email(ctx, field)
}
@ -8543,47 +8530,6 @@ func (ec *executionContext) fieldContext_User_name(ctx context.Context, field gr
return fc, nil
}
func (ec *executionContext) _User_project(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_User_project(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.Project, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.(*string)
fc.Result = res
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_User_project(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "User",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type String does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _User_email(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_User_email(ctx, field)
if err != nil {
@ -12444,10 +12390,6 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj
if out.Values[i] == graphql.Null {
invalids++
}
case "project":
out.Values[i] = ec._User_project(ctx, field, obj)
case "email":
out.Values[i] = ec._User_email(ctx, field, obj)

View File

@ -116,10 +116,9 @@ type TimeRangeOutput struct {
}
type User struct {
Username string `json:"username"`
Name string `json:"name"`
Project *string `json:"project"`
Email string `json:"email"`
Username string `json:"username"`
Name string `json:"name"`
Email string `json:"email"`
}
type Aggregate string

View File

@ -92,7 +92,7 @@
<div class="d-flex">
<form method="GET" action="/search">
<InputGroup>
<Input type="text" placeholder={"Search 'type:<query>' ..."} name="searchId"/>
<Input type="text" placeholder="Search 'type:<query>' ..." name="searchId"/>
<Button outline type="submit"><Icon name="search"/></Button>
<InputGroupText style="cursor:help;" title={(authlevel >= 4) ? "Example: 'projectId:a100cd', Types are: jobId | jobName | projectId | username | name" : "Example: 'jobName:myjob', Types are jobId | jobName | projectId"}><Icon name="info-circle"/></InputGroupText>
</InputGroup>