-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
authorization.go
45 lines (34 loc) · 1.06 KB
/
authorization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package api
import (
"context"
"github.com/gofrs/uuid"
"github.com/stashapp/stash-box/pkg/models"
"github.com/stashapp/stash-box/pkg/user"
)
func getCurrentUser(ctx context.Context) *models.User {
return user.GetCurrentUser(ctx)
}
func validateVote(ctx context.Context) error {
return user.ValidateRole(ctx, models.RoleEnumVote)
}
func validateInvite(ctx context.Context) error {
return user.ValidateRole(ctx, models.RoleEnumInvite)
}
func validateManageInvites(ctx context.Context) error {
return user.ValidateRole(ctx, models.RoleEnumManageInvites)
}
func validateAdmin(ctx context.Context) error {
return user.ValidateRole(ctx, models.RoleEnumAdmin)
}
func validateBot(ctx context.Context) error {
return user.ValidateRole(ctx, models.RoleEnumBot)
}
func validateUser(ctx context.Context, userID uuid.UUID) error {
return user.ValidateOwner(ctx, userID)
}
func validateUserOrAdmin(ctx context.Context, userID uuid.UUID) error {
if err := user.ValidateOwner(ctx, userID); err == nil {
return nil
}
return user.ValidateRole(ctx, models.RoleEnumAdmin)
}