func retrieveFeeds(ctx *middleware.Context, uid, offset int64, isProfile bool) { actions, err := models.GetFeeds(uid, 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.AvatarLink() } act.ActAvatar = unameAvatars[act.ActUserName] feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds }
func Profile(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Profile" // TODO: Need to check view self or others. user, err := models.GetUserByName(params["username"]) if err != nil { ctx.Handle(200, "user.Profile", err) return } ctx.Data["Owner"] = user tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": feeds, err := models.GetFeeds(user.Id, 0, true) if err != nil { ctx.Handle(200, "user.Profile", err) return } ctx.Data["Feeds"] = feeds default: repos, err := models.GetRepositories(user) if err != nil { ctx.Handle(200, "user.Profile", err) return } ctx.Data["Repos"] = repos } ctx.Data["PageIsUserProfile"] = true ctx.HTML(200, "user/profile") }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Dashboard" ctx.Data["PageIsUserDashboard"] = true repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id}, true) if err != nil { ctx.Handle(500, "user.Dashboard", err) return } ctx.Data["MyRepos"] = repos actions, err := models.GetFeeds(ctx.User.Id, 0, false) if err != nil { ctx.Handle(500, "user.Dashboard", err) return } feeds := make([]*models.Action, 0, len(actions)) for _, act := range actions { if act.IsPrivate { if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName, models.AU_READABLE); !has { continue } } feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds ctx.HTML(200, "user/dashboard") }
func Profile(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Profile" ctx.Data["PageIsUserProfile"] = true user, err := models.GetUserByName(params["username"]) if err != nil { if err == models.ErrUserNotExist { ctx.Handle(404, "user.Profile(GetUserByName)", err) } else { ctx.Handle(500, "user.Profile(GetUserByName)", err) } return } ctx.Data["Owner"] = user tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": ctx.Data["Feeds"], err = models.GetFeeds(user.Id, 0, true) if err != nil { ctx.Handle(500, "user.Profile(GetFeeds)", err) return } default: ctx.Data["Repos"], err = models.GetRepositories(user.Id, ctx.IsSigned && ctx.User.Id == user.Id) if err != nil { ctx.Handle(500, "user.Profile(GetRepositories)", err) return } } ctx.HTML(200, "user/profile") }
func Feeds(ctx *middleware.Context, form auth.FeedsForm) { actions, err := models.GetFeeds(form.UserId, form.Page*20, false) if err != nil { ctx.JSON(500, err) } feeds := make([]string, len(actions)) for i := range actions { feeds[i] = fmt.Sprintf(TPL_FEED, base.ActionIcon(actions[i].OpType), base.TimeSince(actions[i].Created), base.ActionDesc(actions[i])) } ctx.JSON(200, &feeds) }
func Profile(ctx *middleware.Context) { ctx.Data["Title"] = "Profile" ctx.Data["PageIsUserProfile"] = true uname := ctx.Params(":username") // Special handle for FireFox requests favicon.ico. if uname == "favicon.ico" { ctx.Redirect("/img/favicon.png") return } u, err := models.GetUserByName(uname) if err != nil { if err == models.ErrUserNotExist { ctx.Handle(404, "GetUserByName", err) } else { ctx.Handle(500, "GetUserByName", err) } return } if u.IsOrganization() { ctx.Redirect("/org/" + u.Name) return } // For security reason, hide e-mail address for anonymous visitors. if !ctx.IsSigned { u.Email = "" } ctx.Data["Owner"] = u tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": ctx.Data["Feeds"], err = models.GetFeeds(u.Id, 0, true) if err != nil { ctx.Handle(500, "GetFeeds", err) return } default: 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 *middleware.Context) { ctx.Data["Title"] = "Dashboard" ctx.Data["PageIsUserDashboard"] = true repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id}) if err != nil { ctx.Handle(200, "user.Dashboard", err) return } ctx.Data["MyRepos"] = repos feeds, err := models.GetFeeds(ctx.User.Id, 0, false) if err != nil { ctx.Handle(200, "user.Dashboard", err) return } ctx.Data["Feeds"] = feeds ctx.HTML(200, "user/dashboard") }
func Profile(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Profile" ctx.Data["PageIsUserProfile"] = true u, err := models.GetUserByName(params["username"]) if err != nil { if err == models.ErrUserNotExist { ctx.Handle(404, "user.Profile(GetUserByName)", err) } else { ctx.Handle(500, "user.Profile(GetUserByName)", err) } return } if u.IsOrganization() { ctx.Redirect("/org/" + u.Name) return } // For security reason, hide e-mail address for anonymous visitors. if !ctx.IsSigned { u.Email = "" } ctx.Data["Owner"] = u tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": ctx.Data["Feeds"], err = models.GetFeeds(u.Id, 0, true) if err != nil { ctx.Handle(500, "user.Profile(GetFeeds)", err) return } default: ctx.Data["Repos"], err = models.GetRepositories(u.Id, ctx.IsSigned && ctx.User.Id == u.Id) if err != nil { ctx.Handle(500, "user.Profile(GetRepositories)", err) return } } ctx.HTML(200, PROFILE) }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Dashboard" ctx.Data["PageIsUserDashboard"] = true if err := ctx.User.GetOrganizations(); err != nil { ctx.Handle(500, "home.Dashboard(GetOrganizations)", err) return } ctx.Data["Orgs"] = ctx.User.Orgs ctx.Data["ContextUser"] = ctx.User var err error ctx.Data["MyRepos"], err = models.GetRepositories(ctx.User.Id, true) if err != nil { ctx.Handle(500, "home.Dashboard(GetRepositories)", err) return } ctx.Data["CollaborativeRepos"], err = models.GetCollaborativeRepos(ctx.User.Name) if err != nil { ctx.Handle(500, "home.Dashboard(GetCollaborativeRepos)", err) return } actions, err := models.GetFeeds(ctx.User.Id, 0, false) if err != nil { ctx.Handle(500, "home.Dashboard(GetFeeds)", err) return } // Check access of private repositories. feeds := make([]*models.Action, 0, len(actions)) for _, act := range actions { if act.IsPrivate { if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName, models.READABLE); !has { continue } } feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds ctx.HTML(200, DASHBOARD) }
func Feeds(ctx *middleware.Context, form auth.FeedsForm) { actions, err := models.GetFeeds(form.UserId, form.Page*20, false) if err != nil { ctx.JSON(500, err) return } feeds := make([]string, 0, len(actions)) for _, act := range actions { if act.IsPrivate { if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName, models.AU_READABLE); !has { continue } } feeds = append(feeds, fmt.Sprintf(TPL_FEED, base.ActionIcon(act.OpType), base.TimeSince(act.Created), base.ActionDesc(act))) } ctx.JSON(200, &feeds) }
func Dashboard(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Dashboard" ctx.Data["PageIsUserDashboard"] = true ctx.Data["PageIsOrgDashboard"] = true org, err := models.GetUserByName(params["org"]) if err != nil { if err == models.ErrUserNotExist { ctx.Handle(404, "org.Dashboard(GetUserByName)", err) } else { ctx.Handle(500, "org.Dashboard(GetUserByName)", err) } return } if err := ctx.User.GetOrganizations(); err != nil { ctx.Handle(500, "home.Dashboard(GetOrganizations)", err) return } ctx.Data["Orgs"] = ctx.User.Orgs ctx.Data["ContextUser"] = org ctx.Data["MyRepos"], err = models.GetRepositories(org.Id, true) if err != nil { ctx.Handle(500, "org.Dashboard(GetRepositories)", err) return } actions, err := models.GetFeeds(org.Id, 0, false) if err != nil { ctx.Handle(500, "org.Dashboard(GetFeeds)", err) return } ctx.Data["Feeds"] = actions ctx.HTML(200, user.DASHBOARD) }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("dashboard") ctx.Data["PageIsDashboard"] = true ctx.Data["PageIsNews"] = true var ctxUser *models.User // Check context type. orgName := ctx.Params(":org") if len(orgName) > 0 { // Organization. org, err := models.GetUserByName(orgName) if err != nil { if err == models.ErrUserNotExist { ctx.Handle(404, "GetUserByName", err) } else { ctx.Handle(500, "GetUserByName", err) } return } ctxUser = org } else { // Normal user. ctxUser = ctx.User collaborates, err := models.GetCollaborativeRepos(ctxUser.Name) if err != nil { ctx.Handle(500, "GetCollaborativeRepos", err) return } ctx.Data["CollaborateCount"] = len(collaborates) ctx.Data["CollaborativeRepos"] = collaborates } ctx.Data["ContextUser"] = ctxUser if err := ctx.User.GetOrganizations(); err != nil { ctx.Handle(500, "GetOrganizations", err) return } ctx.Data["Orgs"] = ctx.User.Orgs 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, len(repos)/2) 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 // Get feeds. actions, err := models.GetFeeds(ctxUser.Id, 0, false) if err != nil { ctx.Handle(500, "GetFeeds", err) return } // Check access of private repositories. feeds := make([]*models.Action, 0, len(actions)) for _, act := range actions { if act.IsPrivate { if has, _ := models.HasAccess(ctxUser.Name, act.RepoUserName+"/"+act.RepoName, models.READABLE); !has { continue } } feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds ctx.HTML(200, DASHBOARD) }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("dashboard") ctx.Data["PageIsDashboard"] = true ctx.Data["PageIsNews"] = true ctxUser := getDashboardContextUser(ctx) if ctx.Written() { return } // Check context type. if !ctxUser.IsOrganization() { // Normal user. ctxUser = ctx.User collaborates, err := ctx.User.GetAccessibleRepositories() if err != nil { ctx.Handle(500, "GetAccessibleRepositories", err) return } repositories := make([]*models.Repository, 0, len(collaborates)) for repo := range collaborates { repositories = append(repositories, repo) } ctx.Data["CollaborateCount"] = len(repositories) ctx.Data["CollaborativeRepos"] = repositories } 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, len(repos)/2) 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 // Get feeds. actions, err := models.GetFeeds(ctxUser.Id, 0, false) if err != nil { ctx.Handle(500, "GetFeeds", err) return } // Check access of private repositories. feeds := make([]*models.Action, 0, len(actions)) for _, act := range actions { if act.IsPrivate { // This prevents having to retrieve the repository for each action repo := &models.Repository{ID: act.RepoID, IsPrivate: true} if act.RepoUserName != ctx.User.LowerName { if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { continue } } } // FIXME: cache results? u, err := models.GetUserByName(act.ActUserName) if err != nil { if models.IsErrUserNotExist(err) { continue } ctx.Handle(500, "GetUserByName", err) return } act.ActAvatar = u.AvatarLink() feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds ctx.HTML(200, DASHBOARD) }
func Profile(ctx *middleware.Context) { ctx.Data["Title"] = "Profile" ctx.Data["PageIsUserProfile"] = true uname := ctx.Params(":username") // Special handle for FireFox requests favicon.ico. if uname == "favicon.ico" { ctx.Redirect(setting.AppSubUrl + "/img/favicon.png") return } isShowKeys := false if strings.HasSuffix(uname, ".keys") { isShowKeys = true uname = strings.TrimSuffix(uname, ".keys") } u, err := models.GetUserByName(uname) if err != nil { if models.IsErrUserNotExist(err) { ctx.Handle(404, "GetUserByName", err) } else { ctx.Handle(500, "GetUserByName", err) } return } // Show SSH keys. if isShowKeys { ShowSSHKeys(ctx, u.Id) return } if u.IsOrganization() { ctx.Redirect(setting.AppSubUrl + "/org/" + u.Name) return } ctx.Data["Owner"] = u tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": actions, err := models.GetFeeds(u.Id, 0, false) if err != nil { ctx.Handle(500, "GetFeeds", err) return } feeds := make([]*models.Action, 0, len(actions)) for _, act := range actions { if act.IsPrivate { if !ctx.IsSigned { continue } // This prevents having to retrieve the repository for each action repo := &models.Repository{ID: act.RepoID, IsPrivate: true} if act.RepoUserName != ctx.User.LowerName { if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { continue } } } // FIXME: cache results? u, err := models.GetUserByName(act.ActUserName) if err != nil { if models.IsErrUserNotExist(err) { continue } ctx.Handle(500, "GetUserByName", err) return } act.ActAvatar = u.AvatarLink() feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds default: 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) }