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.

34 lines
577 B

  1. package users
  2. import (
  3. "git.aiterp.net/rpdata/api/models"
  4. "github.com/globalsign/mgo"
  5. )
  6. // Ensure finds a user by id, or makes a new one.
  7. func Ensure(id string) (models.User, error) {
  8. user := models.User{}
  9. err := collection.FindId(id).One(&user)
  10. if err == mgo.ErrNotFound {
  11. user = models.User{
  12. ID: id,
  13. Nick: "",
  14. Permissions: []string{
  15. "member",
  16. "log.edit",
  17. "post.edit",
  18. "post.move",
  19. "post.remove",
  20. "file.upload",
  21. },
  22. }
  23. err := collection.Insert(user)
  24. if err != nil {
  25. return models.User{}, err
  26. }
  27. }
  28. return user, err
  29. }