mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
Merge pull request #9501 from swordqiu/feature/qj-user-add-lang-attribute
feature(keystone): user add language attribute
This commit is contained in:
@@ -174,6 +174,8 @@ func init() {
|
||||
|
||||
IdpId string `help:"Id of identity provider to link with"`
|
||||
IdpEntityId string `help:"Entity id of identity provider to link with"`
|
||||
|
||||
Lang string `help:"user default language"`
|
||||
}
|
||||
R(&UserCreateOptions{}, "user-create", "Create a user", func(s *mcclient.ClientSession, args *UserCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
@@ -224,6 +226,10 @@ func init() {
|
||||
params.Add(jsonutils.NewString(args.IdpEntityId), "idp_entity_id")
|
||||
}
|
||||
|
||||
if len(args.Lang) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Lang), "lang")
|
||||
}
|
||||
|
||||
/*if len(args.DefaultProject) > 0 {
|
||||
projId, err := modules.Projects.GetId(s, args.DefaultProject, nil)
|
||||
if err != nil {
|
||||
@@ -265,6 +271,8 @@ func init() {
|
||||
// Option []string `help:"User options"`
|
||||
|
||||
SkipPasswordComplexityCheck bool `help:"skip_password_complexity_check"`
|
||||
|
||||
Lang string `help:"update user language"`
|
||||
}
|
||||
R(&UserUpdateOptions{}, "user-update", "Update a user", func(s *mcclient.ClientSession, args *UserUpdateOptions) error {
|
||||
query := jsonutils.NewDict()
|
||||
@@ -321,6 +329,9 @@ func init() {
|
||||
} else if args.DisableMfa {
|
||||
params.Add(jsonutils.JSONFalse, "enable_mfa")
|
||||
}
|
||||
if len(args.Lang) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Lang), "lang")
|
||||
}
|
||||
// if len(args.DefaultProject) > 0 {
|
||||
// projId, err := modules.Projects.GetId(s, args.DefaultProject, nil)
|
||||
// if err != nil {
|
||||
|
||||
@@ -147,7 +147,7 @@ require (
|
||||
yunion.io/x/ovsdb v0.0.0-20200526071744-27bf0940cbc7
|
||||
yunion.io/x/pkg v0.0.0-20201123083159-ca3aea986ff2
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/sqlchemy v0.0.0-20201208011733-4adc2e143fde
|
||||
yunion.io/x/sqlchemy v0.0.0-20201218150209-7f971e45179f
|
||||
yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce
|
||||
)
|
||||
|
||||
|
||||
@@ -937,7 +937,7 @@ yunion.io/x/pkg v0.0.0-20201123083159-ca3aea986ff2 h1:NeCr2J8HjcIuJvEhP0rwWA1UKP
|
||||
yunion.io/x/pkg v0.0.0-20201123083159-ca3aea986ff2/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v0.0.0-20201208011733-4adc2e143fde h1:qE2NGwZdiALSGsVbnzugFBSZ5N1cmGMJsWOGnoexuDg=
|
||||
yunion.io/x/sqlchemy v0.0.0-20201208011733-4adc2e143fde/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
|
||||
yunion.io/x/sqlchemy v0.0.0-20201218150209-7f971e45179f h1:/kYVDTlHjq12EJLw3+zkrJA4psxRYAQ8MB461S9pkyg=
|
||||
yunion.io/x/sqlchemy v0.0.0-20201218150209-7f971e45179f/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
|
||||
yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce h1:kU8xE7O5uZ1GSJVMZHoJ+jrNL7csUQHYGyAPW9QfNpE=
|
||||
yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
|
||||
|
||||
@@ -205,6 +205,13 @@ type SCloudaccount struct {
|
||||
SAMLAuth *bool `json:"saml_auth,omitempty"`
|
||||
}
|
||||
|
||||
// SCloudimage is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudimage.
|
||||
type SCloudimage struct {
|
||||
apis.SStandaloneResourceBase
|
||||
apis.SExternalizedResourceBase
|
||||
SCloudregionResourceBase
|
||||
}
|
||||
|
||||
// SCloudprovider is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudprovider.
|
||||
type SCloudprovider struct {
|
||||
apis.SEnabledStatusStandaloneResourceBase
|
||||
@@ -2123,11 +2130,10 @@ type SSecurityGroupRule struct {
|
||||
|
||||
// SServerSku is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SServerSku.
|
||||
type SServerSku struct {
|
||||
apis.SStatusStandaloneResourceBase
|
||||
apis.SEnabledStatusStandaloneResourceBase
|
||||
apis.SExternalizedResourceBase
|
||||
SCloudregionResourceBase
|
||||
SZoneResourceBase
|
||||
Enabled bool `json:"enabled"`
|
||||
// SkuId string `width:"64" charset:"ascii" nullable:"false" list:"user" create:"admin_required"` // x2.large
|
||||
InstanceTypeFamily string `json:"instance_type_family"`
|
||||
// x2
|
||||
|
||||
@@ -450,6 +450,8 @@ type UserUpdateInput struct {
|
||||
Password string `json:"password"`
|
||||
|
||||
SkipPasswordComplexityCheck *bool `json:"skip_password_complexity_check"`
|
||||
|
||||
Lang string `json:"lang"`
|
||||
}
|
||||
|
||||
type UserCreateInput struct {
|
||||
@@ -474,6 +476,8 @@ type UserCreateInput struct {
|
||||
IdpId string `json:"idp_id"`
|
||||
|
||||
IdpEntityId string `json:"idp_entity_id"`
|
||||
|
||||
Lang string `json:"lang"`
|
||||
}
|
||||
|
||||
type ProjectCreateInput struct {
|
||||
|
||||
@@ -292,6 +292,7 @@ type SUser struct {
|
||||
DefaultProjectId string `json:"default_project_id"`
|
||||
AllowWebConsole *bool `json:"allow_web_console,omitempty"`
|
||||
EnableMfa *bool `json:"enable_mfa,omitempty"`
|
||||
Lang string `json:"lang"`
|
||||
}
|
||||
|
||||
// SUserOption is an autogenerated struct via yunion.io/x/onecloud/pkg/keystone/models.SUserOption.
|
||||
|
||||
@@ -158,6 +158,7 @@ type SMetricField struct {
|
||||
DisplayName string `json:"display_name"`
|
||||
Unit string `json:"unit"`
|
||||
ValueType string `json:"value_type"`
|
||||
Score int `json:"score"`
|
||||
}
|
||||
|
||||
// SMetricMeasurement is an autogenerated struct via yunion.io/x/onecloud/pkg/monitor/models.SMetricMeasurement.
|
||||
@@ -192,58 +193,6 @@ type SNotification struct {
|
||||
Settings interface{} `json:"settings"`
|
||||
}
|
||||
|
||||
// SSuggestSysAlert is an autogenerated struct via yunion.io/x/onecloud/pkg/monitor/models.SSuggestSysAlert.
|
||||
type SSuggestSysAlert struct {
|
||||
apis.SVirtualResourceBase
|
||||
apis.SEnabledResourceBase
|
||||
// 监控规则对应的json对象
|
||||
RuleName string `json:"rule_name"`
|
||||
MonitorConfig interface{} `json:"monitor_config"`
|
||||
// 监控规则type:Rule Type
|
||||
Type string `json:"type"`
|
||||
ResMeta interface{} `json:"res_meta"`
|
||||
// problem may have more than one ,so the problem instanceof jsonutils.jsonArray
|
||||
Problem interface{} `json:"problem"`
|
||||
// Suggest string `width:"256" list:"user" update:"user"`
|
||||
Action string `json:"action"`
|
||||
ResId string `json:"res_id"`
|
||||
CloudEnv string `json:"cloud_env"`
|
||||
Provider string `json:"provider"`
|
||||
Project string `json:"project"`
|
||||
Cloudaccount string `json:"cloudaccount"`
|
||||
// 费用
|
||||
Amount float64 `json:"amount"`
|
||||
// 币种
|
||||
Currency string `json:"currency"`
|
||||
}
|
||||
|
||||
// SSuggestSysRule is an autogenerated struct via yunion.io/x/onecloud/pkg/monitor/models.SSuggestSysRule.
|
||||
type SSuggestSysRule struct {
|
||||
apis.SStandaloneResourceBase
|
||||
apis.SEnabledResourceBase
|
||||
Type string `json:"type"`
|
||||
Period string `json:"period"`
|
||||
TimeFrom string `json:"time_from"`
|
||||
Setting interface{} `json:"setting"`
|
||||
ExecTime time.Time `json:"exec_time"`
|
||||
}
|
||||
|
||||
// SSuggestSysRuleConfig is an autogenerated struct via yunion.io/x/onecloud/pkg/monitor/models.SSuggestSysRuleConfig.
|
||||
type SSuggestSysRuleConfig struct {
|
||||
apis.SStandaloneResourceBase
|
||||
SMonitorScopedResource
|
||||
// RuleId is SSuggestSysRule model object id
|
||||
// RuleId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"`
|
||||
// Type is suggestsysrules driver type
|
||||
Type string `json:"type"`
|
||||
// ResourceType is suggestsysrules driver resource type
|
||||
ResourceType string `json:"resource_type"`
|
||||
// ResourceId is suggest alert result resource id
|
||||
ResourceId string `json:"resource_id"`
|
||||
// IgnoreAlert means whether or not show SSuggestSysAlert results for current scope
|
||||
IgnoreAlert bool `json:"ignore_alert"`
|
||||
}
|
||||
|
||||
// SV1Alert is an autogenerated struct via yunion.io/x/onecloud/pkg/monitor/models.SV1Alert.
|
||||
type SV1Alert struct {
|
||||
SAlert
|
||||
|
||||
+7
-3
@@ -13,6 +13,10 @@ const (
|
||||
ctxLangKey = ctxLang(0)
|
||||
)
|
||||
|
||||
var (
|
||||
defaultLang = language.English
|
||||
)
|
||||
|
||||
func WithLangTag(ctx context.Context, tag language.Tag) context.Context {
|
||||
return context.WithValue(ctx, ctxLangKey, tag)
|
||||
}
|
||||
@@ -20,7 +24,7 @@ func WithLangTag(ctx context.Context, tag language.Tag) context.Context {
|
||||
func WithLang(ctx context.Context, lang string) context.Context {
|
||||
tag, err := language.Parse(lang)
|
||||
if err != nil {
|
||||
tag = language.English
|
||||
tag = defaultLang
|
||||
}
|
||||
return WithLangTag(ctx, tag)
|
||||
}
|
||||
@@ -35,7 +39,7 @@ func WithRequestLang(ctx context.Context, req *http.Request) context.Context {
|
||||
if cookie, err := req.Cookie("lang"); err == nil {
|
||||
return WithLang(ctx, cookie.Value)
|
||||
}
|
||||
return WithLangTag(ctx, language.English)
|
||||
return WithLangTag(ctx, defaultLang)
|
||||
}
|
||||
|
||||
func Lang(ctx context.Context) language.Tag {
|
||||
@@ -46,7 +50,7 @@ func Lang(ctx context.Context) language.Tag {
|
||||
if langv != nil {
|
||||
lang = langv.(language.Tag)
|
||||
} else {
|
||||
lang = language.English
|
||||
lang = defaultLang
|
||||
}
|
||||
return lang
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ func init() {
|
||||
),
|
||||
}
|
||||
UserManager.SetVirtualObject(UserManager)
|
||||
db.InitManager(func() {
|
||||
UserManager.TableSpec().ColumnSpec("lang").SetDefault(options.Options.DefaultUserLanguage)
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -93,6 +96,8 @@ type SUser struct {
|
||||
|
||||
AllowWebConsole tristate.TriState `nullable:"false" default:"true" list:"domain" update:"domain" create:"domain_optional"`
|
||||
EnableMfa tristate.TriState `nullable:"false" default:"false" list:"domain" update:"domain" create:"domain_optional"`
|
||||
|
||||
Lang string `width:"8" charset:"ascii" nullable:"false" list:"domain" update:"domain" create:"domain_optional"`
|
||||
}
|
||||
|
||||
func (manager *SUserManager) GetContextManagers() [][]db.IModelManager {
|
||||
@@ -664,6 +669,7 @@ func userExtra(user *SUser, out api.UserDetails) api.UserDetails {
|
||||
nextUpdate := update.Add(time.Duration(options.Options.FetchScopeResourceCountIntervalSeconds) * time.Second)
|
||||
out.ExtResourcesNextUpdate = nextUpdate
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ type SKeystoneOptions struct {
|
||||
SessionEndpointType string `help:"Client session end point type"`
|
||||
|
||||
AllowJoinProjectsAcrossDomains bool `help:"allow users/groups to join projects across domains" default:"false"`
|
||||
|
||||
DefaultUserLanguage string `help:"default user language, default to zh-CN" default:"zh-CN"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -73,5 +75,9 @@ func OnOptionsChange(oldOptions, newOptions interface{}) bool {
|
||||
changed = true
|
||||
}
|
||||
|
||||
if oldOpts.DefaultUserLanguage != newOpts.DefaultUserLanguage {
|
||||
changed = true
|
||||
}
|
||||
|
||||
return changed
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1152,7 +1152,7 @@ yunion.io/x/pkg/util/workqueue
|
||||
yunion.io/x/pkg/utils
|
||||
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/s3cli
|
||||
# yunion.io/x/sqlchemy v0.0.0-20201208011733-4adc2e143fde
|
||||
# yunion.io/x/sqlchemy v0.0.0-20201218150209-7f971e45179f
|
||||
yunion.io/x/sqlchemy
|
||||
# yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce
|
||||
yunion.io/x/structarg
|
||||
|
||||
+6
@@ -54,6 +54,8 @@ type IColumnSpec interface {
|
||||
Tags() map[string]string
|
||||
|
||||
IsPointer() bool
|
||||
|
||||
SetDefault(defStr string)
|
||||
}
|
||||
|
||||
type SBaseColumn struct {
|
||||
@@ -90,6 +92,10 @@ func (c *SBaseColumn) Default() string {
|
||||
return c.defaultString
|
||||
}
|
||||
|
||||
func (c *SBaseColumn) SetDefault(defStr string) {
|
||||
c.defaultString = defStr
|
||||
}
|
||||
|
||||
func (c *SBaseColumn) IsSupportDefault() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user