mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-10 09:41:52 +02:00
refactor: add permission denied error type to group model package
This commit is contained in:
parent
aaa7e46da5
commit
0af8cacd4d
@ -42,3 +42,21 @@ func IsErrGroupTooDeep(err error) bool {
|
||||
func (err ErrGroupTooDeep) Error() string {
|
||||
return fmt.Sprintf("group has reached or exceeded the subgroup nesting limit [id: %d]", err.ID)
|
||||
}
|
||||
|
||||
type ErrUserDoesNotHaveAccessToGroup struct {
|
||||
UserID, GroupID int64
|
||||
}
|
||||
|
||||
func (e ErrUserDoesNotHaveAccessToGroup) Error() string {
|
||||
return fmt.Sprintf("user %d does not have access to group %d", e.UserID, e.GroupID)
|
||||
}
|
||||
|
||||
func (e ErrUserDoesNotHaveAccessToGroup) Unwrap() error {
|
||||
return util.ErrPermissionDenied
|
||||
}
|
||||
|
||||
func IsErrUserDoesNotHaveAccessToGroup(err error) bool {
|
||||
var eNoAccess ErrUserDoesNotHaveAccessToGroup
|
||||
ok := errors.As(err, &eNoAccess)
|
||||
return ok
|
||||
}
|
||||
|
||||
@ -98,7 +98,10 @@ func MoveGroupItem(ctx context.Context, opts MoveGroupOptions, doer *user_model.
|
||||
return err
|
||||
}
|
||||
if !canAccessNewParent {
|
||||
return errors.New("cannot access new parent group")
|
||||
return group_model.ErrUserDoesNotHaveAccessToGroup{
|
||||
GroupID: opts.NewParent,
|
||||
UserID: doer.ID,
|
||||
}
|
||||
}
|
||||
|
||||
err = parentGroup.LoadSubgroups(ctx, false)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user