Skip to content

Commit 5294821

Browse files
authored
Support default private when creating or migrating repository (#3239)
* support default private when creating or migrating repository * fix fmt * use string constants on repository default private in app.ini * fix fmt
1 parent e67b405 commit 5294821

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ SCRIPT_TYPE = bash
1616
ANSI_CHARSET =
1717
; Force every new repository to be private
1818
FORCE_PRIVATE = false
19+
; Default private when create a new repository, could be: last, private, public. Default is last which means last user repo visiblity.
20+
DEFAULT_PRIVATE = last
1921
; Global maximum creation limit of repository per user, -1 means no limit
2022
MAX_CREATION_LIMIT = -1
2123
; Mirror sync queue length, increase if mirror syncing starts hanging

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
3939
- `SCRIPT_TYPE`: The script type your server supports, usually this is `bash`, but some customers report that they only have `sh`.
4040
- `ANSI_CHARSET`: The default charset for an unrecognized charset.
4141
- `FORCE_PRIVATE`: Force every new repository to be private.
42+
- `DEFAULT_PRIVATE`: Default private when create a new repository, could be: `last`, `private` and `public`. Default is last which means last user repo visiblity.
4243
- `MAX_CREATION_LIMIT`: Global maximum creation limit of repositories per user, `-1` means no limit.
4344
- `PULL_REQUEST_QUEUE_LENGTH`:exclamation:: Length of pull request patch test queue, make it as large as possible.
4445
- `MIRROR_QUEUE_LENGTH`: Patch test queue length, increase if pull request patch testing starts hanging. Defaults to 1000.

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ menu:
2929
- `SCRIPT_TYPE`: 服务器支持的Shell类型,通常是 `bash`,但有些服务器也有可能是 `sh`
3030
- `ANSI_CHARSET`: 默认字符编码。
3131
- `FORCE_PRIVATE`: 强制所有git工程必须私有。
32+
- `DEFAULT_PRIVATE`: 默认创建的git工程为私有。 可以是`last`, `private``public`。默认值是 `last`表示用户最后创建的Repo的选择。
3233
- `MAX_CREATION_LIMIT`: 全局最大每个用户创建的git工程数目, `-1` 表示没限制。
3334
- `PULL_REQUEST_QUEUE_LENGTH`: 小心:合并请求测试队列的长度,尽量放大。
3435

modules/setting/setting.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ type MarkupParser struct {
7070
IsInputFile bool
7171
}
7272

73+
// enumerates all the policy repository creating
74+
const (
75+
RepoCreatingLastUserVisibility = "last"
76+
RepoCreatingPrivate = "private"
77+
RepoCreatingPublic = "public"
78+
)
79+
7380
// settings
7481
var (
7582
// AppVer settings
@@ -180,6 +187,7 @@ var (
180187
Repository = struct {
181188
AnsiCharset string
182189
ForcePrivate bool
190+
DefaultPrivate string
183191
MaxCreationLimit int
184192
MirrorQueueLength int
185193
PullRequestQueueLength int
@@ -209,6 +217,7 @@ var (
209217
}{
210218
AnsiCharset: "",
211219
ForcePrivate: false,
220+
DefaultPrivate: RepoCreatingLastUserVisibility,
212221
MaxCreationLimit: -1,
213222
MirrorQueueLength: 1000,
214223
PullRequestQueueLength: 1000,

routers/repo/repo.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
8181
return org
8282
}
8383

84+
func getRepoPrivate(ctx *context.Context) bool {
85+
switch strings.ToLower(setting.Repository.DefaultPrivate) {
86+
case setting.RepoCreatingLastUserVisibility:
87+
return ctx.User.LastRepoVisibility
88+
case setting.RepoCreatingPrivate:
89+
return true
90+
case setting.RepoCreatingPublic:
91+
return false
92+
default:
93+
return ctx.User.LastRepoVisibility
94+
}
95+
}
96+
8497
// Create render creating repository page
8598
func Create(ctx *context.Context) {
8699
if !ctx.User.CanCreateRepo() {
@@ -94,7 +107,7 @@ func Create(ctx *context.Context) {
94107
ctx.Data["Licenses"] = models.Licenses
95108
ctx.Data["Readmes"] = models.Readmes
96109
ctx.Data["readme"] = "Default"
97-
ctx.Data["private"] = ctx.User.LastRepoVisibility
110+
ctx.Data["private"] = getRepoPrivate(ctx)
98111
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
99112

100113
ctxUser := checkContextUser(ctx, ctx.QueryInt64("org"))
@@ -170,7 +183,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
170183
// Migrate render migration of repository page
171184
func Migrate(ctx *context.Context) {
172185
ctx.Data["Title"] = ctx.Tr("new_migrate")
173-
ctx.Data["private"] = ctx.User.LastRepoVisibility
186+
ctx.Data["private"] = getRepoPrivate(ctx)
174187
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
175188
ctx.Data["mirror"] = ctx.Query("mirror") == "1"
176189
ctx.Data["LFSActive"] = setting.LFS.StartServer

0 commit comments

Comments
 (0)