Skip to content

(Preview) Fix no same naming convention between template and form #22846

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

Closed
Show file tree
Hide file tree
Changes from 10 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
23 changes: 2 additions & 21 deletions modules/web/middleware/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,8 @@ func init() {

// AssignForm assign form values back to the template data.
func AssignForm(form interface{}, data map[string]interface{}) {
typ := reflect.TypeOf(form)
val := reflect.ValueOf(form)

for typ.Kind() == reflect.Ptr {
typ = typ.Elem()
val = val.Elem()
}

for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)

fieldName := field.Tag.Get("form")
// Allow ignored fields in the struct
if fieldName == "-" {
continue
} else if len(fieldName) == 0 {
fieldName = util.ToSnakeCase(field.Name)
}

data[fieldName] = val.Field(i).Interface()
}
// TODO: Allow ignored fields in the struct?
data["Form"] = form
}

func getRuleBody(field reflect.StructField, prefix string) string {
Expand Down
6 changes: 5 additions & 1 deletion routers/web/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ const (
// Create render the page for create organization
func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_org")
ctx.Data["DefaultOrgVisibilityMode"] = setting.Service.DefaultOrgVisibilityMode
ctx.Data["Form"] = forms.CreateOrgForm{
Visibility: setting.Service.DefaultOrgVisibilityMode,
RepoAdminChangeTeamAccess: true,
}

if !ctx.Doer.CanCreateOrganization() {
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
return
Expand Down
18 changes: 12 additions & 6 deletions routers/web/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,33 @@ func Create(ctx *context.Context) {
ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
ctx.Data["Licenses"] = repo_module.Licenses
ctx.Data["Readmes"] = repo_module.Readmes
ctx.Data["readme"] = "Default"
ctx.Data["private"] = getRepoPrivate(ctx)
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
ctx.Data["default_branch"] = setting.Repository.DefaultBranch

ctxUser := checkContextUser(ctx, ctx.FormInt64("org"))
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctxUser

ctx.Data["repo_template_name"] = ctx.Tr("repo.template_select")
ctx.Data["RepoTemplateName"] = ctx.Tr("repo.template_select")
templateID := ctx.FormInt64("template_id")
repoTemplate := int64(0)
if templateID > 0 {
templateRepo, err := repo_model.GetRepositoryByID(ctx, templateID)
if err == nil && access_model.CheckRepoUnitUser(ctx, templateRepo, ctxUser, unit.TypeCode) {
ctx.Data["repo_template"] = templateID
ctx.Data["repo_template_name"] = templateRepo.Name
repoTemplate = templateID
ctx.Data["RepoTemplateName"] = templateRepo.Name
}
}

ctx.Data["Form"] = forms.CreateRepoForm{
Private: getRepoPrivate(ctx),
DefaultBranch: setting.Repository.DefaultBranch,
Readme: "Default",
RepoTemplate: repoTemplate,
TrustModel: "Default",
}

ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo()
ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit()

Expand Down
10 changes: 5 additions & 5 deletions templates/org/create.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
{{template "base/alert" .}}
<div class="inline required field {{if .Err_OrgName}}error{{end}}">
<label for="org_name">{{.locale.Tr "org.org_name_holder"}}</label>
<input id="org_name" name="org_name" value="{{.org_name}}" autofocus required>
<input id="org_name" name="org_name" value="{{.Form.OrgName}}" autofocus required>
<span class="help">{{.locale.Tr "org.org_name_helper"}}</span>
</div>

<div class="inline field {{if .Err_OrgVisibility}}error{{end}}">
<span class="inline required field"><label for="visibility">{{.locale.Tr "org.settings.visibility"}}</label></span>
<div class="inline-grouped-list">
<div class="ui radio checkbox">
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="0" {{if .DefaultOrgVisibilityMode.IsPublic}}checked{{end}}/>
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="0" {{if .Form.Visibility.IsPublic}}checked{{end}}/>
<label>{{.locale.Tr "org.settings.visibility.public"}}</label>
</div>
<div class="ui radio checkbox">
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="1" {{if .DefaultOrgVisibilityMode.IsLimited}}checked{{end}}/>
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="1" {{if .Form.Visibility.IsLimited}}checked{{end}}/>
<label>{{.locale.Tr "org.settings.visibility.limited"}}</label>
</div>
<div class="ui radio checkbox">
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="2" {{if .DefaultOrgVisibilityMode.IsPrivate}}checked{{end}}/>
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="2" {{if .Form.Visibility.IsPrivate}}checked{{end}}/>
<label>{{.locale.Tr "org.settings.visibility.private"}}</label>
</div>
</div>
Expand All @@ -37,7 +37,7 @@
<label>{{.locale.Tr "org.settings.permission"}}</label>
<div class="inline-grouped-list">
<div class="ui checkbox">
<input class="hidden" type="checkbox" name="repo_admin_change_team_access" checked/>
<input class="hidden" type="checkbox" name="repo_admin_change_team_access" {{if .Form.RepoAdminChangeTeamAccess}}checked{{end}}/>
<label>{{.locale.Tr "org.settings.repoadminchangeteam"}}</label>
</div>
</div>
Expand Down
38 changes: 19 additions & 19 deletions templates/repo/create.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<div class="inline required field {{if .Err_RepoName}}error{{end}}">
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
<input id="repo_name" name="repo_name" value="{{.repo_name}}" autofocus required>
<input id="repo_name" name="repo_name" value="{{.Form.RepoName}}" autofocus required>
<span class="help">{{.locale.Tr "repo.repo_name_helper"}}</span>
</div>
<div class="inline field">
Expand All @@ -53,21 +53,21 @@
<input name="private" type="checkbox" checked readonly>
<label>{{.locale.Tr "repo.visibility_helper_forced" | Safe}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
<input name="private" type="checkbox" {{if .Form.Private}}checked{{end}}>
<label>{{.locale.Tr "repo.visibility_helper" | Safe}}</label>
{{end}}
</div>
<span class="help">{{.locale.Tr "repo.visibility_description"}}</span>
</div>
<div class="inline field {{if .Err_Description}}error{{end}}">
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
<textarea id="description" name="description" placeholder="{{.locale.Tr "repo.repo_desc_helper"}}">{{.description}}</textarea>
<textarea id="description" name="description" placeholder="{{.locale.Tr "repo.repo_desc_helper"}}">{{.Form.Description}}</textarea>
</div>
<div class="inline field">
<label>{{.locale.Tr "repo.template"}}</label>
<div id="repo_template_search" class="ui search normal selection dropdown">
<input type="hidden" id="repo_template" name="repo_template" value="{{.repo_template}}">
<div class="default text">{{.repo_template_name}}</div>
<input type="hidden" id="repo_template" name="repo_template" value="{{.Form.RepoTemplate}}">
<div class="default text">{{.RepoTemplateName}}</div>
<div class="menu">
</div>
</div>
Expand All @@ -77,33 +77,33 @@
<div class="inline field">
<label>{{.locale.Tr "repo.template.items"}}</label>
<div class="ui checkbox">
<input class="hidden" name="git_content" type="checkbox" tabindex="0" {{if .git_content}}checked{{end}}>
<input class="hidden" name="git_content" type="checkbox" tabindex="0" {{if .Form.GitContent}}checked{{end}}>
<label>{{.locale.Tr "repo.template.git_content"}}</label>
</div>
<div class="ui checkbox{{if not .SignedUser.CanEditGitHook}} tooltip{{end}}"{{if not .SignedUser.CanEditGitHook}} data-content="{{.locale.Tr "repo.template.git_hooks_tooltip"}}"{{end}}>
<input class="hidden" name="git_hooks" type="checkbox" tabindex="0" {{if .git_hooks}}checked{{end}}>
<input class="hidden" name="git_hooks" type="checkbox" tabindex="0" {{if .Form.GitHooks}}checked{{end}}>
<label>{{.locale.Tr "repo.template.git_hooks"}}</label>
</div>
</div>
<div class="inline field">
<label></label>
<div class="ui checkbox">
<input class="hidden" name="webhooks" type="checkbox" tabindex="0" {{if .webhooks}}checked{{end}}>
<input class="hidden" name="webhooks" type="checkbox" tabindex="0" {{if .Form.Webhooks}}checked{{end}}>
<label>{{.locale.Tr "repo.template.webhooks"}}</label>
</div>
<div class="ui checkbox">
<input class="hidden" name="topics" type="checkbox" tabindex="0" {{if .topics}}checked{{end}}>
<input class="hidden" name="topics" type="checkbox" tabindex="0" {{if .Form.Topics}}checked{{end}}>
<label>{{.locale.Tr "repo.template.topics"}}</label>
</div>
</div>
<div class="inline field">
<label></label>
<div class="ui checkbox">
<input class="hidden" name="avatar" type="checkbox" tabindex="0" {{if .avatar}}checked{{end}}>
<input class="hidden" name="avatar" type="checkbox" tabindex="0" {{if .Form.Avatar}}checked{{end}}>
<label>{{.locale.Tr "repo.template.avatar"}}</label>
</div>
<div class="ui checkbox">
<input class="hidden" name="labels" type="checkbox" tabindex="0" {{if .labels}}checked{{end}}>
<input class="hidden" name="labels" type="checkbox" tabindex="0" {{if .Form.Labels}}checked{{end}}>
<label>{{.locale.Tr "repo.template.issue_labels"}}</label>
</div>
</div>
Expand All @@ -113,7 +113,7 @@
<div class="inline field">
<label>{{.locale.Tr "repo.issue_labels"}}</label>
<div class="ui search normal selection dropdown">
<input type="hidden" name="issue_labels" value="{{.issueLabels}}">
<input type="hidden" name="issue_labels" value="{{.Form.IssueLabels}}">
<div class="default text">{{.locale.Tr "repo.issue_labels_helper"}}</div>
<div class="menu">
<div class="item" data-value="">{{.locale.Tr "repo.issue_labels_helper"}}</div>
Expand All @@ -129,7 +129,7 @@
<div class="inline field">
<label>.gitignore</label>
<div class="ui multiple search normal selection dropdown">
<input type="hidden" name="gitignores" value="{{.gitignores}}">
<input type="hidden" name="gitignores" value="{{.Form.Gitignores}}">
<div class="default text">{{.locale.Tr "repo.repo_gitignore_helper"}}</div>
<div class="menu">
{{range .Gitignores}}
Expand All @@ -142,7 +142,7 @@
<div class="inline field">
<label>{{.locale.Tr "repo.license"}}</label>
<div class="ui search selection dropdown">
<input type="hidden" name="license" value="{{.license}}">
<input type="hidden" name="license" value="{{.Form.License}}">
<div class="default text">{{.locale.Tr "repo.license_helper"}}</div>
<div class="menu">
<div class="item" data-value="">{{.locale.Tr "repo.license_helper"}}</div>
Expand All @@ -157,7 +157,7 @@
<div class="inline field">
<label>{{.locale.Tr "repo.readme"}}</label>
<div class="ui selection dropdown">
<input type="hidden" name="readme" value="{{.readme}}">
<input type="hidden" name="readme" value="{{.Form.Readme}}">
<div class="default text">{{.locale.Tr "repo.readme_helper"}}</div>
<div class="menu">
{{range .Readmes}}
Expand All @@ -169,19 +169,19 @@
</div>
<div class="inline field">
<div class="ui checkbox" id="auto-init">
<input class="hidden" name="auto_init" type="checkbox" tabindex="0" {{if .auto_init}}checked{{end}}>
<input class="hidden" name="auto_init" type="checkbox" tabindex="0" {{if .Form.AutoInit}}checked{{end}}>
<label>{{.locale.Tr "repo.auto_init"}}</label>
</div>
</div>
<div class="inline field">
<label for="default_branch">{{.locale.Tr "repo.default_branch"}}</label>
<input id="default_branch" name="default_branch" value="{{.default_branch}}" placeholder="{{.default_branch}}">
<input id="default_branch" name="default_branch" value="{{.Form.DefaultBranch}}" placeholder="{{.default_branch}}">
<span class="help">{{.locale.Tr "repo.default_branch_helper"}}</span>
</div>
<div class="inline field">
<label>{{.locale.Tr "repo.settings.trust_model"}}</label>
<div class="ui selection owner dropdown">
<input type="hidden" id="trust_model" name="trust_model" value="default" required>
<input type="hidden" id="trust_model" name="trust_model" value="{{.Form.TrustModel}}" required>
<div class="default text">{{.locale.Tr "repo.settings.trust_model"}}</div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
Expand All @@ -204,7 +204,7 @@
<div class="inline field">
<label>{{.locale.Tr "repo.template"}}</label>
<div class="ui checkbox">
<input class="hidden" name="template" type="checkbox" tabindex="0">
<input class="hidden" name="template" type="checkbox" tabindex="0" {{if .Form.Template}}checked{{end}}>
<label>{{.locale.Tr "repo.template_helper"}}</label>
</div>
</div>
Expand Down