summaryrefslogtreecommitdiff
path: root/shrine/utils/auth/hierarchy.go
blob: a1262b37414d8e925688c778c74113a84ce35b03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package auth

import (
	"fmt"
	"shrine/messages"
	"shrine/models"
)

func ValidateHierarchy(admin *models.User, target *models.User, action string) error {
	if target.ID == admin.ID {
		return fmt.Errorf(messages.CannotActionSelf, action)
	}

	if target.IsOwner() {
		return fmt.Errorf(messages.CannotActionOwner, action)
	}

	if target.IsAdmin() && !admin.IsOwner() {
		return fmt.Errorf(messages.OnlyOwnerCanActionAdmin, action)
	}

	return nil
}