From a616127909ee4d1cfedcb51094acd6b064a46a4f Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Wed, 18 Oct 2023 11:58:25 +0800 Subject: [PATCH] Add organization.DefaultPassword --- init_data.json.template | 1 + object/application.go | 3 +++ object/organization.go | 9 +++++++++ object/user.go | 4 ++++ web/src/OrganizationEditPage.js | 10 ++++++++++ web/src/OrganizationListPage.js | 1 + 6 files changed, 28 insertions(+) diff --git a/init_data.json.template b/init_data.json.template index 1d91266c..9dc69807 100644 --- a/init_data.json.template +++ b/init_data.json.template @@ -15,6 +15,7 @@ "tags": [], "languages": ["en", "zh", "es", "fr", "de", "id", "ja", "ko", "ru", "vi", "it", "ms", "tr","ar", "he", "nl", "pl", "fi", "sv", "uk", "kk", "fa"], "masterPassword": "", + "defaultPassword": "", "initScore": 2000, "enableSoftDeletion": false, "isProfilePublic": true, diff --git a/object/application.go b/object/application.go index ea638876..70f947e1 100644 --- a/object/application.go +++ b/object/application.go @@ -315,6 +315,9 @@ func GetMaskedApplication(application *Application, userId string) *Application if application.OrganizationObj.MasterPassword != "" { application.OrganizationObj.MasterPassword = "***" } + if application.OrganizationObj.DefaultPassword != "" { + application.OrganizationObj.DefaultPassword = "***" + } if application.OrganizationObj.PasswordType != "" { application.OrganizationObj.PasswordType = "***" } diff --git a/object/organization.go b/object/organization.go index 5ed56d3c..3bfc5f20 100644 --- a/object/organization.go +++ b/object/organization.go @@ -64,6 +64,7 @@ type Organization struct { Languages []string `xorm:"varchar(255)" json:"languages"` ThemeData *ThemeData `xorm:"json" json:"themeData"` MasterPassword string `xorm:"varchar(100)" json:"masterPassword"` + DefaultPassword string `xorm:"varchar(100)" json:"defaultPassword"` InitScore int `json:"initScore"` EnableSoftDeletion bool `json:"enableSoftDeletion"` IsProfilePublic bool `json:"isProfilePublic"` @@ -155,6 +156,9 @@ func GetMaskedOrganization(organization *Organization, errs ...error) (*Organiza if organization.MasterPassword != "" { organization.MasterPassword = "***" } + if organization.DefaultPassword != "" { + organization.DefaultPassword = "***" + } return organization, nil } @@ -202,9 +206,14 @@ func UpdateOrganization(id string, organization *Organization) (bool, error) { } session := ormer.Engine.ID(core.PK{owner, name}).AllCols() + if organization.MasterPassword == "***" { session.Omit("master_password") } + if organization.DefaultPassword == "***" { + session.Omit("default_password") + } + affected, err := session.Update(organization) if err != nil { return false, err diff --git a/object/user.go b/object/user.go index 37564423..910bd728 100644 --- a/object/user.go +++ b/object/user.go @@ -696,6 +696,10 @@ func AddUser(user *User) (bool, error) { return false, nil } + if organization.DefaultPassword != "" && user.Password == "123" { + user.Password = organization.DefaultPassword + } + if user.PasswordType == "" || user.PasswordType == "plain" { user.UpdateUserPassword(organization) } diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index 89613e1a..ebae63d8 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -313,6 +313,16 @@ class OrganizationEditPage extends React.Component { }} /> + + + {Setting.getLabel(i18next.t("general:Default password"), i18next.t("general:Default password - Tooltip"))} : + + + { + this.updateOrganizationField("defaultPassword", e.target.value); + }} /> + + {Setting.getLabel(i18next.t("organization:Init score"), i18next.t("organization:Init score - Tooltip"))} : diff --git a/web/src/OrganizationListPage.js b/web/src/OrganizationListPage.js index e346a23a..33d05c7e 100644 --- a/web/src/OrganizationListPage.js +++ b/web/src/OrganizationListPage.js @@ -41,6 +41,7 @@ class OrganizationListPage extends BaseListPage { tags: [], languages: Setting.Countries.map(item => item.key), masterPassword: "", + defaultPassword: "", enableSoftDeletion: false, isProfilePublic: true, accountItems: [