@@ -147,27 +147,33 @@ func getRepoPrivate(ctx *context.Context) bool {
147
147
}
148
148
}
149
149
150
- // Create render creating repository page
151
- func Create (ctx * context.Context ) {
150
+ func createCommon (ctx * context.Context ) {
152
151
ctx .Data ["Title" ] = ctx .Tr ("new_repo" )
153
-
154
- // Give default value for template to render.
155
152
ctx .Data ["Gitignores" ] = repo_module .Gitignores
156
153
ctx .Data ["LabelTemplateFiles" ] = repo_module .LabelTemplateFiles
157
154
ctx .Data ["Licenses" ] = repo_module .Licenses
158
155
ctx .Data ["Readmes" ] = repo_module .Readmes
159
- ctx .Data ["readme" ] = "Default"
160
- ctx .Data ["private" ] = getRepoPrivate (ctx )
161
156
ctx .Data ["IsForcedPrivate" ] = setting .Repository .ForcePrivate
162
- ctx .Data ["default_branch" ] = setting .Repository .DefaultBranch
157
+ ctx .Data ["CanCreateRepo" ] = ctx .Doer .CanCreateRepo ()
158
+ ctx .Data ["MaxCreationLimit" ] = ctx .Doer .MaxCreationLimit ()
159
+ ctx .Data ["SupportedObjectFormats" ] = git .DefaultFeatures ().SupportedObjectFormats
160
+ ctx .Data ["DefaultObjectFormat" ] = git .Sha1ObjectFormat
161
+ }
163
162
163
+ // Create render creating repository page
164
+ func Create (ctx * context.Context ) {
165
+ createCommon (ctx )
164
166
ctxUser := checkContextUser (ctx , ctx .FormInt64 ("org" ))
165
167
if ctx .Written () {
166
168
return
167
169
}
168
170
ctx .Data ["ContextUser" ] = ctxUser
169
171
172
+ ctx .Data ["readme" ] = "Default"
173
+ ctx .Data ["private" ] = getRepoPrivate (ctx )
174
+ ctx .Data ["default_branch" ] = setting .Repository .DefaultBranch
170
175
ctx .Data ["repo_template_name" ] = ctx .Tr ("repo.template_select" )
176
+
171
177
templateID := ctx .FormInt64 ("template_id" )
172
178
if templateID > 0 {
173
179
templateRepo , err := repo_model .GetRepositoryByID (ctx , templateID )
@@ -177,11 +183,6 @@ func Create(ctx *context.Context) {
177
183
}
178
184
}
179
185
180
- ctx .Data ["CanCreateRepo" ] = ctx .Doer .CanCreateRepo ()
181
- ctx .Data ["MaxCreationLimit" ] = ctx .Doer .MaxCreationLimit ()
182
- ctx .Data ["SupportedObjectFormats" ] = git .DefaultFeatures ().SupportedObjectFormats
183
- ctx .Data ["DefaultObjectFormat" ] = git .Sha1ObjectFormat
184
-
185
186
ctx .HTML (http .StatusOK , tplCreate )
186
187
}
187
188
@@ -219,23 +220,23 @@ func handleCreateError(ctx *context.Context, owner *user_model.User, err error,
219
220
220
221
// CreatePost response for creating repository
221
222
func CreatePost (ctx * context.Context ) {
223
+ createCommon (ctx )
222
224
form := web .GetForm (ctx ).(* forms.CreateRepoForm )
223
- ctx .Data ["Title" ] = ctx .Tr ("new_repo" )
224
-
225
- ctx .Data ["Gitignores" ] = repo_module .Gitignores
226
- ctx .Data ["LabelTemplateFiles" ] = repo_module .LabelTemplateFiles
227
- ctx .Data ["Licenses" ] = repo_module .Licenses
228
- ctx .Data ["Readmes" ] = repo_module .Readmes
229
-
230
- ctx .Data ["CanCreateRepo" ] = ctx .Doer .CanCreateRepo ()
231
- ctx .Data ["MaxCreationLimit" ] = ctx .Doer .MaxCreationLimit ()
232
225
233
226
ctxUser := checkContextUser (ctx , form .UID )
234
227
if ctx .Written () {
235
228
return
236
229
}
237
230
ctx .Data ["ContextUser" ] = ctxUser
238
231
232
+ if form .RepoTemplate > 0 {
233
+ templateRepo , err := repo_model .GetRepositoryByID (ctx , form .RepoTemplate )
234
+ if err == nil && access_model .CheckRepoUnitUser (ctx , templateRepo , ctxUser , unit .TypeCode ) {
235
+ ctx .Data ["repo_template" ] = form .RepoTemplate
236
+ ctx .Data ["repo_template_name" ] = templateRepo .Name
237
+ }
238
+ }
239
+
239
240
if ctx .HasError () {
240
241
ctx .HTML (http .StatusOK , tplCreate )
241
242
return
0 commit comments