role.go 826 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package models
  2. import (
  3. "gorm.io/gorm"
  4. )
  5. // The roles available for a project
  6. const (
  7. RoleAdmin string = "admin"
  8. RoleDeveloper string = "developer"
  9. RoleViewer string = "viewer"
  10. )
  11. // Role type that extends gorm.Model
  12. type Role struct {
  13. gorm.Model
  14. Kind string `json:"kind"`
  15. UserID uint `json:"user_id"`
  16. ProjectID uint `json:"project_id"`
  17. }
  18. // RoleExternal represents the Role type that is sent over REST
  19. type RoleExternal struct {
  20. ID uint `json:"id"`
  21. Kind string `json:"kind"`
  22. UserID uint `json:"user_id"`
  23. ProjectID uint `json:"project_id"`
  24. }
  25. // Externalize generates an external Role to be shared over REST
  26. func (r *Role) Externalize() *RoleExternal {
  27. return &RoleExternal{
  28. ID: r.ID,
  29. Kind: r.Kind,
  30. UserID: r.UserID,
  31. ProjectID: r.ProjectID,
  32. }
  33. }