func Issues(ctx *middleware.Context) { ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true ctx.Data["ViewType"] = "all" milestoneId, _ := base.StrTo(ctx.Query("milestone")).Int() page, _ := base.StrTo(ctx.Query("page")).Int() ctx.Data["IssueCreatedCount"] = 0 var posterId int64 = 0 if ctx.Query("type") == "created_by" { if !ctx.IsSigned { ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) ctx.Redirect("/user/login/", 302) return } ctx.Data["ViewType"] = "created_by" } // Get issues. issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, posterId, int64(milestoneId), page, ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType")) if err != nil { ctx.Handle(200, "issue.Issues: %v", err) return } if ctx.IsSigned { posterId = ctx.User.Id } var createdByCount int // Get posters. for i := range issues { u, err := models.GetUserById(issues[i].PosterId) if err != nil { ctx.Handle(200, "issue.Issues(get poster): %v", err) return } issues[i].Poster = u if u.Id == posterId { createdByCount++ } } ctx.Data["Issues"] = issues ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues ctx.Data["IssueCreatedCount"] = createdByCount ctx.Data["IsShowClosed"] = ctx.Query("state") == "closed" ctx.HTML(200, "issue/list") }
func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { ctx.Data["Title"] = "New Account" ctx.Data["PageIsUsers"] = true if ctx.HasError() { ctx.HTML(200, USER_NEW) return } if form.Password != form.RetypePasswd { ctx.Data["Err_Password"] = true ctx.Data["Err_RetypePasswd"] = true ctx.RenderWithErr("Password and re-type password are not same.", "admin/users/new", &form) return } u := &models.User{ Name: form.UserName, Email: form.Email, Passwd: form.Password, IsActive: true, LoginType: models.PLAIN, } if len(form.LoginType) > 0 { // NOTE: need rewrite. fields := strings.Split(form.LoginType, "-") tp, _ := base.StrTo(fields[0]).Int() u.LoginType = models.LoginType(tp) u.LoginSource, _ = base.StrTo(fields[1]).Int64() u.LoginName = form.LoginName } var err error if u, err = models.CreateUser(u); err != nil { switch err { case models.ErrUserAlreadyExist: ctx.RenderWithErr("Username has been already taken", USER_NEW, &form) case models.ErrEmailAlreadyUsed: ctx.RenderWithErr("E-mail address has been already used", USER_NEW, &form) case models.ErrUserNameIllegal: ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), USER_NEW, &form) default: ctx.Handle(500, "admin.user.NewUser(CreateUser)", err) } return } log.Trace("%s User created by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, strings.ToLower(form.UserName)) ctx.Redirect("/admin/users") }
func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { if !ctx.Repo.IsOwner { ctx.Handle(404, "issue.UpdateIssue", nil) return } index, err := base.StrTo(params["index"]).Int() if err != nil { ctx.Handle(404, "issue.UpdateIssue", err) return } issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index)) if err != nil { if err == models.ErrIssueNotExist { ctx.Handle(404, "issue.UpdateIssue", err) } else { ctx.Handle(200, "issue.UpdateIssue", err) } return } issue.Name = form.IssueName issue.MilestoneId = form.MilestoneId issue.AssigneeId = form.AssigneeId issue.Labels = form.Labels issue.Content = form.Content if err = models.UpdateIssue(issue); err != nil { ctx.Handle(200, "issue.UpdateIssue", err) return } ctx.Data["Title"] = issue.Name ctx.Data["Issue"] = issue }
func EditUser(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Edit Account" ctx.Data["PageIsUsers"] = true uid, err := base.StrTo(params["userid"]).Int() if err != nil { ctx.Handle(404, "admin.user.EditUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { ctx.Handle(500, "admin.user.EditUser(GetUserById)", err) return } ctx.Data["User"] = u auths, err := models.GetAuths() if err != nil { ctx.Handle(500, "admin.user.NewUser(GetAuths)", err) return } ctx.Data["LoginSources"] = auths ctx.HTML(200, USER_EDIT) }
func DeleteAuthSource(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Delete Authentication" ctx.Data["PageIsAuths"] = true id, err := base.StrTo(params["authid"]).Int64() if err != nil { ctx.Handle(404, "admin.auths.DeleteAuth", err) return } a, err := models.GetLoginSourceById(id) if err != nil { ctx.Handle(500, "admin.auths.DeleteAuth", err) return } if err = models.DelLoginSource(a); err != nil { switch err { case models.ErrAuthenticationUserUsed: ctx.Flash.Error("This authentication still has used by some users, you should move them and then delete again.") ctx.Redirect("/admin/auths/" + params["authid"]) default: ctx.Handle(500, "admin.auths.DeleteAuth", err) } return } log.Trace("%s Authentication deleted by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.User.LowerName) ctx.Redirect("/admin/auths") }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Admin Dashboard" ctx.Data["PageIsDashboard"] = true // Run operation. op, _ := base.StrTo(ctx.Query("op")).Int() if op > 0 { var err error var success string switch AdminOperation(op) { case CLEAN_UNBIND_OAUTH: success = "All unbind OAuthes have been deleted." err = models.CleanUnbindOauth() case CLEAN_INACTIVATE_USER: success = "All inactivate accounts have been deleted." err = models.DeleteInactivateUsers() } if err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(success) } ctx.Redirect("/admin") return } ctx.Data["Stats"] = models.GetStatistic() updateSystemStatus() ctx.Data["SysStatus"] = sysStatus ctx.HTML(200, DASHBOARD) }
func WebHooks(ctx *middleware.Context) { ctx.Data["IsRepoToolbarWebHooks"] = true ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhooks" // Delete webhook. remove, _ := base.StrTo(ctx.Query("remove")).Int64() if remove > 0 { if err := models.DeleteWebhook(remove); err != nil { ctx.Handle(500, "setting.WebHooks(DeleteWebhook)", err) return } ctx.Flash.Success("Webhook has been removed.") ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks") return } ws, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id) if err != nil { ctx.Handle(500, "setting.WebHooks(GetWebhooksByRepoId)", err) return } ctx.Data["Webhooks"] = ws ctx.HTML(200, "repo/hooks") }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Admin Dashboard" ctx.Data["PageIsDashboard"] = true // Run operation. op, _ := base.StrTo(ctx.Query("op")).Int() if op > 0 { var err error var success string switch op { case OT_CLEAN_OAUTH: success = "All unbind OAuthes have been deleted." err = models.CleanUnbindOauth() } if err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(success) } ctx.Redirect("/admin") return } ctx.Data["Stats"] = models.GetStatistic() updateSystemStatus() ctx.Data["SysStatus"] = sysStatus ctx.HTML(200, "admin/dashboard") }
func DeleteUser(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Delete Account" ctx.Data["PageIsUsers"] = true log.Info("delete") uid, err := base.StrTo(params["userid"]).Int() if err != nil { ctx.Handle(404, "admin.user.EditUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { ctx.Handle(500, "admin.user.EditUser", err) return } if err = models.DeleteUser(u); err != nil { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error("This account still has ownership of repository, owner has to delete or transfer them first.") ctx.Redirect("/admin/users/" + params["userid"]) default: ctx.Handle(500, "admin.user.DeleteUser", err) } return } log.Trace("%s User deleted by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.User.LowerName) ctx.Redirect("/admin/users") }
func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) { ctx.Data["Title"] = "Edit Account" ctx.Data["PageIsUsers"] = true uid, err := base.StrTo(params["userid"]).Int() if err != nil { ctx.Handle(404, "admin.user.EditUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { ctx.Handle(500, "admin.user.EditUser", err) return } u.Email = form.Email u.Website = form.Website u.Location = form.Location u.Avatar = base.EncodeMd5(form.Avatar) u.AvatarEmail = form.Avatar u.IsActive = form.Active == "on" u.IsAdmin = form.Admin == "on" if err := models.UpdateUser(u); err != nil { ctx.Handle(500, "admin.user.EditUser", err) return } log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.User.LowerName) ctx.Data["User"] = u ctx.Flash.Success("Account profile has been successfully updated.") ctx.Redirect("/admin/users/" + params["userid"]) }
// DeleteLabel delete a label of given repository. func DeleteLabel(repoId int64, strId string) error { id, _ := base.StrTo(strId).Int64() l, err := GetLabelById(id) if err != nil { if err == ErrLabelNotExist { return nil } return err } issues, err := GetIssuesByLabel(repoId, strId) if err != nil { return err } sess := orm.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err } for _, issue := range issues { issue.LabelIds = strings.Replace(issue.LabelIds, "$"+strId+"|", "", -1) if _, err = sess.Id(issue.Id).AllCols().Update(issue); err != nil { sess.Rollback() return err } } if _, err = sess.Delete(l); err != nil { sess.Rollback() return err } return sess.Commit() }
func FileHistory(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarCommits"] = true fileName := params["_1"] if len(fileName) == 0 { Commits(ctx, params) return } userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name branchName := params["branchname"] brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { ctx.Handle(500, "repo.FileHistory", err) return } else if len(brs) == 0 { ctx.Handle(404, "repo.FileHistory", nil) return } commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName) if err != nil { ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err) return } else if commitsCount == 0 { ctx.Handle(404, "repo.FileHistory", nil) return } // Calculate and validate page number. page, _ := base.StrTo(ctx.Query("p")).Int() if page < 1 { page = 1 } lastPage := page - 1 if lastPage < 0 { lastPage = 0 } nextPage := page + 1 if nextPage*50 > commitsCount { nextPage = 0 } ctx.Data["Commits"], err = ctx.Repo.GitRepo.CommitsByFileAndRange( branchName, fileName, page) if err != nil { ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err) return } ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["FileName"] = fileName ctx.Data["CommitCount"] = commitsCount ctx.Data["LastPageNum"] = lastPage ctx.Data["NextPageNum"] = nextPage ctx.HTML(200, COMMITS) }
func Create(ctx *middleware.Context) { ctx.Data["Title"] = "Create repository" ctx.Data["PageIsNewRepo"] = true ctx.Data["LanguageIgns"] = models.LanguageIgns ctx.Data["Licenses"] = models.Licenses ctxUser := ctx.User orgId, _ := base.StrTo(ctx.Query("org")).Int64() if orgId > 0 { org, err := models.GetUserById(orgId) if err != nil && err != models.ErrUserNotExist { ctx.Handle(500, "home.Dashboard(GetUserById)", err) return } ctxUser = org } ctx.Data["ContextUser"] = ctxUser if err := ctx.User.GetOrganizations(); err != nil { ctx.Handle(500, "home.Dashboard(GetOrganizations)", err) return } ctx.Data["AllUsers"] = append([]*models.User{ctx.User}, ctx.User.Orgs...) ctx.HTML(200, CREATE) }
func SettingSocial(ctx *middleware.Context) { ctx.Data["Title"] = "Social Account" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingSocial"] = true // Unbind social account. remove, _ := base.StrTo(ctx.Query("remove")).Int64() if remove > 0 { if err := models.DeleteOauth2ById(remove); err != nil { ctx.Handle(500, "user.SettingSocial(DeleteOauth2ById)", err) return } ctx.Flash.Success("OAuth2 has been unbinded.") ctx.Redirect("/user/settings/social") return } socials, err := models.GetOauthByUserId(ctx.User.Id) if err != nil { ctx.Handle(500, "user.SettingSocial(GetOauthByUserId)", err) return } ctx.Data["Socials"] = socials ctx.HTML(200, "user/social") }
func UpdateIssueMilestone(ctx *middleware.Context) { if !ctx.Repo.IsOwner { ctx.Error(403) return } issueId, err := base.StrTo(ctx.Query("issue")).Int64() if err != nil { ctx.Error(404) return } issue, err := models.GetIssueById(issueId) if err != nil { if err == models.ErrIssueNotExist { ctx.Handle(404, "issue.UpdateIssueMilestone(GetIssueById)", err) } else { ctx.Handle(500, "issue.UpdateIssueMilestone(GetIssueById)", err) } return } oldMid := issue.MilestoneId mid, _ := base.StrTo(ctx.Query("milestone")).Int64() if oldMid == mid { ctx.JSON(200, map[string]interface{}{ "ok": true, }) return } // Not check for invalid milestone id and give responsibility to owners. issue.MilestoneId = mid if err = models.ChangeMilestoneAssign(oldMid, mid, issue); err != nil { ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err) return } else if err = models.UpdateIssue(issue); err != nil { ctx.Handle(500, "issue.UpdateIssueMilestone(UpdateIssue)", err) return } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }
func UpdateMilestone(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Update Milestone" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true idx, _ := base.StrTo(params["index"]).Int64() if idx == 0 { ctx.Handle(404, "issue.UpdateMilestone", nil) return } mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, idx) if err != nil { if err == models.ErrMilestoneNotExist { ctx.Handle(404, "issue.UpdateMilestone(GetMilestoneByIndex)", err) } else { ctx.Handle(500, "issue.UpdateMilestone(GetMilestoneByIndex)", err) } return } action := params["action"] if len(action) > 0 { switch action { case "open": if mile.IsClosed { if err = models.ChangeMilestoneStatus(mile, false); err != nil { ctx.Handle(500, "issue.UpdateMilestone(ChangeMilestoneStatus)", err) return } } case "close": if !mile.IsClosed { mile.ClosedDate = time.Now() if err = models.ChangeMilestoneStatus(mile, true); err != nil { ctx.Handle(500, "issue.UpdateMilestone(ChangeMilestoneStatus)", err) return } } case "delete": if err = models.DeleteMilestone(mile); err != nil { ctx.Handle(500, "issue.UpdateMilestone(DeleteMilestone)", err) return } } ctx.Redirect(ctx.Repo.RepoLink + "/issues/milestones") return } mile.DeadlineString = mile.Deadline.UTC().Format("01/02/2006") if mile.DeadlineString == "12/31/9999" { mile.DeadlineString = "" } ctx.Data["Milestone"] = mile ctx.HTML(200, MILESTONE_EDIT) }
func Issues(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true milestoneId, _ := base.StrTo(params["milestone"]).Int() page, _ := base.StrTo(params["page"]).Int() var err error ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0, int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"]) if err != nil { ctx.Handle(200, "issue.Issues: %v", err) return } if len(params["branchname"]) == 0 { params["branchname"] = "master" } ctx.Data["Branchname"] = params["branchname"] ctx.HTML(200, "repo/issues") }
func ViewIssue(ctx *middleware.Context, params martini.Params) { index, err := base.StrTo(params["index"]).Int() if err != nil { ctx.Handle(404, "issue.ViewIssue", err) return } issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index)) if err != nil { if err == models.ErrIssueNotExist { ctx.Handle(404, "issue.ViewIssue", err) } else { ctx.Handle(200, "issue.ViewIssue", err) } return } // Get posters. u, err := models.GetUserById(issue.PosterId) if err != nil { ctx.Handle(200, "issue.ViewIssue(get poster): %v", err) return } issue.Poster = u issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink)) // Get comments. comments, err := models.GetIssueComments(issue.Id) if err != nil { ctx.Handle(200, "issue.ViewIssue(get comments): %v", err) return } // Get posters. for i := range comments { u, err := models.GetUserById(comments[i].PosterId) if err != nil { ctx.Handle(200, "issue.ViewIssue(get poster): %v", err) return } comments[i].Poster = u comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ctx.Repo.RepoLink)) } ctx.Data["Title"] = issue.Name ctx.Data["Issue"] = issue ctx.Data["Comments"] = comments ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner || (ctx.IsSigned && issue.PosterId == ctx.User.Id) ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false ctx.HTML(200, "issue/view") }
func UpdateAssignee(ctx *middleware.Context) { if !ctx.Repo.IsOwner { ctx.Error(403) return } issueId, err := base.StrTo(ctx.Query("issue")).Int64() if err != nil { ctx.Error(404) return } issue, err := models.GetIssueById(issueId) if err != nil { if err == models.ErrIssueNotExist { ctx.Handle(404, "issue.UpdateAssignee(GetIssueById)", err) } else { ctx.Handle(500, "issue.UpdateAssignee(GetIssueById)", err) } return } aid, _ := base.StrTo(ctx.Query("assigneeid")).Int64() // Not check for invalid assignne id and give responsibility to owners. issue.AssigneeId = aid if err = models.UpdateIssueUserPairByAssignee(aid, issue.Id); err != nil { ctx.Handle(500, "issue.UpdateAssignee(UpdateIssueUserPairByAssignee): %v", err) return } else if err = models.UpdateIssue(issue); err != nil { ctx.Handle(500, "issue.UpdateAssignee(UpdateIssue)", err) return } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }
func Commits(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarCommits"] = true userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { ctx.Handle(500, "repo.Commits", err) return } else if len(brs) == 0 { ctx.Handle(404, "repo.Commits", nil) return } commitsCount, err := ctx.Repo.Commit.CommitsCount() if err != nil { ctx.Handle(500, "repo.Commits(GetCommitsCount)", err) return } // Calculate and validate page number. page, _ := base.StrTo(ctx.Query("p")).Int() if page < 1 { page = 1 } lastPage := page - 1 if lastPage < 0 { lastPage = 0 } nextPage := page + 1 if nextPage*50 > commitsCount { nextPage = 0 } // Both `git log branchName` and `git log commitId` work. ctx.Data["Commits"], err = ctx.Repo.Commit.CommitsByRange(page) if err != nil { ctx.Handle(500, "repo.Commits(CommitsByRange)", err) return } ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["CommitCount"] = commitsCount ctx.Data["LastPageNum"] = lastPage ctx.Data["NextPageNum"] = nextPage ctx.HTML(200, "repo/commits") }
func WebHooksEditPost(ctx *middleware.Context, params martini.Params, form auth.NewWebhookForm) { ctx.Data["IsRepoToolbarWebHooks"] = true ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhook" hookId, _ := base.StrTo(params["id"]).Int64() if hookId == 0 { ctx.Handle(404, "setting.WebHooksEditPost", nil) return } w, err := models.GetWebhookById(hookId) if err != nil { if err == models.ErrWebhookNotExist { ctx.Handle(404, "setting.WebHooksEditPost(GetWebhookById)", nil) } else { ctx.Handle(500, "setting.WebHooksEditPost(GetWebhookById)", err) } return } if ctx.HasError() { ctx.HTML(200, HOOK_EDIT) return } ct := models.JSON if form.ContentType == "2" { ct = models.FORM } w.Url = form.Url w.ContentType = ct w.Secret = form.Secret w.HookEvent = &models.HookEvent{ PushOnly: form.PushOnly, } w.IsActive = form.Active if err := w.UpdateEvent(); err != nil { ctx.Handle(500, "setting.WebHooksEditPost(UpdateEvent)", err) return } else if err := models.UpdateWebhook(w); err != nil { ctx.Handle(500, "setting.WebHooksEditPost(WebHooksEditPost)", err) return } ctx.Flash.Success("Webhook has been updated.") ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", ctx.Repo.RepoLink, hookId)) }
func EditAuthSource(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Edit Authentication" ctx.Data["PageIsAuths"] = true id, err := base.StrTo(params["authid"]).Int64() if err != nil { ctx.Handle(404, "admin.auths.EditAuthSource", err) return } u, err := models.GetLoginSourceById(id) if err != nil { ctx.Handle(500, "admin.user.EditUser", err) return } ctx.Data["Source"] = u ctx.Data["LoginTypes"] = models.LoginTypes ctx.HTML(200, "admin/auths/edit") }
func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form auth.CreateMilestoneForm) { ctx.Data["Title"] = "Update Milestone" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true idx, _ := base.StrTo(params["index"]).Int64() if idx == 0 { ctx.Handle(404, "issue.UpdateMilestonePost", nil) return } mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, idx) if err != nil { if err == models.ErrMilestoneNotExist { ctx.Handle(404, "issue.UpdateMilestonePost(GetMilestoneByIndex)", err) } else { ctx.Handle(500, "issue.UpdateMilestonePost(GetMilestoneByIndex)", err) } return } if ctx.HasError() { ctx.HTML(200, MILESTONE_EDIT) return } var deadline time.Time if len(form.Deadline) == 0 { form.Deadline = "12/31/9999" } deadline, err = time.Parse("01/02/2006", form.Deadline) if err != nil { ctx.Handle(500, "issue.UpdateMilestonePost(time.Parse)", err) return } mile.Name = form.Title mile.Content = form.Content mile.Deadline = deadline if err = models.UpdateMilestone(mile); err != nil { ctx.Handle(500, "issue.UpdateMilestonePost(UpdateMilestone)", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/issues/milestones") }
func UpdateLabel(ctx *middleware.Context, params martini.Params, form auth.CreateLabelForm) { id, _ := base.StrTo(ctx.Query("id")).Int64() if id == 0 { ctx.Error(404) return } l := &models.Label{ Id: id, Name: form.Title, Color: form.Color, } if err := models.UpdateLabel(l); err != nil { ctx.Handle(500, "issue.UpdateLabel(UpdateLabel)", err) return } ctx.Redirect(ctx.Repo.RepoLink + "/issues") }
func EditUser(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Edit Account" ctx.Data["PageIsUsers"] = true uid, err := base.StrTo(params["userid"]).Int() if err != nil { ctx.Handle(404, "admin.user.EditUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { ctx.Handle(500, "admin.user.EditUser", err) return } ctx.Data["User"] = u ctx.HTML(200, "admin/users/edit") }
func WebHooksEditPost(ctx *middleware.Context, params martini.Params, form auth.NewWebhookForm) { ctx.Data["IsRepoToolbarWebHooks"] = true ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhook" if ctx.HasError() { ctx.HTML(200, "repo/hooks_add") return } hookId, _ := base.StrTo(params["id"]).Int64() if hookId == 0 { ctx.Handle(404, "setting.WebHooksEditPost", nil) return } ct := models.CT_JSON if form.ContentType == "2" { ct = models.CT_FORM } w := &models.Webhook{ Id: hookId, RepoId: ctx.Repo.Repository.Id, Url: form.Url, ContentType: ct, Secret: form.Secret, HookEvent: &models.HookEvent{ PushOnly: form.PushOnly, }, IsActive: form.Active, } if err := w.SaveEvent(); err != nil { ctx.Handle(500, "setting.WebHooksEditPost(SaveEvent)", err) return } else if err := models.UpdateWebhook(w); err != nil { ctx.Handle(500, "setting.WebHooksEditPost(WebHooksEditPost)", err) return } ctx.Flash.Success("Webhook has been updated.") ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", ctx.Repo.RepoLink, hookId)) }
func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { idx, _ := base.StrTo(params["index"]).Int64() if idx <= 0 { ctx.Error(404) return } issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx) if err != nil { if err == models.ErrIssueNotExist { ctx.Handle(404, "issue.UpdateIssue", err) } else { ctx.Handle(500, "issue.UpdateIssue(GetIssueByIndex)", err) } return } if ctx.User.Id != issue.PosterId && !ctx.Repo.IsOwner { ctx.Error(403) return } issue.Name = form.IssueName issue.MilestoneId = form.MilestoneId issue.AssigneeId = form.AssigneeId issue.LabelIds = form.Labels issue.Content = form.Content // try get content from text, ignore conflict with preview ajax if form.Content == "" { issue.Content = ctx.Query("text") } if err = models.UpdateIssue(issue); err != nil { ctx.Handle(500, "issue.UpdateIssue(UpdateIssue)", err) return } ctx.JSON(200, map[string]interface{}{ "ok": true, "title": issue.Name, "content": string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink)), }) }
func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) { ctx.Data["Title"] = "Edit Account" ctx.Data["PageIsUsers"] = true uid, err := base.StrTo(params["userid"]).Int() if err != nil { ctx.Handle(200, "admin.user.EditUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { ctx.Handle(200, "admin.user.EditUser", err) return } if ctx.Req.Method == "GET" { ctx.Data["User"] = u ctx.HTML(200, "admin/users/edit") return } u.Email = form.Email u.Website = form.Website u.Location = form.Location u.Avatar = base.EncodeMd5(form.Avatar) u.AvatarEmail = form.Avatar u.IsActive = form.Active == "on" u.IsAdmin = form.Admin == "on" if err := models.UpdateUser(u); err != nil { ctx.Handle(200, "admin.user.EditUser", err) return } ctx.Data["IsSuccess"] = true ctx.Data["User"] = u ctx.HTML(200, "admin/users/edit") log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.User.LowerName) }
func ViewIssue(ctx *middleware.Context, params martini.Params) { index, err := base.StrTo(params["index"]).Int() if err != nil { ctx.Handle(404, "issue.ViewIssue", err) return } issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index)) if err != nil { if err == models.ErrIssueNotExist { ctx.Handle(404, "issue.ViewIssue", err) } else { ctx.Handle(200, "issue.ViewIssue", err) } return } ctx.Data["Title"] = issue.Name ctx.Data["Issue"] = issue ctx.HTML(200, "issue/view") }
func (i *Issue) GetLabels() error { if len(i.LabelIds) < 3 { return nil } strIds := strings.Split(strings.TrimSuffix(i.LabelIds[1:], "|"), "|$") i.Labels = make([]*Label, 0, len(strIds)) for _, strId := range strIds { id, _ := base.StrTo(strId).Int64() if id > 0 { l, err := GetLabelById(id) if err != nil { if err == ErrLabelNotExist { continue } return err } i.Labels = append(i.Labels, l) } } return nil }