@@ -147,27 +147,33 @@ func getRepoPrivate(ctx *context.Context) bool {
147147 }
148148}
149149
150- // Create render creating repository page
151- func Create (ctx * context.Context ) {
150+ func createCommon (ctx * context.Context ) {
152151 ctx .Data ["Title" ] = ctx .Tr ("new_repo" )
153-
154- // Give default value for template to render.
155152 ctx .Data ["Gitignores" ] = repo_module .Gitignores
156153 ctx .Data ["LabelTemplateFiles" ] = repo_module .LabelTemplateFiles
157154 ctx .Data ["Licenses" ] = repo_module .Licenses
158155 ctx .Data ["Readmes" ] = repo_module .Readmes
159- ctx .Data ["readme" ] = "Default"
160- ctx .Data ["private" ] = getRepoPrivate (ctx )
161156 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+ }
163162
163+ // Create render creating repository page
164+ func Create (ctx * context.Context ) {
165+ createCommon (ctx )
164166 ctxUser := checkContextUser (ctx , ctx .FormInt64 ("org" ))
165167 if ctx .Written () {
166168 return
167169 }
168170 ctx .Data ["ContextUser" ] = ctxUser
169171
172+ ctx .Data ["readme" ] = "Default"
173+ ctx .Data ["private" ] = getRepoPrivate (ctx )
174+ ctx .Data ["default_branch" ] = setting .Repository .DefaultBranch
170175 ctx .Data ["repo_template_name" ] = ctx .Tr ("repo.template_select" )
176+
171177 templateID := ctx .FormInt64 ("template_id" )
172178 if templateID > 0 {
173179 templateRepo , err := repo_model .GetRepositoryByID (ctx , templateID )
@@ -177,11 +183,6 @@ func Create(ctx *context.Context) {
177183 }
178184 }
179185
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-
185186 ctx .HTML (http .StatusOK , tplCreate )
186187}
187188
@@ -219,23 +220,23 @@ func handleCreateError(ctx *context.Context, owner *user_model.User, err error,
219220
220221// CreatePost response for creating repository
221222func CreatePost (ctx * context.Context ) {
223+ createCommon (ctx )
222224 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 ()
232225
233226 ctxUser := checkContextUser (ctx , form .UID )
234227 if ctx .Written () {
235228 return
236229 }
237230 ctx .Data ["ContextUser" ] = ctxUser
238231
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+
239240 if ctx .HasError () {
240241 ctx .HTML (http .StatusOK , tplCreate )
241242 return
0 commit comments