// https://github.com/gigforks/go-gogs-client/wiki/Repositories#list-your-repositories func ListMyRepos(ctx *context.APIContext) { ownRepos, err := models.GetRepositories(ctx.User.Id, true) if err != nil { ctx.Error(500, "GetRepositories", err) return } numOwnRepos := len(ownRepos) accessibleRepos, err := ctx.User.GetRepositoryAccesses() if err != nil { ctx.Error(500, "GetRepositoryAccesses", err) return } repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos)) for i := range ownRepos { repos[i] = convert.ToRepository(ctx.User, ownRepos[i], api.Permission{true, true, true}) } i := numOwnRepos for repo, access := range accessibleRepos { repos[i] = convert.ToRepository(repo.Owner, repo, api.Permission{ Admin: access >= models.ACCESS_MODE_ADMIN, Push: access >= models.ACCESS_MODE_WRITE, Pull: true, }) i++ } ctx.JSON(200, &repos) }
func showOrgProfile(ctx *context.Context) { ctx.SetParams(":org", ctx.Params(":username")) context.HandleOrgAssignment(ctx) if ctx.Written() { return } org := ctx.Org.Organization ctx.Data["Title"] = org.FullName if ctx.IsSigned { if ctx.User.IsAdmin { repos, err := models.GetRepositories(org.Id, true) if err != nil { ctx.Handle(500, "GetRepositoriesAsAdmin", err) return } ctx.Data["Repos"] = repos } else { if err := org.GetUserRepositories(ctx.User.Id); err != nil { ctx.Handle(500, "GetUserRepositories", err) return } ctx.Data["Repos"] = org.Repos } } else { repos, err := models.GetRepositories(org.Id, false) if err != nil { ctx.Handle(500, "GetRepositories", err) return } ctx.Data["Repos"] = repos } if err := org.GetMembers(); err != nil { ctx.Handle(500, "GetMembers", err) return } ctx.Data["Members"] = org.Members ctx.Data["Teams"] = org.Teams ctx.HTML(200, ORG_HOME) }
func Profile(ctx *context.Context) { uname := ctx.Params(":username") // Special handle for FireFox requests favicon.ico. if uname == "favicon.ico" { ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png")) return } else if strings.HasSuffix(uname, ".png") { ctx.Error(404) return } isShowKeys := false if strings.HasSuffix(uname, ".keys") { isShowKeys = true } u := GetUserByName(ctx, strings.TrimSuffix(uname, ".keys")) if ctx.Written() { return } // Show SSH keys. if isShowKeys { ShowSSHKeys(ctx, u.Id) return } if u.IsOrganization() { showOrgProfile(ctx) return } ctx.Data["Title"] = u.DisplayName() ctx.Data["PageIsUserProfile"] = true ctx.Data["Owner"] = u orgs, err := models.GetOrgsByUserID(u.Id, ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.Id == u.Id)) if err != nil { ctx.Handle(500, "GetOrgsByUserIDDesc", err) return } ctx.Data["Orgs"] = orgs tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": retrieveFeeds(ctx, u.Id, -1, 0, true) if ctx.Written() { return } default: var err error ctx.Data["Repos"], err = models.GetRepositories(u.Id, ctx.IsSigned && ctx.User.Id == u.Id) if err != nil { ctx.Handle(500, "GetRepositories", err) return } } ctx.HTML(200, PROFILE) }
func Dashboard(ctx *context.Context) { ctxUser := getDashboardContextUser(ctx) ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard") ctx.Data["PageIsDashboard"] = true ctx.Data["PageIsNews"] = true if ctx.Written() { return } if !ctxUser.IsOrganization() { collaborateRepos, err := ctx.User.GetAccessibleRepositories() if err != nil { ctx.Handle(500, "GetAccessibleRepositories", err) return } for i := range collaborateRepos { if err = collaborateRepos[i].GetOwner(); err != nil { ctx.Handle(500, "GetOwner: "+collaborateRepos[i].Name, err) return } } ctx.Data["CollaborateCount"] = len(collaborateRepos) ctx.Data["CollaborativeRepos"] = collaborateRepos } var repos []*models.Repository if ctxUser.IsOrganization() { if err := ctxUser.GetUserRepositories(ctx.User.Id); err != nil { ctx.Handle(500, "GetUserRepositories", err) return } repos = ctxUser.Repos } else { var err error repos, err = models.GetRepositories(ctxUser.Id, true) if err != nil { ctx.Handle(500, "GetRepositories", err) return } } ctx.Data["Repos"] = repos // Get mirror repositories. mirrors := make([]*models.Repository, 0, 5) for _, repo := range repos { if repo.IsMirror { if err := repo.GetMirror(); err != nil { ctx.Handle(500, "GetMirror: "+repo.Name, err) return } mirrors = append(mirrors, repo) } } ctx.Data["MirrorCount"] = len(mirrors) ctx.Data["Mirrors"] = mirrors retrieveFeeds(ctx, ctxUser.Id, ctx.User.Id, 0, false) if ctx.Written() { return } ctx.HTML(200, DASHBOARD) }