Skip to content

Commit

Permalink
Add requireReason (bool) to GET /webapi/sites/:site/context (#49413)
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiczko authored Nov 27, 2024
1 parent 2b7e492 commit e5db273
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ func (h *Handler) getUserContext(w http.ResponseWriter, r *http.Request, p httpr
userContext.AccessCapabilities = ui.AccessCapabilities{
RequestableRoles: res.RequestableRoles,
SuggestedReviewers: res.SuggestedReviewers,
RequireReason: res.RequireReason,
}

userContext.AllowedSearchAsRoles = accessChecker.GetAllowedSearchAsRoles()
Expand Down
3 changes: 3 additions & 0 deletions lib/web/ui/usercontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type AccessCapabilities struct {
RequestableRoles []string `json:"requestableRoles"`
// SuggestedReviewers is a list of reviewers that the user can select when creating a request.
SuggestedReviewers []string `json:"suggestedReviewers"`
// RequireReason indicates whether the reason is required for the user to create an Access
// Request.
RequireReason bool `json:"requireReason"`
}

type authType string
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/services/user/makeUserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function makeAccessCapabilities(json): AccessCapabilities {
return {
requestableRoles: json.requestableRoles || [],
suggestedReviewers: json.suggestedReviewers || [],
requireReason: json.requireReason || false,
};
}

Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/services/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface AccessStrategy {
export interface AccessCapabilities {
requestableRoles: string[];
suggestedReviewers: string[];
requireReason: boolean;
}

export interface UserContext {
Expand Down
6 changes: 5 additions & 1 deletion web/packages/teleport/src/services/user/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ test('undefined values in context response gives proper default values', async (
// Test undefined access strategy is set to default optional.
accessStrategy: { type: 'optional', prompt: '' },
// Test undefined roles and reviewers are set to empty arrays.
accessCapabilities: { requestableRoles: [], suggestedReviewers: [] },
accessCapabilities: {
requestableRoles: [],
suggestedReviewers: [],
requireReason: false,
},
allowedSearchAsRoles: [],
passwordState: PasswordState.PASSWORD_STATE_UNSPECIFIED,
});
Expand Down

0 comments on commit e5db273

Please sign in to comment.