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.

33 lines
558 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. "file.upload",
  20. },
  21. }
  22. err := collection.Insert(user)
  23. if err != nil {
  24. return models.User{}, err
  25. }
  26. }
  27. return user, err
  28. }