collaborators.go 991 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. api "github.com/gogits/go-gogs-client"
  7. "github.com/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/context"
  9. )
  10. func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
  11. collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
  12. if err != nil {
  13. if models.IsErrUserNotExist(err) {
  14. ctx.Error(422, "", err)
  15. } else {
  16. ctx.Error(500, "GetUserByName", err)
  17. }
  18. return
  19. }
  20. if err := ctx.Repo.Repository.AddCollaborator(collaborator); err != nil {
  21. ctx.Error(500, "AddCollaborator", err)
  22. return
  23. }
  24. if form.Permission != nil {
  25. if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, models.ParseAccessMode(*form.Permission)); err != nil {
  26. ctx.Error(500, "ChangeCollaborationAccessMode", err)
  27. return
  28. }
  29. }
  30. ctx.Status(204)
  31. }