completeAccessRequestIssue completes the ACCESS_GRANT/ROLE_GRANT issue. For ROLE_GRANT issue: grant the privilege and update the status. For ACCESS_GRANT issue: mark the status as ACTIVE.
(ctx context.Context, stores *store.Store, userEmail string, issue *store.IssueMessage)
| 92 | // For ROLE_GRANT issue: grant the privilege and update the status. |
| 93 | // For ACCESS_GRANT issue: mark the status as ACTIVE. |
| 94 | func completeAccessRequestIssue(ctx context.Context, stores *store.Store, userEmail string, issue *store.IssueMessage) (*store.IssueMessage, error) { |
| 95 | switch issue.Type { |
| 96 | case storepb.Issue_ACCESS_GRANT: |
| 97 | if issue.Payload.AccessGrantId == "" { |
| 98 | return nil, errors.Errorf("invalid access grant id for issue %d", issue.UID) |
| 99 | } |
| 100 | accessGrantName := common.FormatAccessGrant(issue.ProjectID, issue.Payload.AccessGrantId) |
| 101 | if _, err := activateAccessGrant(ctx, stores, accessGrantName, true /* refresh expire time */); err != nil { |
| 102 | return nil, errors.Wrapf(err, "failed to activate access grant %v", accessGrantName) |
| 103 | } |
| 104 | case storepb.Issue_ROLE_GRANT: |
| 105 | if err := utils.UpdateProjectPolicyFromRoleGrantIssue(ctx, stores, common.GetWorkspaceIDFromContext(ctx), issue, issue.Payload.RoleGrant); err != nil { |
| 106 | return nil, err |
| 107 | } |
| 108 | default: |
| 109 | return issue, nil |
| 110 | } |
| 111 | |
| 112 | updatedIssue, err := stores.UpdateIssue(ctx, issue.ProjectID, issue.UID, &store.UpdateIssueMessage{Status: new(storepb.Issue_DONE)}) |
| 113 | if err != nil { |
| 114 | return nil, errors.Wrapf(err, "failed to update issue %q's status", issue.Title) |
| 115 | } |
| 116 | |
| 117 | if _, err := stores.CreateIssueComments(ctx, userEmail, &store.IssueCommentMessage{ |
| 118 | ProjectID: issue.ProjectID, |
| 119 | IssueUID: issue.UID, |
| 120 | Payload: &storepb.IssueCommentPayload{ |
| 121 | Event: &storepb.IssueCommentPayload_IssueUpdate_{ |
| 122 | IssueUpdate: &storepb.IssueCommentPayload_IssueUpdate{ |
| 123 | FromStatus: &issue.Status, |
| 124 | ToStatus: &updatedIssue.Status, |
| 125 | }, |
| 126 | }, |
| 127 | }, |
| 128 | }); err != nil { |
| 129 | slog.Warn("failed to create issue comment after changing the issue status", log.BBError(err)) |
| 130 | } |
| 131 | |
| 132 | return updatedIssue, nil |
| 133 | } |
no test coverage detected