MCPcopy Create free account
hub / github.com/bytebase/bytebase / completeAccessRequestIssue

Function completeAccessRequestIssue

backend/api/v1/issue_hook.go:94–133  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

92// For ROLE_GRANT issue: grant the privilege and update the status.
93// For ACCESS_GRANT issue: mark the status as ACTIVE.
94func 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}

Callers 3

postCreateIssueFunction · 0.85
ApproveIssueMethod · 0.85
RetryIssueApprovalMethod · 0.85

Calls 8

FormatAccessGrantFunction · 0.92
BBErrorFunction · 0.92
activateAccessGrantFunction · 0.85
ErrorfMethod · 0.80
CreateIssueCommentsMethod · 0.80
UpdateIssueMethod · 0.65

Tested by

no test coverage detected