stufflog graphql server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. package models
  2. // ProjectPermission is a structure that associates a user with a project.
  3. type ProjectPermission struct {
  4. ProjectID string `db:"project_id"`
  5. UserID string `db:"user_id"`
  6. Level int `db:"access_level"`
  7. }
  8. const (
  9. ProjectPermissionLevelNoAccess int = 0
  10. ProjectPermissionLevelObserver int = 1
  11. ProjectPermissionLevelMember int = 2
  12. ProjectPermissionLevelAdmin int = 3
  13. ProjectPermissionLevelOwner int = 4
  14. )
  15. func (permission *ProjectPermission) CanViewAnyIssue() bool {
  16. return permission.Level >= ProjectPermissionLevelObserver
  17. }
  18. func (permission *ProjectPermission) CanViewOwnIssue() bool {
  19. return permission.Level >= ProjectPermissionLevelObserver
  20. }
  21. func (permission *ProjectPermission) CanManageOwnIssue() bool {
  22. return permission.Level >= ProjectPermissionLevelMember
  23. }
  24. func (permission *ProjectPermission) CanManageAnyIssue() bool {
  25. return permission.Level >= ProjectPermissionLevelAdmin
  26. }
  27. func (permission *ProjectPermission) CanManagePermissions() bool {
  28. return permission.Level >= ProjectPermissionLevelOwner
  29. }