Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tabs to org projects page #22705

Merged
merged 18 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions modules/context/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ func (org *Organization) UnitPermission(ctx *Context, doerID int64, unitType uni
return perm.AccessModeNone
}

func GetOrganizationByParams(ctx *Context) {
orgName := ctx.Params(":org")

var err error
ctx.Org.Organization, err = organization.GetOrgByName(orgName)
if err != nil {
if organization.IsErrOrgNotExist(err) {
redirectUserID, err := user_model.LookupUserRedirect(orgName)
if err == nil {
RedirectToUser(ctx, orgName, redirectUserID)
} else if user_model.IsErrUserRedirectNotExist(err) {
ctx.NotFound("GetUserByName", err)
} else {
ctx.ServerError("LookupUserRedirect", err)
}
} else {
ctx.ServerError("GetUserByName", err)
}
return
}
}

// HandleOrgAssignment handles organization assignment
func HandleOrgAssignment(ctx *Context, args ...bool) {
var (
Expand All @@ -77,25 +99,13 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
requireTeamAdmin = args[3]
}

orgName := ctx.Params(":org")

var err error
ctx.Org.Organization, err = organization.GetOrgByName(orgName)
if err != nil {
if organization.IsErrOrgNotExist(err) {
redirectUserID, err := user_model.LookupUserRedirect(orgName)
if err == nil {
RedirectToUser(ctx, orgName, redirectUserID)
} else if user_model.IsErrUserRedirectNotExist(err) {
ctx.NotFound("GetUserByName", err)
} else {
ctx.ServerError("LookupUserRedirect", err)
}
} else {
ctx.ServerError("GetUserByName", err)
}
return

// if Organization is not defined, get it from params
if ctx.Org.Organization == nil {
GetOrganizationByParams(ctx)
yp05327 marked this conversation as resolved.
Show resolved Hide resolved
}

org := ctx.Org.Organization

// Handle Visibility
Expand Down
1 change: 1 addition & 0 deletions routers/web/org/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func NewProject(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
ctx.Data["ProjectTypes"] = project_model.GetProjectsConfig()
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
ctx.Data["PageIsViewProjects"] = true
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
shared_user.RenderUserHeader(ctx)
ctx.HTML(http.StatusOK, tplProjectsNew)
Expand Down
3 changes: 2 additions & 1 deletion services/context/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func userAssignment(ctx *context.Context, errCb func(int, string, interface{}))
ctx.Org = &context.Organization{}
}
ctx.Org.Organization = (*org_model.Organization)(ctx.ContextUser)
ctx.Data["Org"] = ctx.Org.Organization

context.HandleOrgAssignment(ctx)
}
}
}
Expand Down