Skip to content

Commit f9f1eab

Browse files
committed
fix org projects page incorrect tab
1 parent f47ea60 commit f9f1eab

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

modules/context/org.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ func (org *Organization) UnitPermission(ctx *Context, doerID int64, unitType uni
5656
return perm.AccessModeNone
5757
}
5858

59+
func GetOrganizationByParams(ctx *Context) {
60+
orgName := ctx.Params(":org")
61+
62+
var err error
63+
ctx.Org.Organization, err = organization.GetOrgByName(orgName)
64+
if err != nil {
65+
if organization.IsErrOrgNotExist(err) {
66+
redirectUserID, err := user_model.LookupUserRedirect(orgName)
67+
if err == nil {
68+
RedirectToUser(ctx, orgName, redirectUserID)
69+
} else if user_model.IsErrUserRedirectNotExist(err) {
70+
ctx.NotFound("GetUserByName", err)
71+
} else {
72+
ctx.ServerError("LookupUserRedirect", err)
73+
}
74+
} else {
75+
ctx.ServerError("GetUserByName", err)
76+
}
77+
return
78+
}
79+
}
80+
5981
// HandleOrgAssignment handles organization assignment
6082
func HandleOrgAssignment(ctx *Context, args ...bool) {
6183
var (
@@ -77,25 +99,13 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
7799
requireTeamAdmin = args[3]
78100
}
79101

80-
orgName := ctx.Params(":org")
81-
82102
var err error
83-
ctx.Org.Organization, err = organization.GetOrgByName(orgName)
84-
if err != nil {
85-
if organization.IsErrOrgNotExist(err) {
86-
redirectUserID, err := user_model.LookupUserRedirect(orgName)
87-
if err == nil {
88-
RedirectToUser(ctx, orgName, redirectUserID)
89-
} else if user_model.IsErrUserRedirectNotExist(err) {
90-
ctx.NotFound("GetUserByName", err)
91-
} else {
92-
ctx.ServerError("LookupUserRedirect", err)
93-
}
94-
} else {
95-
ctx.ServerError("GetUserByName", err)
96-
}
97-
return
103+
104+
// if Organization is not defined, get it from params
105+
if ctx.Org.Organization == nil {
106+
GetOrganizationByParams(ctx)
98107
}
108+
99109
org := ctx.Org.Organization
100110

101111
// Handle Visibility

routers/web/org/projects.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func NewProject(ctx *context.Context) {
123123
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
124124
ctx.Data["ProjectTypes"] = project_model.GetProjectsConfig()
125125
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
126+
ctx.Data["PageIsViewProjects"] = true
126127
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
127128
shared_user.RenderUserHeader(ctx)
128129
ctx.HTML(http.StatusOK, tplProjectsNew)

services/context/user.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func userAssignment(ctx *context.Context, errCb func(int, string, interface{}))
6363
ctx.Org = &context.Organization{}
6464
}
6565
ctx.Org.Organization = (*org_model.Organization)(ctx.ContextUser)
66-
ctx.Data["Org"] = ctx.Org.Organization
66+
67+
context.HandleOrgAssignment(ctx)
6768
}
6869
}
6970
}

0 commit comments

Comments
 (0)