-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEVPROD-3065: Update directive to handle SetLastRevision permission #7689
Changes from all commits
531743d
9dad979
5bf3f47
d32446f
211396f
eb7e08f
a3515f7
d9896e3
d6834b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,18 @@ import ( | |
|
||
"github.com/99designs/gqlgen/graphql" | ||
"github.com/evergreen-ci/evergreen" | ||
"github.com/evergreen-ci/evergreen/model" | ||
"github.com/evergreen-ci/evergreen/rest/data" | ||
restModel "github.com/evergreen-ci/evergreen/rest/model" | ||
"github.com/evergreen-ci/gimlet" | ||
"github.com/evergreen-ci/utility" | ||
) | ||
|
||
const ( | ||
CreateProjectMutation = "CreateProject" | ||
CopyProjectMutation = "CopyProject" | ||
DeleteProjectMutation = "DeleteProject" | ||
CreateProjectMutation = "CreateProject" | ||
CopyProjectMutation = "CopyProject" | ||
DeleteProjectMutation = "DeleteProject" | ||
SetLastRevisionMutation = "SetLastRevision" | ||
) | ||
|
||
type Resolver struct { | ||
|
@@ -87,11 +89,6 @@ func New(apiURL string) Config { | |
return next(ctx) | ||
} | ||
|
||
// Check for admin permissions for each of the resolvers. | ||
args, isStringMap := obj.(map[string]interface{}) | ||
if !isStringMap { | ||
return nil, ResourceNotFound.Send(ctx, "Project not specified") | ||
} | ||
operationContext := graphql.GetOperationContext(ctx).OperationName | ||
|
||
if operationContext == CreateProjectMutation { | ||
|
@@ -104,17 +101,26 @@ func New(apiURL string) Config { | |
} | ||
} | ||
|
||
getPermissionOpts := func(projectId string) gimlet.PermissionOpts { | ||
return gimlet.PermissionOpts{ | ||
Resource: projectId, | ||
ResourceType: evergreen.ProjectResourceType, | ||
Permission: evergreen.PermissionProjectSettings, | ||
RequiredLevel: evergreen.ProjectSettingsEdit.Value, | ||
} | ||
} | ||
|
||
args, isStringMap := obj.(map[string]interface{}) | ||
if !isStringMap { | ||
return nil, ResourceNotFound.Send(ctx, "Project not specified") | ||
} | ||
|
||
if operationContext == CopyProjectMutation { | ||
projectIdToCopy, ok := args["project"].(map[string]interface{})["projectIdToCopy"].(string) | ||
if !ok { | ||
return nil, InternalServerError.Send(ctx, "finding projectIdToCopy for copy project operation") | ||
} | ||
opts := gimlet.PermissionOpts{ | ||
Resource: projectIdToCopy, | ||
ResourceType: evergreen.ProjectResourceType, | ||
Permission: evergreen.PermissionProjectSettings, | ||
RequiredLevel: evergreen.ProjectSettingsEdit.Value, | ||
} | ||
opts := getPermissionOpts(projectIdToCopy) | ||
if user.HasPermission(opts) { | ||
return next(ctx) | ||
} | ||
|
@@ -125,12 +131,25 @@ func New(apiURL string) Config { | |
if !ok { | ||
return nil, InternalServerError.Send(ctx, "finding projectId for delete project operation") | ||
} | ||
opts := gimlet.PermissionOpts{ | ||
Resource: projectId, | ||
ResourceType: evergreen.ProjectResourceType, | ||
Permission: evergreen.PermissionProjectSettings, | ||
RequiredLevel: evergreen.ProjectSettingsEdit.Value, | ||
opts := getPermissionOpts(projectId) | ||
if user.HasPermission(opts) { | ||
return next(ctx) | ||
} | ||
} | ||
|
||
if operationContext == SetLastRevisionMutation { | ||
projectIdentifier, ok := args["opts"].(map[string]interface{})["projectIdentifier"].(string) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just retrieve the project ID directly from the request or is that not possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you show me which data structure you're referring to? "opts" refers to the mutation parameter where the directive was applied. |
||
if !ok { | ||
return nil, InternalServerError.Send(ctx, "finding projectIdentifier for set last revision operation") | ||
} | ||
project, err := model.FindBranchProjectRef(projectIdentifier) | ||
if err != nil { | ||
return nil, InternalServerError.Send(ctx, fmt.Sprintf("finding project '%s': %s", projectIdentifier, err.Error())) | ||
} | ||
if project == nil { | ||
return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("project '%s' not found", projectIdentifier)) | ||
} | ||
opts := getPermissionOpts(project.Id) | ||
if user.HasPermission(opts) { | ||
return next(ctx) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(request) can we move the block for
CreateProjectMutation
above the declaration of theargs
variable, since it doesn't use theargs
variable?