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

Support org/user level projects #22235

Merged
merged 28 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bb64be1
support org level projects
lunny Dec 24, 2022
c5266e3
Fix move
lunny Dec 24, 2022
420c5cd
Change the repo ref
lunny Dec 24, 2022
0436072
improve FindProjects
lunny Dec 24, 2022
4a5eb97
Fix lint
lunny Dec 27, 2022
24ce5fc
Merge branch 'main' into lunny/org_project
lunny Dec 27, 2022
8de5ae3
Merge branch 'main' into lunny/org_project
lunny Dec 27, 2022
68e6c14
Fix lint
lunny Dec 27, 2022
c39fca7
improve menus
lunny Dec 28, 2022
2c40716
Fix test
lunny Dec 28, 2022
44a56ed
Merge branch 'main' into lunny/org_project
lunny Dec 28, 2022
2c081a5
support user level projects
lunny Dec 28, 2022
b2c2deb
Fix test
lunny Dec 29, 2022
2a1365f
Merge branch 'main' into lunny/org_project
lunny Dec 29, 2022
547c309
improvement
lunny Dec 29, 2022
d0a3680
Fix test
lunny Dec 31, 2022
f94cb43
Merge branch 'main' into lunny/org_project
lunny Dec 31, 2022
ada5889
Use project-symblink icon for org level project
lunny Dec 31, 2022
a4ce734
Fix test
lunny Dec 31, 2022
afbd579
Merge branch 'main' into lunny/org_project
lunny Jan 1, 2023
ed07255
fix test
lunny Jan 1, 2023
959ba4b
Merge branch 'main' into lunny/org_project
lunny Jan 1, 2023
7a97a60
Merge branch 'main' into lunny/org_project
lunny Jan 2, 2023
a3322d2
Fix bug
lunny Jan 2, 2023
1889007
Merge branch 'main' into lunny/org_project
6543 Jan 2, 2023
cccf1e9
Merge branch 'main' into lunny/org_project
lunny Jan 16, 2023
a094dc8
Merge branch 'main' into lunny/org_project
lunny Jan 19, 2023
c4f1e41
Merge branch 'main' into lunny/org_project
lunny Jan 20, 2023
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
Prev Previous commit
Next Next commit
support user level projects
  • Loading branch information
lunny committed Dec 28, 2022
commit 2c081a5ddbf02e87b804a50130e2bff768821670
19 changes: 13 additions & 6 deletions routers/web/org/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,26 @@ func Projects(ctx *context.Context) {
pager.AddParam(ctx, "state", "State")
ctx.Data["Page"] = pager

ctx.Data["CanWriteProjects"] = ctx.Org.CanWriteUnit(ctx, unit.TypeProjects)
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
ctx.Data["IsShowClosed"] = isShowClosed
ctx.Data["PageIsViewProjects"] = true
ctx.Data["SortType"] = sortType

ctx.HTML(http.StatusOK, tplProjects)
}

func canWriteUnit(ctx *context.Context) bool {
if ctx.ContextUser.IsOrganization() {
return ctx.Org.CanWriteUnit(ctx, unit.TypeProjects)
}
return ctx.Doer != nil && ctx.ContextUser.ID == ctx.Doer.ID
}

// NewProject render creating a project page
func NewProject(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
ctx.Data["ProjectTypes"] = project_model.GetProjectsConfig()
ctx.Data["CanWriteProjects"] = ctx.Org.CanWriteUnit(ctx, unit.TypeProjects)
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
shared_user.RenderUserHeader(ctx)
ctx.HTML(http.StatusOK, tplProjectsNew)
Expand All @@ -128,7 +135,7 @@ func NewProjectPost(ctx *context.Context) {
shared_user.RenderUserHeader(ctx)

if ctx.HasError() {
ctx.Data["CanWriteProjects"] = ctx.Org.CanWriteUnit(ctx, unit.TypeProjects)
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
ctx.Data["PageIsViewProjects"] = true
ctx.Data["ProjectTypes"] = project_model.GetProjectsConfig()
ctx.HTML(http.StatusOK, tplProjectsNew)
Expand Down Expand Up @@ -207,7 +214,7 @@ func EditProject(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
ctx.Data["PageIsEditProjects"] = true
ctx.Data["PageIsViewProjects"] = true
ctx.Data["CanWriteProjects"] = ctx.Org.CanWriteUnit(ctx, unit.TypeProjects)
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
shared_user.RenderUserHeader(ctx)

p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
Expand Down Expand Up @@ -236,7 +243,7 @@ func EditProjectPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
ctx.Data["PageIsEditProjects"] = true
ctx.Data["PageIsViewProjects"] = true
ctx.Data["CanWriteProjects"] = ctx.Org.CanWriteUnit(ctx, unit.TypeProjects)
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
shared_user.RenderUserHeader(ctx)

if ctx.HasError() {
Expand Down Expand Up @@ -325,7 +332,7 @@ func ViewProject(ctx *context.Context) {
project.RenderedContent = project.Description
ctx.Data["LinkedPRs"] = linkedPrsMap
ctx.Data["PageIsViewProjects"] = true
ctx.Data["CanWriteProjects"] = ctx.Org.CanWriteUnit(ctx, unit.TypeProjects)
ctx.Data["CanWriteProjects"] = canWriteUnit(ctx)
ctx.Data["Project"] = project
ctx.Data["IssuesMap"] = issuesMap
ctx.Data["Boards"] = boards
Expand Down
11 changes: 10 additions & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,16 @@ func RegisterRoutes(m *web.Route) {
})
})
}, reqSignIn, func(ctx *context.Context) {
if !ctx.Org.CanWriteUnit(ctx, unit.TypeProjects) {
if ctx.ContextUser == nil {
ctx.NotFound("NewProject", nil)
return
}
if ctx.ContextUser.IsOrganization() {
if !ctx.Org.CanWriteUnit(ctx, unit.TypeProjects) {
ctx.NotFound("NewProject", nil)
return
}
} else if ctx.ContextUser.ID != ctx.Doer.ID {
ctx.NotFound("NewProject", nil)
return
}
Expand Down
3 changes: 3 additions & 0 deletions templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
<a class='{{if and (ne .TabName "activity") (ne .TabName "following") (ne .TabName "followers") (ne .TabName "stars") (ne .TabName "watching") (ne .TabName "projects") (ne .TabName "code")}}active {{end}}item' href="{{.Owner.HomeLink}}">
{{svg "octicon-repo"}} {{.locale.Tr "user.repositories"}}
</a>
<a href="{{.Owner.HomeLink}}/-/projects" class="{{if eq .TabName "projects"}}active {{end}}item">
{{svg "octicon-project"}} {{.locale.Tr "user.projects"}}
</a>
{{if .IsPackageEnabled}}
<a class='{{if eq .TabName "packages"}}active {{end}}item' href="{{.Owner.HomeLink}}/-/packages">
{{svg "octicon-package"}} {{.locale.Tr "packages.title"}}
Expand Down