GraphQL API and utilities for the rpdata project
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.

23 lines
636 B

  1. package models
  2. // A User represents user information about a user that has logged in.
  3. type User struct {
  4. ID string `bson:"_id" json:"id"`
  5. Nick string `bson:"nick,omitempty" json:"nick,omitempty"`
  6. Permissions []string `bson:"permissions" json:"permissions"`
  7. }
  8. // Permitted returns true if either of the permissions can be found
  9. //
  10. // `token.UserID == page.Author || token.Permitted("story.edit")`
  11. func (user *User) Permitted(permissions ...string) bool {
  12. for i := range permissions {
  13. for j := range user.Permissions {
  14. if permissions[i] == user.Permissions[j] {
  15. return true
  16. }
  17. }
  18. }
  19. return false
  20. }