role.go 784 B

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