0
0
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:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2026-05-06 21:11:01 -04:00
parent aaa7e46da5
commit 0af8cacd4d
No known key found for this signature in database
GPG Key ID: 924A5F6AF051E87C
2 changed files with 22 additions and 1 deletions

View File

@ -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
}

View File

@ -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)