예제 #1
0
파일: repo.go 프로젝트: kiliit/gogs
func AddCollaborator(ctx *middleware.Context, opt api.CollaboratorOption) {
	u, err := models.GetUserByName(opt.UserName)
	if err != nil {
		if models.IsErrUserNotExist(err) {
			ctx.APIError(422, "", err)
		} else {
			ctx.Handle(500, "GetUserByName", err)
		}
		return
	}

	// Check if user is organization member.
	if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) {
		ctx.APIError(422, "", "User is organization member")
		return
	}

	if err = ctx.Repo.Repository.AddCollaborator(u); err != nil {
		ctx.Handle(500, "AddCollaborator", err)
		return
	}

	if setting.Service.EnableNotifyMail {
		if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
			ctx.Handle(500, "SendCollaboratorMail", err)
			return
		}
	}

	ctx.Status(201)
}
예제 #2
0
func checkUserFollowing(ctx *middleware.Context, u *models.User, followID int64) {
	if u.IsFollowing(followID) {
		ctx.Status(204)
	} else {
		ctx.Error(404)
	}
}
예제 #3
0
파일: repo.go 프로젝트: nafrente/gogs
func DeleteRepo(ctx *middleware.Context) {
	user, err := models.GetUserByName(ctx.Params(":username"))
	if err != nil {
		if models.IsErrUserNotExist(err) {
			ctx.APIError(422, "", err)
		} else {
			ctx.APIError(500, "GetUserByName", err)
		}
		return
	}

	repo, err := models.GetRepositoryByName(user.Id, ctx.Params(":reponame"))
	if err != nil {
		if models.IsErrRepoNotExist(err) {
			ctx.Error(404)
		} else {
			ctx.APIError(500, "GetRepositoryByName", err)
		}
		return
	}

	if user.IsOrganization() && !user.IsOwnedBy(ctx.User.Id) {
		ctx.APIError(403, "", "Given user is not owner of organization.")
		return
	}

	if err := models.DeleteRepository(user.Id, repo.ID); err != nil {
		ctx.APIError(500, "DeleteRepository", err)
		return
	}

	log.Trace("Repository deleted: %s/%s", user.Name, repo.Name)
	ctx.Status(204)
}
예제 #4
0
파일: email.go 프로젝트: cuteluo1983/gogs
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses
func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) {
	if len(form.Emails) == 0 {
		ctx.Status(422)
		return
	}

	emails := make([]*models.EmailAddress, len(form.Emails))
	for i := range form.Emails {
		emails[i] = &models.EmailAddress{
			UID:         ctx.User.Id,
			Email:       form.Emails[i],
			IsActivated: !setting.Service.RegisterEmailConfirm,
		}
	}

	if err := models.AddEmailAddresses(emails); err != nil {
		if models.IsErrEmailAlreadyUsed(err) {
			ctx.APIError(422, "", "Email address has been used: "+err.(models.ErrEmailAlreadyUsed).Email)
		} else {
			ctx.APIError(500, "AddEmailAddresses", err)
		}
		return
	}

	apiEmails := make([]*api.Email, len(emails))
	for i := range emails {
		apiEmails[i] = convert.ToApiEmail(emails[i])
	}
	ctx.JSON(201, &apiEmails)
}
예제 #5
0
파일: repo_keys.go 프로젝트: kiliit/gogs
// https://github.com/gogits/go-gogs-client/wiki/Repositories---Deploy-Keys#remove-a-deploy-key
func DeleteRepoDeploykey(ctx *middleware.Context) {
	if err := models.DeleteDeployKey(ctx.ParamsInt64(":id")); err != nil {
		ctx.APIError(500, "DeleteDeployKey", err)
		return
	}

	ctx.Status(204)
}
예제 #6
0
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
func Follow(ctx *middleware.Context) {
	target := GetUserByParams(ctx)
	if ctx.Written() {
		return
	}
	if err := models.FollowUser(ctx.User.Id, target.Id); err != nil {
		ctx.APIError(500, "FollowUser", err)
		return
	}
	ctx.Status(204)
}
예제 #7
0
파일: user_keys.go 프로젝트: Janfred/gogs
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
func DeleteUserPublicKey(ctx *middleware.Context) {
	if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
		if models.IsErrKeyAccessDenied(err) {
			ctx.APIError(403, "", "You do not have access to this key")
		} else {
			ctx.APIError(500, "DeletePublicKey", err)
		}
		return
	}

	ctx.Status(204)
}
예제 #8
0
파일: pull.go 프로젝트: Janfred/gogs
func TriggerTask(ctx *middleware.Context) {
	_, repo := parseOwnerAndRepo(ctx)
	if ctx.Written() {
		return
	}
	branch := ctx.Query("branch")
	if len(branch) == 0 {
		ctx.Handle(422, "TriggerTask", errors.New("branch is empty"))
		return
	}

	log.Trace("TriggerTask[%d].(new request): %s", repo.ID, branch)

	go models.HookQueue.Add(repo.ID)
	go models.AddTestPullRequestTask(repo.ID, branch)
	ctx.Status(202)
}
예제 #9
0
파일: notice.go 프로젝트: cuteluo1983/gogs
func DeleteNotices(ctx *middleware.Context) {
	strs := ctx.QueryStrings("ids[]")
	ids := make([]int64, 0, len(strs))
	for i := range strs {
		id := com.StrTo(strs[i]).MustInt64()
		if id > 0 {
			ids = append(ids, id)
		}
	}

	if err := models.DeleteNoticesByIDs(ids); err != nil {
		ctx.Flash.Error("DeleteNoticesByIDs: " + err.Error())
		ctx.Status(500)
	} else {
		ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
		ctx.Status(200)
	}
}
예제 #10
0
파일: repo.go 프로젝트: kiliit/gogs
func DeleteRepo(ctx *middleware.Context) {
	owner, repo := parseOwnerAndRepo(ctx)
	if ctx.Written() {
		return
	}

	if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.Id) {
		ctx.APIError(403, "", "Given user is not owner of organization.")
		return
	}

	if err := models.DeleteRepository(owner.Id, repo.ID); err != nil {
		ctx.APIError(500, "DeleteRepository", err)
		return
	}

	log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
	ctx.Status(204)
}
예제 #11
0
파일: users.go 프로젝트: cuteluo1983/gogs
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user
func DeleteUser(ctx *middleware.Context) {
	u := user.GetUserByParams(ctx)
	if ctx.Written() {
		return
	}

	if err := models.DeleteUser(u); err != nil {
		if models.IsErrUserOwnRepos(err) ||
			models.IsErrUserHasOrgs(err) {
			ctx.APIError(422, "", err)
		} else {
			ctx.APIError(500, "DeleteUser", err)
		}
		return
	}
	log.Trace("Account deleted by admin(%s): %s", ctx.User.Name, u.Name)

	ctx.Status(204)
}
예제 #12
0
파일: email.go 프로젝트: cuteluo1983/gogs
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
func DeleteEmail(ctx *middleware.Context, form api.CreateEmailOption) {
	if len(form.Emails) == 0 {
		ctx.Status(204)
		return
	}

	emails := make([]*models.EmailAddress, len(form.Emails))
	for i := range form.Emails {
		emails[i] = &models.EmailAddress{
			Email: form.Emails[i],
		}
	}

	if err := models.DeleteEmailAddresses(emails); err != nil {
		ctx.APIError(500, "DeleteEmailAddresses", err)
		return
	}
	ctx.Status(204)
}
예제 #13
0
func ReleaseByName(ctx *middleware.Context) {
	rel, err := models.GetRelease(ctx.Repo.Repository.ID, ctx.Params(":release"))
	if err != nil {
		log.Error(4, "GetRelease: %v", err)
		ctx.Status(500)
		return
	}

	publisher, err := models.GetUserByID(rel.PublisherID)
	if err != nil {
		if models.IsErrUserNotExist(err) {
			publisher = models.NewFakeUser()
		} else {
			ctx.Handle(422, "GetUserByID", err)
			return
		}
	}
	rel.Publisher = publisher

	ctx.JSON(200, ToApiRelease(rel))
}
예제 #14
0
파일: setting.go 프로젝트: nafrente/gogs
func TriggerHook(ctx *middleware.Context) {
	u, err := models.GetUserByName(ctx.Params(":username"))
	if err != nil {
		if models.IsErrUserNotExist(err) {
			ctx.Handle(404, "GetUserByName", err)
		} else {
			ctx.Handle(500, "GetUserByName", err)
		}
		return
	}

	repo, err := models.GetRepositoryByName(u.Id, ctx.Params(":reponame"))
	if err != nil {
		if models.IsErrRepoNotExist(err) {
			ctx.Handle(404, "GetRepositoryByName", err)
		} else {
			ctx.Handle(500, "GetRepositoryByName", err)
		}
		return
	}
	models.HookQueue.AddRepoID(repo.ID)
	ctx.Status(200)
}
예제 #15
0
파일: webhook.go 프로젝트: cuteluo1983/gogs
func TestWebhook(ctx *middleware.Context) {
	p := &api.PushPayload{
		Ref:    ctx.Repo.Repository.DefaultBranch,
		Before: ctx.Repo.CommitID,
		After:  ctx.Repo.CommitID,
		Commits: []*api.PayloadCommit{
			{
				ID:      ctx.Repo.CommitID,
				Message: ctx.Repo.Commit.Message(),
				URL:     ctx.Repo.Repository.FullRepoLink() + "/commit/" + ctx.Repo.CommitID,
				Author: &api.PayloadAuthor{
					Name:  ctx.Repo.Commit.Author.Name,
					Email: ctx.Repo.Commit.Author.Email,
				},
			},
		},
		Repo: ctx.Repo.Repository.ComposePayload(),
		Pusher: &api.PayloadAuthor{
			Name:     ctx.User.Name,
			Email:    ctx.User.Email,
			UserName: ctx.User.Name,
		},
		Sender: &api.PayloadUser{
			UserName:  ctx.User.Name,
			ID:        ctx.User.Id,
			AvatarUrl: setting.AppUrl + ctx.User.RelAvatarLink(),
		},
	}
	if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil {
		ctx.Flash.Error("PrepareWebhooks: " + err.Error())
		ctx.Status(500)
	} else {
		go models.HookQueue.Add(ctx.Repo.Repository.ID)
		ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success"))
		ctx.Status(200)
	}
}
예제 #16
0
파일: pull.go 프로젝트: cuteluo1983/gogs
func TriggerTask(ctx *middleware.Context) {
	branch := ctx.Query("branch")
	secret := ctx.Query("secret")
	if len(branch) == 0 || len(secret) == 0 {
		ctx.Error(404)
		log.Trace("TriggerTask: branch or secret is empty")
		return
	}
	owner, repo := parseOwnerAndRepo(ctx)
	if ctx.Written() {
		return
	}
	if secret != base.EncodeMD5(owner.Salt) {
		ctx.Error(404)
		log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
		return
	}

	log.Trace("TriggerTask [%d].(new request): %s", repo.ID, branch)

	go models.HookQueue.Add(repo.ID)
	go models.AddTestPullRequestTask(repo.ID, branch)
	ctx.Status(202)
}