func NewTeam(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeamsNew"] = true ctx.Data["Team"] = &models.Team{} ctx.HTML(200, TEAM_NEW) }
func HTTPBackend(ctx *context.Context, cfg *serviceConfig) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { for _, route := range routes { r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name if m := route.reg.FindStringSubmatch(r.URL.Path); m != nil { if route.method != r.Method { if r.Proto == "HTTP/1.1" { w.WriteHeader(http.StatusMethodNotAllowed) w.Write([]byte("Method Not Allowed")) } else { w.WriteHeader(http.StatusBadRequest) w.Write([]byte("Bad Request")) } return } file := strings.Replace(r.URL.Path, m[1]+"/", "", 1) dir, err := getGitRepoPath(m[1]) if err != nil { log.GitLogger.Error(4, err.Error()) ctx.Handle(http.StatusNotFound, "HTTPBackend", err) return } route.handler(serviceHandler{cfg, w, r, dir, file}) return } } ctx.Handle(http.StatusNotFound, "HTTPBackend", nil) return } }
func SettingsDeleteAvatar(ctx *context.Context) { if err := ctx.Org.Organization.DeleteAvatar(); err != nil { ctx.Flash.Error(err.Error()) } ctx.Redirect(ctx.Org.OrgLink + "/settings") }
func ChangeCollaborationAccessMode(ctx *context.Context) { if err := ctx.Repo.Repository.ChangeCollaborationAccessMode( ctx.QueryInt64("uid"), models.AccessMode(ctx.QueryInt("mode"))); err != nil { log.Error(4, "ChangeCollaborationAccessMode: %v", err) } }
// retrieveFeeds loads feeds from database by given context user. // The user could be organization so it is not always the logged in user, // which is why we have to explicitly pass the context user ID. func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID, offset int64, isProfile bool) { actions, err := models.GetFeeds(ctxUser, userID, offset, isProfile) if err != nil { ctx.Handle(500, "GetFeeds", err) return } // Check access of private repositories. feeds := make([]*models.Action, 0, len(actions)) unameAvatars := make(map[string]string) for _, act := range actions { // Cache results to reduce queries. _, ok := unameAvatars[act.ActUserName] if !ok { u, err := models.GetUserByName(act.ActUserName) if err != nil { if models.IsErrUserNotExist(err) { continue } ctx.Handle(500, "GetUserByName", err) return } unameAvatars[act.ActUserName] = u.RelAvatarLink() } act.ActAvatar = unameAvatars[act.ActUserName] feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds }
func SettingsDeleteAvatar(ctx *context.Context) { if err := ctx.User.DeleteAvatar(); err != nil { ctx.Flash.Error(err.Error()) } ctx.Redirect(setting.AppSubUrl + "/user/settings/avatar") }
func EditTeam(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["PageIsOrgTeams"] = true ctx.Data["team_name"] = ctx.Org.Team.Name ctx.Data["desc"] = ctx.Org.Team.Description ctx.HTML(200, TEAM_NEW) }
func Monitor(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.monitor") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminMonitor"] = true ctx.Data["Processes"] = process.Processes ctx.Data["Entries"] = cron.ListTasks() ctx.HTML(200, MONITOR) }
func checkHookType(ctx *context.Context) string { hookType := strings.ToLower(ctx.Params(":type")) if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) { ctx.Handle(404, "checkHookType", nil) return "" } return hookType }
func TeamRepositories(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["PageIsOrgTeams"] = true if err := ctx.Org.Team.GetRepositories(); err != nil { ctx.Handle(500, "GetRepositories", err) return } ctx.HTML(200, TEAM_REPOSITORIES) }
func TeamMembers(ctx *context.Context) { ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["PageIsOrgTeams"] = true if err := ctx.Org.Team.GetMembers(); err != nil { ctx.Handle(500, "GetMembers", err) return } ctx.HTML(200, TEAM_MEMBERS) }
func SettingsAvatarPost(ctx *context.Context, form auth.AvatarForm) { if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.update_avatar_success")) } ctx.Redirect(setting.AppSubUrl + "/user/settings/avatar") }
func SettingsAvatar(ctx *context.Context, form auth.AvatarForm) { form.Source = auth.AVATAR_LOCAL if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success")) } ctx.Redirect(ctx.Org.OrgLink + "/settings") }
func DeleteFile(ctx *context.Context) { ctx.Data["PageIsDelete"] = true ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName ctx.Data["TreePath"] = ctx.Repo.TreePath ctx.Data["commit_summary"] = "" ctx.Data["commit_message"] = "" ctx.Data["commit_choice"] = "direct" ctx.Data["new_branch_name"] = "" ctx.HTML(200, DELETE_FILE) }
func MustEnableWiki(ctx *context.Context) { if !ctx.Repo.Repository.EnableWiki { ctx.Handle(404, "MustEnableWiki", nil) return } if ctx.Repo.Repository.EnableExternalWiki { ctx.Redirect(ctx.Repo.Repository.ExternalWikiURL) return } }
func NewWiki(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["PageIsWiki"] = true ctx.Data["RequireSimpleMDE"] = true if !ctx.Repo.Repository.HasWiki() { ctx.Data["title"] = "Home" } ctx.HTML(200, WIKI_NEW) }
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 TemplatePreview(ctx *context.Context) { ctx.Data["User"] = models.User{Name: "Unknown"} ctx.Data["AppName"] = setting.AppName ctx.Data["AppVer"] = setting.AppVer ctx.Data["AppUrl"] = setting.AppUrl ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374" ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60 ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60 ctx.Data["CurDbValue"] = "" ctx.HTML(200, base.TplName(ctx.Params("*"))) }
func SetEditorconfigIfExists(ctx *context.Context) { ec, err := ctx.Repo.GetEditorconfig() if err != nil && !git.IsErrNotExist(err) { description := fmt.Sprintf("Error while getting .editorconfig file: %v", err) if err := models.CreateRepositoryNotice(description); err != nil { ctx.Handle(500, "ErrCreatingReporitoryNotice", err) } return } ctx.Data["Editorconfig"] = ec }
func ExploreRepos(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("explore") ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreRepositories"] = true RenderRepoSearch(ctx, &RepoSearchOptions{ Counter: models.CountRepositories, Ranger: models.GetRecentUpdatedRepositories, PageSize: setting.UI.ExplorePagingNum, OrderBy: "updated_unix DESC", TplName: EXPLORE_REPOS, }) }
func Members(ctx *context.Context) { org := ctx.Org.Organization ctx.Data["Title"] = org.FullName ctx.Data["PageIsOrgMembers"] = true if err := org.GetMembers(); err != nil { ctx.Handle(500, "GetMembers", err) return } ctx.Data["Members"] = org.Members ctx.HTML(200, MEMBERS) }
func Config(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.config") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminConfig"] = true ctx.Data["AppUrl"] = setting.AppUrl ctx.Data["Domain"] = setting.Domain ctx.Data["OfflineMode"] = setting.OfflineMode ctx.Data["DisableRouterLog"] = setting.DisableRouterLog ctx.Data["RunUser"] = setting.RunUser ctx.Data["RunMode"] = strings.Title(macaron.Env) ctx.Data["RepoRootPath"] = setting.RepoRootPath ctx.Data["StaticRootPath"] = setting.StaticRootPath ctx.Data["LogRootPath"] = setting.LogRootPath ctx.Data["ScriptType"] = setting.ScriptType ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser ctx.Data["SSH"] = setting.SSH ctx.Data["Service"] = setting.Service ctx.Data["DbCfg"] = models.DbCfg ctx.Data["Webhook"] = setting.Webhook ctx.Data["MailerEnabled"] = false if setting.MailService != nil { ctx.Data["MailerEnabled"] = true ctx.Data["Mailer"] = setting.MailService } ctx.Data["CacheAdapter"] = setting.CacheAdapter ctx.Data["CacheInterval"] = setting.CacheInterval ctx.Data["CacheConn"] = setting.CacheConn ctx.Data["SessionConfig"] = setting.SessionConfig ctx.Data["DisableGravatar"] = setting.DisableGravatar ctx.Data["EnableFederatedAvatar"] = setting.EnableFederatedAvatar ctx.Data["Git"] = setting.Git type logger struct { Mode, Config string } loggers := make([]*logger, len(setting.LogModes)) for i := range setting.LogModes { loggers[i] = &logger{setting.LogModes[i], setting.LogConfigs[i]} } ctx.Data["Loggers"] = loggers ctx.HTML(200, CONFIG) }
func Migrate(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("new_migrate") ctx.Data["private"] = ctx.User.LastRepoVisibility ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate ctx.Data["mirror"] = ctx.Query("mirror") == "1" ctxUser := checkContextUser(ctx, ctx.QueryInt64("org")) if ctx.Written() { return } ctx.Data["ContextUser"] = ctxUser ctx.HTML(200, MIGRATE) }
func ShowSSHKeys(ctx *context.Context, uid int64) { keys, err := models.ListPublicKeys(uid) if err != nil { ctx.Handle(500, "ListPublicKeys", err) return } var buf bytes.Buffer for i := range keys { buf.WriteString(keys[i].OmitEmail()) buf.WriteString("\n") } ctx.PlainText(200, buf.Bytes()) }
// getDashboardContextUser finds out dashboard is viewing as which context user. func getDashboardContextUser(ctx *context.Context) *models.User { ctxUser := ctx.User orgName := ctx.Params(":org") if len(orgName) > 0 { // Organization. org, err := models.GetUserByName(orgName) if err != nil { if models.IsErrUserNotExist(err) { ctx.Handle(404, "GetUserByName", err) } else { ctx.Handle(500, "GetUserByName", err) } return nil } ctxUser = org } ctx.Data["ContextUser"] = ctxUser if err := ctx.User.GetOrganizations(true); err != nil { ctx.Handle(500, "GetOrganizations", err) return nil } ctx.Data["Orgs"] = ctx.User.Orgs return ctxUser }
func ExploreUsers(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("explore") ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreUsers"] = true RenderUserSearch(ctx, &UserSearchOptions{ Type: models.USER_TYPE_INDIVIDUAL, Counter: models.CountUsers, Ranger: models.Users, PageSize: setting.UI.ExplorePagingNum, OrderBy: "updated_unix DESC", TplName: EXPLORE_USERS, }) }
func ExploreOrganizations(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("explore") ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreOrganizations"] = true RenderUserSearch(ctx, &UserSearchOptions{ Type: models.USER_TYPE_ORGANIZATION, Counter: models.CountOrganizations, Ranger: models.Organizations, PageSize: setting.UI.ExplorePagingNum, OrderBy: "updated_unix DESC", TplName: EXPLORE_ORGANIZATIONS, }) }
func Organizations(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.organizations") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminOrganizations"] = true routers.RenderUserSearch(ctx, &routers.UserSearchOptions{ Type: models.USER_TYPE_ORGANIZATION, Counter: models.CountOrganizations, Ranger: models.Organizations, PageSize: setting.UI.Admin.OrgPagingNum, OrderBy: "id ASC", TplName: ORGS, }) }
func Repos(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.repositories") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminRepositories"] = true routers.RenderRepoSearch(ctx, &routers.RepoSearchOptions{ Counter: models.CountRepositories, Ranger: models.Repositories, Private: true, PageSize: setting.UI.Admin.RepoPagingNum, OrderBy: "id ASC", TplName: REPOS, }) }
func SearchCommits(ctx *context.Context) { ctx.Data["PageIsCommits"] = true keyword := ctx.Query("q") if len(keyword) == 0 { ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName) return } commits, err := ctx.Repo.Commit.SearchCommits(keyword) if err != nil { ctx.Handle(500, "SearchCommits", err) return } commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Keyword"] = keyword ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["CommitCount"] = commits.Len() ctx.Data["Branch"] = ctx.Repo.BranchName ctx.HTML(200, COMMITS) }