Partial grants completed without feedback, leaving Reconnect required unexplained. Keep the token and toast the backend missing-scopes error after the OAuth callback redirect. Signed-off-by: Sacha Al Himdani <sacha@probo.com>
168 lines
4.9 KiB
Go
168 lines
4.9 KiB
Go
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
// SOFTWARE.
|
|
|
|
package accessreview
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"go.probo.inc/probo/pkg/gid"
|
|
)
|
|
|
|
var (
|
|
ErrCampaignMissingSources = errors.New("access review campaign missing scope sources")
|
|
ErrCampaignNotDraft = errors.New("access review campaign not draft")
|
|
ErrCampaignNotDeletable = errors.New("access review campaign not deletable")
|
|
ErrCampaignNotPendingActions = errors.New("access review campaign not pending actions")
|
|
ErrCampaignCompleted = errors.New("access review campaign completed")
|
|
ErrCampaignCancelled = errors.New("access review campaign cancelled")
|
|
ErrMissingOAuthScopes = errors.New("missing required OAuth scopes")
|
|
)
|
|
|
|
type (
|
|
CampaignMissingSourcesError struct {
|
|
CampaignID gid.GID
|
|
}
|
|
|
|
CampaignNotDraftError struct {
|
|
CampaignID gid.GID
|
|
}
|
|
|
|
CampaignNotDeletableError struct {
|
|
CampaignID gid.GID
|
|
}
|
|
|
|
CampaignNotPendingActionsError struct {
|
|
CampaignID gid.GID
|
|
}
|
|
|
|
CampaignCompletedError struct {
|
|
CampaignID gid.GID
|
|
}
|
|
|
|
CampaignCancelledError struct {
|
|
CampaignID gid.GID
|
|
}
|
|
|
|
MissingOAuthScopesError struct {
|
|
Scopes []string
|
|
}
|
|
)
|
|
|
|
func NewCampaignMissingSourcesError(campaignID gid.GID) error {
|
|
return &CampaignMissingSourcesError{CampaignID: campaignID}
|
|
}
|
|
|
|
func (e *CampaignMissingSourcesError) Error() string {
|
|
return fmt.Sprintf(
|
|
"access review campaign %q cannot be started: no scope sources configured",
|
|
e.CampaignID,
|
|
)
|
|
}
|
|
|
|
func (e *CampaignMissingSourcesError) Is(target error) bool {
|
|
return target == ErrCampaignMissingSources
|
|
}
|
|
|
|
func NewCampaignNotDraftError(campaignID gid.GID) error {
|
|
return &CampaignNotDraftError{CampaignID: campaignID}
|
|
}
|
|
|
|
func (e *CampaignNotDraftError) Error() string {
|
|
return fmt.Sprintf("access review campaign %q is not in draft", e.CampaignID)
|
|
}
|
|
|
|
func (e *CampaignNotDraftError) Is(target error) bool {
|
|
return target == ErrCampaignNotDraft
|
|
}
|
|
|
|
func NewCampaignNotDeletableError(campaignID gid.GID) error {
|
|
return &CampaignNotDeletableError{CampaignID: campaignID}
|
|
}
|
|
|
|
func (e *CampaignNotDeletableError) Error() string {
|
|
return fmt.Sprintf(
|
|
"access review campaign %q cannot be deleted while it is in progress",
|
|
e.CampaignID,
|
|
)
|
|
}
|
|
|
|
func (e *CampaignNotDeletableError) Is(target error) bool {
|
|
return target == ErrCampaignNotDeletable
|
|
}
|
|
|
|
func NewCampaignNotPendingActionsError(campaignID gid.GID) error {
|
|
return &CampaignNotPendingActionsError{CampaignID: campaignID}
|
|
}
|
|
|
|
func (e *CampaignNotPendingActionsError) Error() string {
|
|
return fmt.Sprintf(
|
|
"access review campaign %q cannot be closed unless it is pending actions",
|
|
e.CampaignID,
|
|
)
|
|
}
|
|
|
|
func (e *CampaignNotPendingActionsError) Is(target error) bool {
|
|
return target == ErrCampaignNotPendingActions
|
|
}
|
|
|
|
func NewCampaignCompletedError(campaignID gid.GID) error {
|
|
return &CampaignCompletedError{CampaignID: campaignID}
|
|
}
|
|
|
|
func (e *CampaignCompletedError) Error() string {
|
|
return fmt.Sprintf("access review campaign %q is already completed", e.CampaignID)
|
|
}
|
|
|
|
func (e *CampaignCompletedError) Is(target error) bool {
|
|
return target == ErrCampaignCompleted
|
|
}
|
|
|
|
func NewCampaignCancelledError(campaignID gid.GID) error {
|
|
return &CampaignCancelledError{CampaignID: campaignID}
|
|
}
|
|
|
|
func (e *CampaignCancelledError) Error() string {
|
|
return fmt.Sprintf("access review campaign %q is already cancelled", e.CampaignID)
|
|
}
|
|
|
|
func (e *CampaignCancelledError) Is(target error) bool {
|
|
return target == ErrCampaignCancelled
|
|
}
|
|
|
|
func NewMissingOAuthScopesError(scopes []string) error {
|
|
return &MissingOAuthScopesError{Scopes: append([]string(nil), scopes...)}
|
|
}
|
|
|
|
func (e *MissingOAuthScopesError) Error() string {
|
|
display := make([]string, len(e.Scopes))
|
|
for i, scope := range e.Scopes {
|
|
display[i] = strings.TrimPrefix(scope, "https://graph.microsoft.com/")
|
|
}
|
|
|
|
return "Missing required OAuth scopes: " + strings.Join(display, ", ")
|
|
}
|
|
|
|
func (e *MissingOAuthScopesError) Is(target error) bool {
|
|
return target == ErrMissingOAuthScopes
|
|
}
|