diff --git a/models/auth/source.go b/models/auth/source.go index 0a904b7772394..373c44dc10797 100644 --- a/models/auth/source.go +++ b/models/auth/source.go @@ -42,6 +42,36 @@ func (typ Type) Int() int { return int(typ) } +// IsLDAP returns true of this type is of the LDAP type. +func (typ Type) IsLDAP() bool { + return typ == LDAP +} + +// IsDLDAP returns true of this type is of the DLDAP type. +func (typ Type) IsDLDAP() bool { + return typ == DLDAP +} + +// IsSMTP returns true of this type is of the SMTP type. +func (typ Type) IsSMTP() bool { + return typ == SMTP +} + +// IsPAM returns true of this type is of the PAM type. +func (typ Type) IsPAM() bool { + return typ == PAM +} + +// IsOAuth2 returns true of this type is of the OAuth2 type. +func (typ Type) IsOAuth2() bool { + return typ == OAuth2 +} + +// IsSSPI returns true of this type is of the SSPI type. +func (typ Type) IsSSPI() bool { + return typ == SSPI +} + // Names contains the name of LoginType values. var Names = map[Type]string{ LDAP: "LDAP (via BindDN)", @@ -150,32 +180,32 @@ func (source *Source) TypeName() string { // IsLDAP returns true of this source is of the LDAP type. func (source *Source) IsLDAP() bool { - return source.Type == LDAP + return source.Type.IsLDAP() } // IsDLDAP returns true of this source is of the DLDAP type. func (source *Source) IsDLDAP() bool { - return source.Type == DLDAP + return source.Type.IsDLDAP() } // IsSMTP returns true of this source is of the SMTP type. func (source *Source) IsSMTP() bool { - return source.Type == SMTP + return source.Type.IsSMTP() } // IsPAM returns true of this source is of the PAM type. func (source *Source) IsPAM() bool { - return source.Type == PAM + return source.Type.IsPAM() } // IsOAuth2 returns true of this source is of the OAuth2 type. func (source *Source) IsOAuth2() bool { - return source.Type == OAuth2 + return source.Type.IsOAuth2() } // IsSSPI returns true of this source is of the SSPI type. func (source *Source) IsSSPI() bool { - return source.Type == SSPI + return source.Type.IsSSPI() } // HasTLS returns true of this source supports TLS. diff --git a/modules/web/middleware/binding.go b/modules/web/middleware/binding.go index 8b74a864d9571..4ba73d52109a9 100644 --- a/modules/web/middleware/binding.go +++ b/modules/web/middleware/binding.go @@ -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 { diff --git a/routers/web/admin/auths.go b/routers/web/admin/auths.go index 6ebd23b7bbd59..f345677973804 100644 --- a/routers/web/admin/auths.go +++ b/routers/web/admin/auths.go @@ -92,26 +92,24 @@ func NewAuthSource(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true - ctx.Data["type"] = auth.LDAP.Int() - ctx.Data["CurrentTypeName"] = auth.Names[auth.LDAP] - ctx.Data["CurrentSecurityProtocol"] = ldap.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted] - ctx.Data["smtp_auth"] = "PLAIN" - ctx.Data["is_active"] = true - ctx.Data["is_sync_enabled"] = true + ctx.Data["TypeNames"] = auth.Names ctx.Data["AuthSources"] = authSources ctx.Data["SecurityProtocols"] = securityProtocols ctx.Data["SMTPAuths"] = smtp.Authenticators oauth2providers := oauth2.GetOAuth2Providers() ctx.Data["OAuth2Providers"] = oauth2providers - ctx.Data["SSPIAutoCreateUsers"] = true - ctx.Data["SSPIAutoActivateUsers"] = true - ctx.Data["SSPIStripDomainNames"] = true - ctx.Data["SSPISeparatorReplacement"] = "_" - ctx.Data["SSPIDefaultLanguage"] = "" - - // only the first as default - ctx.Data["oauth2_provider"] = oauth2providers[0].Name() + ctx.Data["Form"] = forms.AuthenticationForm{ + Type: auth.LDAP.Int(), + SMTPAuth: "PLAIN", + IsActive: true, + IsSyncEnabled: true, + Oauth2Provider: oauth2providers[0].Name(), // only the first as default + SSPIAutoCreateUsers: true, + SSPIAutoActivateUsers: true, + SSPIStripDomainNames: true, + SSPISeparatorReplacement: "_", + } ctx.HTML(http.StatusOK, tplAuthNew) } @@ -240,20 +238,12 @@ func NewAuthSourcePost(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true - ctx.Data["CurrentTypeName"] = auth.Type(form.Type).String() - ctx.Data["CurrentSecurityProtocol"] = ldap.SecurityProtocolNames[ldap.SecurityProtocol(form.SecurityProtocol)] ctx.Data["AuthSources"] = authSources ctx.Data["SecurityProtocols"] = securityProtocols ctx.Data["SMTPAuths"] = smtp.Authenticators oauth2providers := oauth2.GetOAuth2Providers() ctx.Data["OAuth2Providers"] = oauth2providers - ctx.Data["SSPIAutoCreateUsers"] = true - ctx.Data["SSPIAutoActivateUsers"] = true - ctx.Data["SSPIStripDomainNames"] = true - ctx.Data["SSPISeparatorReplacement"] = "_" - ctx.Data["SSPIDefaultLanguage"] = "" - hasTLS := false var config convert.Conversion switch auth.Type(form.Type) { @@ -330,6 +320,115 @@ func NewAuthSourcePost(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/admin/auths") } +func parseSource(ctx *context.Context) *auth.Source { + source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) + if err != nil { + ctx.ServerError("auth.GetSourceByID", err) + return nil + } + ctx.Data["HasTLS"] = source.HasTLS() + ctx.Data["Type"] = source.Type + + form := forms.AuthenticationForm{ + ID: source.ID, + Type: source.Type.Int(), + Name: source.Name, + IsActive: source.IsActive, + IsSyncEnabled: source.IsSyncEnabled, + } + + if source.Cfg != nil { + switch source.Type { + case auth.LDAP, auth.DLDAP: + cfg := source.Cfg.(*ldap.Source) + if cfg.SearchPageSize > 0 { + form.UsePagedSearch = true + } + form.Host = cfg.Host + form.Port = cfg.Port + form.SecurityProtocol = cfg.SecurityProtocol.Int() + form.SkipVerify = cfg.SkipVerify + form.BindDN = cfg.BindDN + form.BindPassword = cfg.BindPassword + form.UserBase = cfg.UserBase + form.AttributeUsername = cfg.AttributeUsername + form.AttributeName = cfg.AttributeName + form.AttributeSurname = cfg.AttributeSurname + form.AttributeMail = cfg.AttributeMail + form.AttributesInBind = cfg.AttributesInBind + form.AttributeSSHPublicKey = cfg.AttributeSSHPublicKey + form.AttributeAvatar = cfg.AttributeAvatar + form.SearchPageSize = int(cfg.SearchPageSize) + form.Filter = cfg.Filter + form.GroupsEnabled = cfg.GroupsEnabled + form.GroupDN = cfg.GroupDN + form.GroupFilter = cfg.GroupFilter + form.GroupMemberUID = cfg.GroupMemberUID + form.GroupTeamMap = cfg.GroupTeamMap + form.GroupTeamMapRemoval = cfg.GroupTeamMapRemoval + form.UserUID = cfg.UserUID + form.AdminFilter = cfg.AdminFilter + form.RestrictedFilter = cfg.RestrictedFilter + form.AllowDeactivateAll = cfg.AllowDeactivateAll + //form.Enabled=cfg.Enabled + form.SkipLocalTwoFA = cfg.SkipLocalTwoFA + case auth.SMTP: + cfg := source.Cfg.(*smtp.Source) + form.SMTPAuth = cfg.Auth + form.SMTPHost = cfg.Host + form.SMTPPort = cfg.Port + form.AllowedDomains = cfg.AllowedDomains + form.ForceSMTPS = cfg.ForceSMTPS + form.SkipVerify = cfg.SkipVerify + form.HeloHostname = cfg.HeloHostname + form.DisableHelo = cfg.DisableHelo + form.SkipLocalTwoFA = cfg.SkipLocalTwoFA + case auth.PAM: + cfg := source.Cfg.(*pam_service.Source) + form.PAMServiceName = cfg.ServiceName + form.PAMEmailDomain = cfg.EmailDomain + form.SkipLocalTwoFA = cfg.SkipLocalTwoFA + case auth.OAuth2: + cfg := source.Cfg.(*oauth2.Source) + form.Oauth2Provider = cfg.Provider + form.Oauth2Key = cfg.ClientID + form.Oauth2Secret = cfg.ClientSecret + form.OpenIDConnectAutoDiscoveryURL = cfg.OpenIDConnectAutoDiscoveryURL + if cfg.CustomURLMapping != nil { + form.Oauth2UseCustomURL = true + form.Oauth2TokenURL = cfg.CustomURLMapping.TokenURL + form.Oauth2AuthURL = cfg.CustomURLMapping.AuthURL + form.Oauth2ProfileURL = cfg.CustomURLMapping.ProfileURL + form.Oauth2EmailURL = cfg.CustomURLMapping.EmailURL + form.Oauth2Tenant = cfg.CustomURLMapping.Tenant + } + form.Oauth2IconURL = cfg.IconURL + form.Oauth2Scopes = strings.Join(cfg.Scopes, ",") + form.Oauth2RequiredClaimName = cfg.RequiredClaimName + form.Oauth2RequiredClaimValue = cfg.RequiredClaimValue + form.SkipLocalTwoFA = cfg.SkipLocalTwoFA + form.Oauth2GroupClaimName = cfg.GroupClaimName + form.Oauth2RestrictedGroup = cfg.RestrictedGroup + form.Oauth2AdminGroup = cfg.AdminGroup + form.Oauth2GroupTeamMap = cfg.GroupTeamMap + form.Oauth2GroupTeamMapRemoval = cfg.GroupTeamMapRemoval + case auth.SSPI: + cfg := source.Cfg.(*sspi.Source) + form.SSPIAutoCreateUsers = cfg.AutoCreateUsers + form.SSPIAutoActivateUsers = cfg.AutoActivateUsers + form.SSPIStripDomainNames = cfg.StripDomainNames + form.SSPISeparatorReplacement = cfg.SeparatorReplacement + form.SSPIDefaultLanguage = cfg.DefaultLanguage + default: + ctx.Error(http.StatusBadRequest) + return nil + } + } + ctx.Data["Form"] = form + + return source +} + // EditAuthSource render editing auth source page func EditAuthSource(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.auths.edit") @@ -340,27 +439,12 @@ func EditAuthSource(ctx *context.Context) { ctx.Data["SMTPAuths"] = smtp.Authenticators oauth2providers := oauth2.GetOAuth2Providers() ctx.Data["OAuth2Providers"] = oauth2providers + ctx.Data["SourceTypeNames"] = auth.Names - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) - if err != nil { - ctx.ServerError("auth.GetSourceByID", err) + parseSource(ctx) + if ctx.Written() { return } - ctx.Data["Source"] = source - ctx.Data["HasTLS"] = source.HasTLS() - - if source.IsOAuth2() { - type Named interface { - Name() string - } - - for _, provider := range oauth2providers { - if provider.Name() == source.Cfg.(Named).Name() { - ctx.Data["CurrentOAuth2Provider"] = provider - break - } - } - } ctx.HTML(http.StatusOK, tplAuthEdit) } @@ -372,23 +456,18 @@ func EditAuthSourcePost(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true + ctx.Data["SecurityProtocols"] = securityProtocols ctx.Data["SMTPAuths"] = smtp.Authenticators oauth2providers := oauth2.GetOAuth2Providers() ctx.Data["OAuth2Providers"] = oauth2providers + ctx.Data["SourceTypeNames"] = auth.Names - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) - if err != nil { - ctx.ServerError("auth.GetSourceByID", err) - return - } - ctx.Data["Source"] = source - ctx.Data["HasTLS"] = source.HasTLS() - - if ctx.HasError() { - ctx.HTML(http.StatusOK, tplAuthEdit) + source := parseSource(ctx) + if ctx.Written() { return } + var err error var config convert.Conversion switch auth.Type(form.Type) { case auth.LDAP, auth.DLDAP: diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 531f14d08627e..f3d71e2841844 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -5,6 +5,7 @@ package admin import ( + "fmt" "net/http" "net/url" "strconv" @@ -28,6 +29,11 @@ import ( user_service "code.gitea.io/gitea/services/user" ) +type EditUserForm struct { + *forms.AdminEditUserForm + *forms.AvatarForm +} + const ( tplUsers base.TplName = "admin/user/list" tplUserNew base.TplName = "admin/user/new" @@ -82,10 +88,12 @@ func NewUser(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.users.new_account") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminUsers"] = true - ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() - ctx.Data["login_type"] = "0-0" + ctx.Data["Form"] = forms.AdminCreateUserForm{ + LoginType: "0-0", + Visibility: setting.Service.DefaultUserVisibilityMode, + } sources, err := auth.Sources() if err != nil { @@ -104,7 +112,6 @@ func NewUserPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.users.new_account") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminUsers"] = true - ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() sources, err := auth.Sources() @@ -206,7 +213,7 @@ func NewUserPost(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10)) } -func prepareUserInfo(ctx *context.Context) *user_model.User { +func prepareUserInfo(ctx *context.Context, adminEditUserForm *forms.AdminEditUserForm, avatarForm *forms.AvatarForm) (*user_model.User, *EditUserForm) { u, err := user_model.GetUserByID(ctx, ctx.ParamsInt64(":userid")) if err != nil { if user_model.IsErrUserNotExist(err) { @@ -214,40 +221,78 @@ func prepareUserInfo(ctx *context.Context) *user_model.User { } else { ctx.ServerError("GetUserByID", err) } - return nil + return nil, nil } ctx.Data["User"] = u + var loginSource *auth.Source if u.LoginSource > 0 { - ctx.Data["LoginSource"], err = auth.GetSourceByID(u.LoginSource) + loginSource, err = auth.GetSourceByID(u.LoginSource) if err != nil { ctx.ServerError("auth.GetSourceByID", err) - return nil + return nil, nil } } else { - ctx.Data["LoginSource"] = &auth.Source{} + loginSource = &auth.Source{} } + ctx.Data["LoginSource"] = loginSource sources, err := auth.Sources() if err != nil { ctx.ServerError("auth.Sources", err) - return nil + return nil, nil } ctx.Data["Sources"] = sources hasTOTP, err := auth.HasTwoFactorByUID(u.ID) if err != nil { ctx.ServerError("auth.HasTwoFactorByUID", err) - return nil + return nil, nil } hasWebAuthn, err := auth.HasWebAuthnRegistrationsByUID(u.ID) if err != nil { ctx.ServerError("auth.HasWebAuthnRegistrationsByUID", err) - return nil + return nil, nil } ctx.Data["TwoFactorEnabled"] = hasTOTP || hasWebAuthn - return u + var source string + if u.UseCustomAvatar { + source = "local" + } else { + source = "lookup" + } + + if adminEditUserForm == nil { + adminEditUserForm = &forms.AdminEditUserForm{ + LoginType: fmt.Sprintf("%d-%d", loginSource.Type.Int(), loginSource.ID), + UserName: u.Name, + LoginName: u.LoginName, + FullName: u.FullName, + Email: u.Email, + Website: u.Website, + Location: u.Location, + MaxRepoCreation: u.MaxRepoCreation, + Active: u.IsActive, + Admin: u.IsAdmin, + Restricted: u.IsRestricted, + AllowGitHook: u.CanEditGitHook(), + AllowImportLocal: u.CanImportLocal(), + AllowCreateOrganization: u.CanCreateOrganization(), + ProhibitLogin: u.ProhibitLogin, + Visibility: u.Visibility, + } + } + if avatarForm == nil { + avatarForm = &forms.AvatarForm{ + Source: source, + Gravatar: u.AvatarEmail, + } + } + form := &EditUserForm{adminEditUserForm, avatarForm} + ctx.Data["Form"] = form + + return u, form } // EditUser show editing user page @@ -259,7 +304,7 @@ func EditUser(ctx *context.Context) { ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() - prepareUserInfo(ctx) + prepareUserInfo(ctx, nil, nil) if ctx.Written() { return } @@ -276,7 +321,7 @@ func EditUserPost(ctx *context.Context) { ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() - u := prepareUserInfo(ctx) + u, f := prepareUserInfo(ctx, form, nil) if ctx.Written() { return } @@ -301,11 +346,11 @@ func EditUserPost(ctx *context.Context) { var err error if len(form.Password) < setting.MinPasswordLength { ctx.Data["Err_Password"] = true - ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserEdit, &form) + ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplUserEdit, &f) return } if !password.IsComplexEnough(form.Password) { - ctx.RenderWithErr(password.BuildComplexityError(ctx), tplUserEdit, &form) + ctx.RenderWithErr(password.BuildComplexityError(ctx), tplUserEdit, &f) return } pwned, err := password.IsPwned(ctx, form.Password) @@ -316,13 +361,13 @@ func EditUserPost(ctx *context.Context) { log.Error(err.Error()) errMsg = ctx.Tr("auth.password_pwned_err") } - ctx.RenderWithErr(errMsg, tplUserEdit, &form) + ctx.RenderWithErr(errMsg, tplUserEdit, &f) return } if err := user_model.ValidateEmail(form.Email); err != nil { ctx.Data["Err_Email"] = true - ctx.RenderWithErr(ctx.Tr("form.email_error"), tplUserEdit, &form) + ctx.RenderWithErr(ctx.Tr("form.email_error"), tplUserEdit, &f) return } @@ -341,7 +386,7 @@ func EditUserPost(ctx *context.Context) { if ctx.Written() { return } - ctx.RenderWithErr(ctx.Flash.ErrorMsg, tplUserEdit, &form) + ctx.RenderWithErr(ctx.Flash.ErrorMsg, tplUserEdit, &f) return } u.Name = form.UserName @@ -400,11 +445,11 @@ func EditUserPost(ctx *context.Context) { if err := user_model.UpdateUser(ctx, u, emailChanged); err != nil { if user_model.IsErrEmailAlreadyUsed(err) { ctx.Data["Err_Email"] = true - ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form) + ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &f) } else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) { ctx.Data["Err_Email"] = true - ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tplUserEdit, &form) + ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tplUserEdit, &f) } else { ctx.ServerError("UpdateUser", err) } @@ -455,12 +500,13 @@ func DeleteUser(ctx *context.Context) { // AvatarPost response for change user's avatar request func AvatarPost(ctx *context.Context) { - u := prepareUserInfo(ctx) + form := web.GetForm(ctx).(*forms.AvatarForm) + + u, _ := prepareUserInfo(ctx, nil, form) if ctx.Written() { return } - form := web.GetForm(ctx).(*forms.AvatarForm) if err := user_setting.UpdateAvatarSetting(ctx, form, u); err != nil { ctx.Flash.Error(err.Error()) } else { @@ -472,7 +518,7 @@ func AvatarPost(ctx *context.Context) { // DeleteAvatar render delete avatar page func DeleteAvatar(ctx *context.Context) { - u := prepareUserInfo(ctx) + u, _ := prepareUserInfo(ctx, nil, nil) if ctx.Written() { return } diff --git a/routers/web/org/org.go b/routers/web/org/org.go index f67e7edb4c7cc..4663ec3734f1d 100644 --- a/routers/web/org/org.go +++ b/routers/web/org/org.go @@ -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 diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index db8fc728dffc7..943691eec3e20 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -48,8 +48,16 @@ func Settings(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsOrgSettings"] = true ctx.Data["PageIsSettingsOptions"] = true - ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility - ctx.Data["RepoAdminChangeTeamAccess"] = ctx.Org.Organization.RepoAdminChangeTeamAccess + ctx.Data["Form"] = forms.UpdateOrgSettingForm{ + Name: ctx.Org.Organization.Name, + FullName: ctx.Org.Organization.FullName, + Description: ctx.Org.Organization.Description, + Website: ctx.Org.Organization.Website, + Location: ctx.Org.Organization.Location, + Visibility: ctx.Org.Organization.Visibility, + MaxRepoCreation: ctx.Org.Organization.MaxRepoCreation, + RepoAdminChangeTeamAccess: ctx.Org.Organization.RepoAdminChangeTeamAccess, + } ctx.HTML(http.StatusOK, tplSettingsOptions) } @@ -59,7 +67,6 @@ func SettingsPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsOrgSettings"] = true ctx.Data["PageIsSettingsOptions"] = true - ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility if ctx.HasError() { ctx.HTML(http.StatusOK, tplSettingsOptions) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 9b80e85324769..ac4f0f9923136 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -135,10 +135,7 @@ func Create(ctx *context.Context) { ctx.Data["LabelTemplateFiles"] = repo_module.LabelTemplateFiles 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() { @@ -146,16 +143,25 @@ func Create(ctx *context.Context) { } 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() diff --git a/templates/admin/auth/edit.tmpl b/templates/admin/auth/edit.tmpl index 49007e572da96..340848efdc7d0 100644 --- a/templates/admin/auth/edit.tmpl +++ b/templates/admin/auth/edit.tmpl @@ -10,25 +10,24 @@
{{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}} - +
- - {{.Source.TypeName}} + + {{index .SourceTypeNames .Form.Type}}
- +
- {{if or .Source.IsLDAP .Source.IsDLDAP}} - {{$cfg:=.Source.Cfg}} + {{if or .Type.IsLDAP .Type.IsDLDAP}}