You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

collaborators.go 1.0 kB

123456789101112131415161718192021222324252627282930313233343536373839
  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 "code.gitea.io/sdk/gitea"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. )
  10. // AddCollaborator add a collaborator of a repository
  11. func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
  12. collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
  13. if err != nil {
  14. if models.IsErrUserNotExist(err) {
  15. ctx.Error(422, "", err)
  16. } else {
  17. ctx.Error(500, "GetUserByName", err)
  18. }
  19. return
  20. }
  21. if err := ctx.Repo.Repository.AddCollaborator(collaborator); err != nil {
  22. ctx.Error(500, "AddCollaborator", err)
  23. return
  24. }
  25. if form.Permission != nil {
  26. if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, models.ParseAccessMode(*form.Permission)); err != nil {
  27. ctx.Error(500, "ChangeCollaborationAccessMode", err)
  28. return
  29. }
  30. }
  31. ctx.Status(204)
  32. }