func UpdateIssueMilestone(ctx *context.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } oldMilestoneID := issue.MilestoneID milestoneID := ctx.QueryInt64("id") if oldMilestoneID == milestoneID { ctx.JSON(200, map[string]interface{}{ "ok": true, }) return } // Not check for invalid milestone id and give responsibility to owners. issue.MilestoneID = milestoneID if err := models.ChangeMilestoneAssign(issue, oldMilestoneID); err != nil { ctx.Handle(500, "ChangeMilestoneAssign", err) return } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }
func UpdateCommentContent(ctx *context.Context) { comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) if err != nil { ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err) return } if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) { ctx.Error(403) return } else if comment.Type != models.COMMENT_TYPE_COMMENT { ctx.Error(204) return } comment.Content = ctx.Query("content") if len(comment.Content) == 0 { ctx.JSON(200, map[string]interface{}{ "content": "", }) return } if err = models.UpdateComment(comment); err != nil { ctx.Handle(500, "UpdateComment", err) return } ctx.JSON(200, map[string]interface{}{ "content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), }) }
func UpdateIssueAssignee(ctx *context.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } aid := ctx.QueryInt64("id") if issue.AssigneeID == aid { ctx.JSON(200, map[string]interface{}{ "ok": true, }) return } // Not check for invalid assignee id and give responsibility to owners. issue.AssigneeID = aid if err := models.UpdateIssueUserByAssignee(issue); err != nil { ctx.Handle(500, "UpdateIssueUserByAssignee: %v", err) return } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }
func DeleteAuthSource(ctx *context.Context) { source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { ctx.Handle(500, "GetLoginSourceByID", err) return } if err = models.DeleteSource(source); err != nil { if models.IsErrLoginSourceInUse(err) { ctx.Flash.Error(ctx.Tr("admin.auths.still_in_used")) } else { ctx.Flash.Error(fmt.Sprintf("DeleteSource: %v", err)) } ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/admin/auths/" + ctx.Params(":authid"), }) return } log.Trace("Authentication deleted by admin(%s): %d", ctx.User.Name, source.ID) ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success")) ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/admin/auths", }) }
func UpdateIssueTitle(ctx *context.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) { ctx.Error(403) return } title := ctx.QueryTrim("title") if len(title) == 0 { ctx.Error(204) return } if err := issue.ChangeTitle(ctx.User, title); err != nil { ctx.Handle(500, "ChangeTitle", err) return } ctx.JSON(200, map[string]interface{}{ "title": issue.Title, }) }
func MembersAction(ctx *context.Context) { uid := com.StrTo(ctx.Query("uid")).MustInt64() if uid == 0 { ctx.Redirect(ctx.Org.OrgLink + "/members") return } org := ctx.Org.Organization var err error switch ctx.Params(":action") { case "private": if ctx.User.ID != uid && !ctx.Org.IsOwner { ctx.Error(404) return } err = models.ChangeOrgUserStatus(org.ID, uid, false) case "public": if ctx.User.ID != uid && !ctx.Org.IsOwner { ctx.Error(404) return } err = models.ChangeOrgUserStatus(org.ID, uid, true) case "remove": if !ctx.Org.IsOwner { ctx.Error(404) return } err = org.RemoveMember(uid) if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Redirect(ctx.Org.OrgLink + "/members") return } case "leave": err = org.RemoveMember(ctx.User.ID) if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Redirect(ctx.Org.OrgLink + "/members") return } } if err != nil { log.Error(4, "Action(%s): %v", ctx.Params(":action"), err) ctx.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), }) return } if ctx.Params(":action") != "leave" { ctx.Redirect(ctx.Org.OrgLink + "/members") } else { ctx.Redirect(setting.AppSubUrl + "/") } }
func DeleteRelease(ctx *context.Context) { if err := models.DeleteReleaseByID(ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteReleaseByID: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.release.deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/releases", }) }
func DeleteMilestone(ctx *context.Context) { if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/milestones", }) }
func DeleteCollaboration(ctx *context.Context) { if err := ctx.Repo.Repository.DeleteCollaboration(ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteCollaboration: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/settings/collaboration", }) }
func DeleteSSHKey(ctx *context.Context) { if err := models.DeletePublicKey(ctx.User, ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeletePublicKey: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.ssh_key_deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/user/settings/ssh", }) }
func SettingsDeleteApplication(ctx *context.Context) { if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.delete_token_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/user/settings/applications", }) }
func DeleteWebhook(ctx *context.Context) { if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteWebhookByRepoID: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/settings/hooks", }) }
func DeleteTeam(ctx *context.Context) { if err := models.DeleteTeam(ctx.Org.Team); err != nil { ctx.Flash.Error("DeleteTeam: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Org.OrgLink + "/teams", }) }
func DeleteDeployKey(ctx *context.Context) { if err := models.DeleteDeployKey(ctx.User, ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteDeployKey: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.settings.deploy_key_deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/settings/keys", }) }
func DeleteEmail(ctx *context.Context) { if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil { ctx.Handle(500, "DeleteEmail", err) return } log.Trace("Email address deleted: %s", ctx.User.Name) ctx.Flash.Success(ctx.Tr("settings.email_deletion_success")) ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/user/settings/email", }) }
func DeleteLabel(ctx *context.Context) { if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteLabel: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/labels", }) return }
func DeleteWikiPagePost(ctx *context.Context) { pageURL := ctx.Params(":page") if len(pageURL) == 0 { pageURL = "Home" } pageName := models.ToWikiPageName(pageURL) if err := ctx.Repo.Repository.DeleteWikiPage(ctx.User, pageName); err != nil { ctx.Handle(500, "DeleteWikiPage", err) return } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/wiki/", }) }
func UploadIssueAttachment(ctx *context.Context) { if !setting.AttachmentEnabled { ctx.Error(404, "attachment is not enabled") return } file, header, err := ctx.Req.FormFile("file") if err != nil { ctx.Error(500, fmt.Sprintf("FormFile: %v", err)) return } defer file.Close() buf := make([]byte, 1024) n, _ := file.Read(buf) if n > 0 { buf = buf[:n] } fileType := http.DetectContentType(buf) allowedTypes := strings.Split(setting.AttachmentAllowedTypes, ",") allowed := false for _, t := range allowedTypes { t := strings.Trim(t, " ") if t == "*/*" || t == fileType { allowed = true break } } if !allowed { ctx.Error(400, ErrFileTypeForbidden.Error()) return } attach, err := models.NewAttachment(header.Filename, buf, file) if err != nil { ctx.Error(500, fmt.Sprintf("NewAttachment: %v", err)) return } log.Trace("New attachment uploaded: %s", attach.UUID) ctx.JSON(200, map[string]string{ "uuid": attach.UUID, }) }
func DeleteRepo(ctx *context.Context) { repo, err := models.GetRepositoryByID(ctx.QueryInt64("id")) if err != nil { ctx.Handle(500, "GetRepositoryByID", err) return } if err := models.DeleteRepository(repo.MustOwner().Id, repo.ID); err != nil { ctx.Handle(500, "DeleteRepository", err) return } log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name) ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success")) ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/admin/repos?page=" + ctx.Query("page"), }) }
func UploadFileToServer(ctx *context.Context) { file, header, err := ctx.Req.FormFile("file") if err != nil { ctx.Error(500, fmt.Sprintf("FormFile: %v", err)) return } defer file.Close() buf := make([]byte, 1024) n, _ := file.Read(buf) if n > 0 { buf = buf[:n] } fileType := http.DetectContentType(buf) if len(setting.Repository.Upload.AllowedTypes) > 0 { allowed := false for _, t := range setting.Repository.Upload.AllowedTypes { t := strings.Trim(t, " ") if t == "*/*" || t == fileType { allowed = true break } } if !allowed { ctx.Error(400, ErrFileTypeForbidden.Error()) return } } upload, err := models.NewUpload(header.Filename, buf, file) if err != nil { ctx.Error(500, fmt.Sprintf("NewUpload: %v", err)) return } log.Trace("New file uploaded: %s", upload.UUID) ctx.JSON(200, map[string]string{ "uuid": upload.UUID, }) }
func UpdateIssueContent(ctx *context.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) { ctx.Error(403) return } content := ctx.Query("content") if err := issue.ChangeContent(ctx.User, content); err != nil { ctx.Handle(500, "ChangeContent", err) return } ctx.JSON(200, map[string]interface{}{ "content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), }) }
func DeleteUser(ctx *context.Context) { u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) if err != nil { ctx.Handle(500, "GetUserByID", err) return } if err = models.DeleteUser(u); err != nil { switch { case models.IsErrUserOwnRepos(err): ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo")) ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"), }) case models.IsErrUserHasOrgs(err): ctx.Flash.Error(ctx.Tr("admin.users.still_has_org")) ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"), }) default: ctx.Handle(500, "DeleteUser", err) } return } log.Trace("Account deleted by admin (%s): %s", ctx.User.Name, u.Name) ctx.Flash.Success(ctx.Tr("admin.users.deletion_success")) ctx.JSON(200, map[string]interface{}{ "redirect": setting.AppSubUrl + "/admin/users", }) }
func UpdateIssueLabel(ctx *context.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } if ctx.Query("action") == "clear" { if err := issue.ClearLabels(ctx.User); err != nil { ctx.Handle(500, "ClearLabels", err) return } } else { isAttach := ctx.Query("action") == "attach" label, err := models.GetLabelByID(ctx.QueryInt64("id")) if err != nil { if models.IsErrLabelNotExist(err) { ctx.Error(404, "GetLabelByID") } else { ctx.Handle(500, "GetLabelByID", err) } return } if isAttach && !issue.HasLabel(label.ID) { if err = issue.AddLabel(ctx.User, label); err != nil { ctx.Handle(500, "AddLabel", err) return } } else if !isAttach && issue.HasLabel(label.ID) { if err = issue.RemoveLabel(ctx.User, label); err != nil { ctx.Handle(500, "RemoveLabel", err) return } } } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }
func UpdateIssueAssignee(ctx *context.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } assigneeID := ctx.QueryInt64("id") if issue.AssigneeID == assigneeID { ctx.JSON(200, map[string]interface{}{ "ok": true, }) return } if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil { ctx.Handle(500, "ChangeAssignee", err) return } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }
func TeamsAction(ctx *context.Context) { uid := com.StrTo(ctx.Query("uid")).MustInt64() if uid == 0 { ctx.Redirect(ctx.Org.OrgLink + "/teams") return } page := ctx.Query("page") var err error switch ctx.Params(":action") { case "join": if !ctx.Org.IsOwner { ctx.Error(404) return } err = ctx.Org.Team.AddMember(ctx.User.ID) case "leave": err = ctx.Org.Team.RemoveMember(ctx.User.ID) case "remove": if !ctx.Org.IsOwner { ctx.Error(404) return } err = ctx.Org.Team.RemoveMember(uid) page = "team" case "add": if !ctx.Org.IsOwner { ctx.Error(404) return } uname := ctx.Query("uname") var u *models.User u, err = models.GetUserByName(uname) if err != nil { if models.IsErrUserNotExist(err) { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName) } else { ctx.Handle(500, " GetUserByName", err) } return } err = ctx.Org.Team.AddMember(u.ID) page = "team" } if err != nil { if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) } else { log.Error(3, "Action(%s): %v", ctx.Params(":action"), err) ctx.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), }) return } } switch page { case "team": ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName) default: ctx.Redirect(ctx.Org.OrgLink + "/teams") } }