Use a standalone struct name for Organization (#17632)
* Use a standalone struct name for Organization * recover unnecessary change * make the code readable * Fix template failure * Fix template failure * Move HasMemberWithUserID to org * Fix test * Remove unnecessary user type check * Fix test Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
a09b40de8d
commit
7a03473159
43 changed files with 335 additions and 259 deletions
|
@ -54,7 +54,7 @@ func CreateOrg(ctx *context.APIContext) {
|
|||
visibility = api.VisibilityModes[form.Visibility]
|
||||
}
|
||||
|
||||
org := &models.User{
|
||||
org := &models.Organization{
|
||||
Name: form.UserName,
|
||||
FullName: form.FullName,
|
||||
Description: form.Description,
|
||||
|
@ -117,7 +117,7 @@ func GetAllOrgs(ctx *context.APIContext) {
|
|||
}
|
||||
orgs := make([]*api.Organization, len(users))
|
||||
for i := range users {
|
||||
orgs[i] = convert.ToOrganization(users[i])
|
||||
orgs[i] = convert.ToOrganization(models.OrgFromUser(users[i]))
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||
|
|
|
@ -59,7 +59,7 @@ func ListHooks(ctx *context.APIContext) {
|
|||
|
||||
hooks := make([]*api.Hook, len(orgHooks))
|
||||
for i, hook := range orgHooks {
|
||||
hooks[i] = convert.ToHook(ctx.Org.Organization.HomeLink(), hook)
|
||||
hooks[i] = convert.ToHook(ctx.Org.Organization.AsUser().HomeLink(), hook)
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
|
@ -95,7 +95,7 @@ func GetHook(ctx *context.APIContext) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), hook))
|
||||
ctx.JSON(http.StatusOK, convert.ToHook(org.AsUser().HomeLink(), hook))
|
||||
}
|
||||
|
||||
// CreateHook create a hook for an organization
|
||||
|
|
|
@ -56,7 +56,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization))
|
||||
ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization.AsUser()))
|
||||
}
|
||||
|
||||
// CreateLabel create a label for a repository
|
||||
|
@ -104,7 +104,7 @@ func CreateLabel(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization))
|
||||
ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
|
||||
}
|
||||
|
||||
// GetLabel get label by organization and label id
|
||||
|
@ -149,7 +149,7 @@ func GetLabel(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization))
|
||||
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
|
||||
}
|
||||
|
||||
// EditLabel modify a label for an Organization
|
||||
|
@ -214,7 +214,7 @@ func EditLabel(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization))
|
||||
ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
|
||||
}
|
||||
|
||||
// DeleteLabel delete a label for an organization
|
||||
|
|
|
@ -31,7 +31,7 @@ func listUserOrgs(ctx *context.APIContext, u *models.User) {
|
|||
}
|
||||
|
||||
maxResults := len(orgs)
|
||||
orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.User)
|
||||
orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.Organization)
|
||||
|
||||
apiOrgs := make([]*api.Organization, len(orgs))
|
||||
for i := range orgs {
|
||||
|
@ -141,7 +141,8 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
authorizeLevel, err := o.GetOrgUserMaxAuthorizeLevel(u.ID)
|
||||
org := models.OrgFromUser(o)
|
||||
authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(u.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetOrgUserAuthorizeLevel", err)
|
||||
return
|
||||
|
@ -160,7 +161,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
|
|||
op.IsOwner = true
|
||||
}
|
||||
|
||||
op.CanCreateRepository, err = o.CanCreateOrgRepo(u.ID)
|
||||
op.CanCreateRepository, err = org.CanCreateOrgRepo(u.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
||||
return
|
||||
|
@ -212,7 +213,7 @@ func GetAll(ctx *context.APIContext) {
|
|||
}
|
||||
orgs := make([]*api.Organization, len(publicOrgs))
|
||||
for i := range publicOrgs {
|
||||
orgs[i] = convert.ToOrganization(publicOrgs[i])
|
||||
orgs[i] = convert.ToOrganization(models.OrgFromUser(publicOrgs[i]))
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||
|
@ -252,7 +253,7 @@ func Create(ctx *context.APIContext) {
|
|||
visibility = api.VisibilityModes[form.Visibility]
|
||||
}
|
||||
|
||||
org := &models.User{
|
||||
org := &models.Organization{
|
||||
Name: form.UserName,
|
||||
FullName: form.FullName,
|
||||
Description: form.Description,
|
||||
|
@ -295,7 +296,7 @@ func Get(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/Organization"
|
||||
|
||||
if !models.HasOrgOrUserVisible(ctx.Org.Organization, ctx.User) {
|
||||
if !models.HasOrgOrUserVisible(ctx.Org.Organization.AsUser(), ctx.User) {
|
||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
||||
return
|
||||
}
|
||||
|
@ -337,7 +338,7 @@ func Edit(ctx *context.APIContext) {
|
|||
if form.RepoAdminChangeTeamAccess != nil {
|
||||
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
|
||||
}
|
||||
if err := models.UpdateUserCols(org,
|
||||
if err := models.UpdateUserCols(org.AsUser(),
|
||||
"full_name", "description", "website", "location",
|
||||
"visibility", "repo_admin_change_team_access",
|
||||
); err != nil {
|
||||
|
|
|
@ -102,7 +102,7 @@ func ListUserTeams(ctx *context.APIContext) {
|
|||
for i := range teams {
|
||||
apiOrg, ok := cache[teams[i].OrgID]
|
||||
if !ok {
|
||||
org, err := models.GetUserByID(teams[i].OrgID)
|
||||
org, err := models.GetOrgByID(teams[i].OrgID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
|
||||
return
|
||||
|
|
|
@ -120,7 +120,7 @@ func CreateFork(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusForbidden, "isMemberNot", fmt.Sprintf("User is no Member of Organisation '%s'", org.Name))
|
||||
return
|
||||
}
|
||||
forker = org
|
||||
forker = org.AsUser()
|
||||
}
|
||||
|
||||
fork, err := repo_service.ForkRepository(ctx.User, forker, models.ForkRepoOptions{
|
||||
|
|
|
@ -86,7 +86,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
|
||||
if repoOwner.IsOrganization() {
|
||||
// Check ownership of organization.
|
||||
isOwner, err := repoOwner.IsOwnedBy(ctx.User.ID)
|
||||
isOwner, err := models.OrgFromUser(repoOwner).IsOwnedBy(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err)
|
||||
return
|
||||
|
|
|
@ -393,7 +393,7 @@ func Generate(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if !ctx.User.IsAdmin {
|
||||
canCreate, err := ctxUser.CanCreateOrgRepo(ctx.User.ID)
|
||||
canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
return
|
||||
|
@ -489,7 +489,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !models.HasOrgOrUserVisible(org, ctx.User) {
|
||||
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) {
|
||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
||||
return
|
||||
}
|
||||
|
@ -504,7 +504,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
}
|
||||
CreateUserRepo(ctx, org, *opt)
|
||||
CreateUserRepo(ctx, org.AsUser(), *opt)
|
||||
}
|
||||
|
||||
// Get one repository
|
||||
|
|
|
@ -64,7 +64,7 @@ func Transfer(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if newOwner.Type == models.UserTypeOrganization {
|
||||
if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !newOwner.HasMemberWithUserID(ctx.User.ID) {
|
||||
if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
|
||||
// The user shouldn't know about this organization
|
||||
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
||||
return
|
||||
|
@ -78,7 +78,7 @@ func Transfer(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
org := convert.ToOrganization(newOwner)
|
||||
org := convert.ToOrganization(models.OrgFromUser(newOwner))
|
||||
for _, tID := range *opts.TeamIDs {
|
||||
team, err := models.GetTeamByID(tID)
|
||||
if err != nil {
|
||||
|
|
|
@ -157,5 +157,5 @@ func ListOrgRepos(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
listUserRepos(ctx, ctx.Org.Organization, ctx.IsSigned)
|
||||
listUserRepos(ctx, ctx.Org.Organization.AsUser(), ctx.IsSigned)
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ func AddOrgHook(ctx *context.APIContext, form *api.CreateHookOption) {
|
|||
org := ctx.Org.Organization
|
||||
hook, ok := addHook(ctx, form, org.ID, 0)
|
||||
if ok {
|
||||
ctx.JSON(http.StatusCreated, convert.ToHook(org.HomeLink(), hook))
|
||||
ctx.JSON(http.StatusCreated, convert.ToHook(org.AsUser().HomeLink(), hook))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ func EditOrgHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), updated))
|
||||
ctx.JSON(http.StatusOK, convert.ToHook(org.AsUser().HomeLink(), updated))
|
||||
}
|
||||
|
||||
// EditRepoHook edit webhook `w` according to `form`. Writes to `ctx` accordingly
|
||||
|
|
|
@ -30,7 +30,7 @@ func Home(ctx *context.Context) {
|
|||
|
||||
org := ctx.Org.Organization
|
||||
|
||||
if !models.HasOrgOrUserVisible(org, ctx.User) {
|
||||
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) {
|
||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
||||
return
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func Home(ctx *context.Context) {
|
|||
ctx.Data["Total"] = count
|
||||
ctx.Data["MembersTotal"] = membersCount
|
||||
ctx.Data["Members"] = members
|
||||
ctx.Data["Teams"] = org.Teams
|
||||
ctx.Data["Teams"] = ctx.Org.Teams
|
||||
|
||||
ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ func CreatePost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
org := &models.User{
|
||||
org := &models.Organization{
|
||||
Name: form.OrgName,
|
||||
IsActive: true,
|
||||
Type: models.UserTypeOrganization,
|
||||
|
@ -75,5 +75,5 @@ func CreatePost(ctx *context.Context) {
|
|||
}
|
||||
log.Trace("Organization created: %s", org.Name)
|
||||
|
||||
ctx.Redirect(org.DashboardLink())
|
||||
ctx.Redirect(org.AsUser().DashboardLink())
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
ctx.Data["OrgName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form)
|
||||
return
|
||||
} else if err = models.ChangeUserName(org, form.Name); err != nil {
|
||||
} else if err = models.ChangeUserName(org.AsUser(), form.Name); err != nil {
|
||||
if err == models.ErrUserNameIllegal {
|
||||
ctx.Data["OrgName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form)
|
||||
|
@ -100,18 +100,20 @@ func SettingsPost(ctx *context.Context) {
|
|||
visibilityChanged := form.Visibility != org.Visibility
|
||||
org.Visibility = form.Visibility
|
||||
|
||||
if err := models.UpdateUser(org); err != nil {
|
||||
if err := models.UpdateUser(org.AsUser()); err != nil {
|
||||
ctx.ServerError("UpdateUser", err)
|
||||
return
|
||||
}
|
||||
|
||||
// update forks visibility
|
||||
if visibilityChanged {
|
||||
if err := org.GetRepositories(db.ListOptions{Page: 1, PageSize: org.NumRepos}); err != nil {
|
||||
repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{
|
||||
Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos}})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetRepositories", err)
|
||||
return
|
||||
}
|
||||
for _, repo := range org.Repos {
|
||||
for _, repo := range repos {
|
||||
repo.OwnerName = org.Name
|
||||
if err := models.UpdateRepository(repo, true); err != nil {
|
||||
ctx.ServerError("UpdateRepository", err)
|
||||
|
@ -134,7 +136,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
func SettingsAvatar(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AvatarForm)
|
||||
form.Source = forms.AvatarLocal
|
||||
if err := userSetting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
|
||||
if err := userSetting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization.AsUser()); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success"))
|
||||
|
@ -145,7 +147,7 @@ func SettingsAvatar(ctx *context.Context) {
|
|||
|
||||
// SettingsDeleteAvatar response for delete avatar on settings page
|
||||
func SettingsDeleteAvatar(ctx *context.Context) {
|
||||
if err := ctx.Org.Organization.DeleteAvatar(); err != nil {
|
||||
if err := ctx.Org.Organization.AsUser().DeleteAvatar(); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
}
|
||||
|
||||
|
|
|
@ -38,13 +38,13 @@ func Teams(ctx *context.Context) {
|
|||
ctx.Data["Title"] = org.FullName
|
||||
ctx.Data["PageIsOrgTeams"] = true
|
||||
|
||||
for _, t := range org.Teams {
|
||||
for _, t := range ctx.Org.Teams {
|
||||
if err := t.GetMembers(&models.SearchMembersOptions{}); err != nil {
|
||||
ctx.ServerError("GetMembers", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx.Data["Teams"] = org.Teams
|
||||
ctx.Data["Teams"] = ctx.Org.Teams
|
||||
|
||||
ctx.HTML(http.StatusOK, tplTeams)
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ func TeamsAction(ctx *context.Context) {
|
|||
case "team":
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName))
|
||||
case "home":
|
||||
ctx.Redirect(ctx.Org.Organization.HomeLink())
|
||||
ctx.Redirect(ctx.Org.Organization.AsUser().HomeLink())
|
||||
default:
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/teams")
|
||||
}
|
||||
|
|
|
@ -2644,13 +2644,15 @@ func handleTeamMentions(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
isAdmin := false
|
||||
var isAdmin bool
|
||||
var err error
|
||||
var teams []*models.Team
|
||||
var org = models.OrgFromUser(ctx.Repo.Owner)
|
||||
// Admin has super access.
|
||||
if ctx.User.IsAdmin {
|
||||
isAdmin = true
|
||||
} else {
|
||||
isAdmin, err = ctx.Repo.Owner.IsOwnedBy(ctx.User.ID)
|
||||
isAdmin, err = org.IsOwnedBy(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsOwnedBy", err)
|
||||
return
|
||||
|
@ -2658,19 +2660,20 @@ func handleTeamMentions(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if isAdmin {
|
||||
if err := ctx.Repo.Owner.LoadTeams(); err != nil {
|
||||
teams, err = org.LoadTeams()
|
||||
if err != nil {
|
||||
ctx.ServerError("LoadTeams", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
ctx.Repo.Owner.Teams, err = ctx.Repo.Owner.GetUserTeams(ctx.User.ID)
|
||||
teams, err = org.GetUserTeams(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserTeams", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["MentionableTeams"] = ctx.Repo.Owner.Teams
|
||||
ctx.Data["MentionableTeams"] = teams
|
||||
ctx.Data["MentionableTeamsOrg"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["MentionableTeamsOrgAvatar"] = ctx.Repo.Owner.AvatarLink()
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ func RetrieveLabels(ctx *context.Context) {
|
|||
ctx.ServerError("org.IsOwnedBy", err)
|
||||
return
|
||||
}
|
||||
ctx.Org.OrgLink = org.OrganisationLink()
|
||||
ctx.Org.OrgLink = org.AsUser().OrganisationLink()
|
||||
ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
|
||||
ctx.Data["OrganizationLink"] = ctx.Org.OrgLink
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ func ForkPost(ctx *context.Context) {
|
|||
|
||||
// Check ownership of organization.
|
||||
if ctxUser.IsOrganization() {
|
||||
isOwner, err := ctxUser.IsOwnedBy(ctx.User.ID)
|
||||
isOwner, err := models.OrgFromUser(ctxUser).IsOwnedBy(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsOwnedBy", err)
|
||||
return
|
||||
|
|
|
@ -94,7 +94,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
|
|||
return nil
|
||||
}
|
||||
if !ctx.User.IsAdmin {
|
||||
canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
|
||||
canCreate, err := models.OrgFromUser(org).CanCreateOrgRepo(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
return nil
|
||||
|
|
|
@ -588,7 +588,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if newOwner.Type == models.UserTypeOrganization {
|
||||
if !ctx.User.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !newOwner.HasMemberWithUserID(ctx.User.ID) {
|
||||
if !ctx.User.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
|
||||
// The user shouldn't know about this organization
|
||||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
|
||||
return
|
||||
|
@ -879,7 +879,7 @@ func AddTeamPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
team, err := ctx.Repo.Owner.GetTeam(name)
|
||||
team, err := models.OrgFromUser(ctx.Repo.Owner).GetTeam(name)
|
||||
if err != nil {
|
||||
if models.IsErrTeamNotExist(err) {
|
||||
ctx.Flash.Error(ctx.Tr("form.team_not_exist"))
|
||||
|
|
|
@ -156,7 +156,7 @@ func SettingsProtectedBranch(c *context.Context) {
|
|||
}
|
||||
|
||||
if c.Repo.Owner.IsOrganization() {
|
||||
teams, err := c.Repo.Owner.TeamsWithAccessToRepo(c.Repo.Repository.ID, models.AccessModeRead)
|
||||
teams, err := models.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c.Repo.Repository.ID, models.AccessModeRead)
|
||||
if err != nil {
|
||||
c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
|
||||
return
|
||||
|
|
|
@ -149,7 +149,7 @@ func setTagsContext(ctx *context.Context) error {
|
|||
ctx.Data["Users"] = users
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
teams, err := ctx.Repo.Owner.TeamsWithAccessToRepo(ctx.Repo.Repository.ID, models.AccessModeRead)
|
||||
teams, err := models.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx.Repo.Repository.ID, models.AccessModeRead)
|
||||
if err != nil {
|
||||
ctx.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
|
||||
return err
|
||||
|
|
|
@ -47,8 +47,8 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
|
|||
ctxUser := ctx.User
|
||||
orgName := ctx.Params(":org")
|
||||
if len(orgName) > 0 {
|
||||
ctxUser = ctx.Org.Organization
|
||||
ctx.Data["Teams"] = ctx.Org.Organization.Teams
|
||||
ctxUser = ctx.Org.Organization.AsUser()
|
||||
ctx.Data["Teams"] = ctx.Org.Teams
|
||||
}
|
||||
ctx.Data["ContextUser"] = ctxUser
|
||||
|
||||
|
@ -97,9 +97,9 @@ func Dashboard(ctx *context.Context) {
|
|||
if ctxUser.IsOrganization() {
|
||||
var env models.AccessibleReposEnvironment
|
||||
if ctx.Org.Team != nil {
|
||||
env = ctxUser.AccessibleTeamReposEnv(ctx.Org.Team)
|
||||
env = models.OrgFromUser(ctxUser).AccessibleTeamReposEnv(ctx.Org.Team)
|
||||
} else {
|
||||
env, err = ctxUser.AccessibleReposEnv(ctx.User.ID)
|
||||
env, err = models.OrgFromUser(ctxUser).AccessibleReposEnv(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("AccessibleReposEnv", err)
|
||||
return
|
||||
|
@ -756,9 +756,9 @@ func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType
|
|||
var env models.AccessibleReposEnvironment
|
||||
|
||||
if team != nil {
|
||||
env = ctxUser.AccessibleTeamReposEnv(team)
|
||||
env = models.OrgFromUser(ctxUser).AccessibleTeamReposEnv(team)
|
||||
} else {
|
||||
env, err = ctxUser.AccessibleReposEnv(ctxUser.ID)
|
||||
env, err = models.OrgFromUser(ctxUser).AccessibleReposEnv(ctxUser.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AccessibleReposEnv: %v", err)
|
||||
}
|
||||
|
|
|
@ -283,11 +283,11 @@ func getOAuthGroupsForUser(user *models.User) ([]string, error) {
|
|||
var groups []string
|
||||
for _, org := range orgs {
|
||||
groups = append(groups, org.Name)
|
||||
|
||||
if err := org.LoadTeams(); err != nil {
|
||||
teams, err := org.LoadTeams()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LoadTeams: %v", err)
|
||||
}
|
||||
for _, team := range org.Teams {
|
||||
for _, team := range teams {
|
||||
if team.IsMember(user.ID) {
|
||||
groups = append(groups, org.Name+":"+team.LowerName)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue