From a51f0d7c08c0b7f911e14f1b4d7bb6926ba6981e Mon Sep 17 00:00:00 2001 From: Yaodong Yu <2814461814@qq.com> Date: Sat, 10 Dec 2022 22:27:12 +0800 Subject: [PATCH] feat: init score in organization (#1388) * feat: init score in organization * Update OrganizationEditPage.js Co-authored-by: hsluoyz --- controllers/account.go | 2 +- controllers/auth.go | 2 +- controllers/util.go | 8 ++++++-- object/init.go | 1 + object/organization.go | 1 + web/src/OrganizationEditPage.js | 13 +++++++++++-- web/src/UserListPage.js | 1 + web/src/locales/de/data.json | 2 ++ web/src/locales/en/data.json | 2 ++ web/src/locales/fr/data.json | 2 ++ web/src/locales/ja/data.json | 2 ++ web/src/locales/ko/data.json | 2 ++ web/src/locales/ru/data.json | 2 ++ web/src/locales/zh/data.json | 2 ++ 14 files changed, 36 insertions(+), 6 deletions(-) diff --git a/controllers/account.go b/controllers/account.go index bff29d85..d808e27f 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -161,7 +161,7 @@ func (c *ApiController) Signup() { username = id } - initScore, err := getInitScore() + initScore, err := getInitScore(organization) if err != nil { c.ResponseError(fmt.Errorf(c.T("account:Get init score failed, error: %w"), err).Error()) return diff --git a/controllers/auth.go b/controllers/auth.go index eb719064..7c81646b 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -412,7 +412,7 @@ func (c *ApiController) Login() { properties := map[string]string{} properties["no"] = strconv.Itoa(len(object.GetUsers(application.Organization)) + 2) - initScore, err := getInitScore() + initScore, err := getInitScore(organization) if err != nil { c.ResponseError(fmt.Errorf(c.T("auth:Get init score failed, error: %w"), err).Error()) return diff --git a/controllers/util.go b/controllers/util.go index ffc6710d..ece90de1 100644 --- a/controllers/util.go +++ b/controllers/util.go @@ -119,8 +119,12 @@ func (c *ApiController) RequireAdmin() (string, bool) { return user.Owner, true } -func getInitScore() (int, error) { - return strconv.Atoi(conf.GetConfigString("initScore")) +func getInitScore(organization *object.Organization) (int, error) { + if organization != nil { + return organization.InitScore, nil + } else { + return strconv.Atoi(conf.GetConfigString("initScore")) + } } func (c *ApiController) GetProviderFromContext(category string) (*object.Provider, *object.User, bool) { diff --git a/object/init.go b/object/init.go index 31b6ec18..b4bd24a6 100644 --- a/object/init.go +++ b/object/init.go @@ -59,6 +59,7 @@ func initBuiltInOrganization() bool { DefaultAvatar: fmt.Sprintf("%s/img/casbin.svg", conf.GetConfigString("staticBaseUrl")), Tags: []string{}, Languages: []string{"en", "zh", "es", "fr", "de", "ja", "ko", "ru"}, + InitScore: 2000, AccountItems: []*AccountItem{ {Name: "Organization", Visible: true, ViewRule: "Public", ModifyRule: "Admin"}, {Name: "ID", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"}, diff --git a/object/organization.go b/object/organization.go index 4cd5b8b2..44fe6948 100644 --- a/object/organization.go +++ b/object/organization.go @@ -47,6 +47,7 @@ type Organization struct { Tags []string `xorm:"mediumtext" json:"tags"` Languages []string `xorm:"varchar(255)" json:"languages"` MasterPassword string `xorm:"varchar(100)" json:"masterPassword"` + InitScore int `json:"initScore"` EnableSoftDeletion bool `json:"enableSoftDeletion"` IsProfilePublic bool `json:"isProfilePublic"` diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index ff7cce2e..9c94e3b9 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -13,7 +13,7 @@ // limitations under the License. import React from "react"; -import {Button, Card, Col, Input, Row, Select, Switch} from "antd"; +import {Button, Card, Col, Input, InputNumber, Row, Select, Switch} from "antd"; import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as ApplicationBackend from "./backend/ApplicationBackend"; import * as LdapBackend from "./backend/LdapBackend"; @@ -86,7 +86,6 @@ class OrganizationEditPage extends React.Component { updateOrganizationField(key, value) { value = this.parseOrganizationField(key, value); - const organization = this.state.organization; organization[key] = value; this.setState({ @@ -280,6 +279,16 @@ class OrganizationEditPage extends React.Component { + + + {Setting.getLabel(i18next.t("organization:InitScore"), i18next.t("organization:The user's initScore - Tooltip"))} : + + + { + this.updateOrganizationField("initScore", value); + }} /> + + {Setting.getLabel(i18next.t("organization:Soft deletion"), i18next.t("organization:Soft deletion - Tooltip"))} : diff --git a/web/src/UserListPage.js b/web/src/UserListPage.js index 36750d63..90d4d6e8 100644 --- a/web/src/UserListPage.js +++ b/web/src/UserListPage.js @@ -62,6 +62,7 @@ class UserListPage extends BaseListPage { isAdmin: (owner === "built-in"), isGlobalAdmin: (owner === "built-in"), IsForbidden: false, + score: this.state.organization.initScore, isDeleted: false, properties: {}, signupApplication: "app-built-in", diff --git a/web/src/locales/de/data.json b/web/src/locales/de/data.json index 8f1cb44e..adc5f005 100644 --- a/web/src/locales/de/data.json +++ b/web/src/locales/de/data.json @@ -330,6 +330,7 @@ "Default avatar": "Standard Avatar", "Edit Organization": "Organisation bearbeiten", "Favicon": "Févicon", + "InitScore": "InitScore", "Is profile public": "Is profile public", "Is profile public - Tooltip": "Is profile public - Tooltip", "Modify rule": "Modify rule", @@ -338,6 +339,7 @@ "Soft deletion - Tooltip": "Weiche Löschung - Tooltip", "Tags": "Tags", "Tags - Tooltip": "Tags - Tooltip", + "The user's initScore - Tooltip": "The user's initScore - Tooltip", "View rule": "View rule", "Visible": "Visible", "Website URL": "Website-URL", diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json index ed59511d..e9d522a1 100644 --- a/web/src/locales/en/data.json +++ b/web/src/locales/en/data.json @@ -330,6 +330,7 @@ "Default avatar": "Default avatar", "Edit Organization": "Edit Organization", "Favicon": "Favicon", + "InitScore": "InitScore", "Is profile public": "Is profile public", "Is profile public - Tooltip": "Is profile public - Tooltip", "Modify rule": "Modify rule", @@ -338,6 +339,7 @@ "Soft deletion - Tooltip": "Soft deletion - Tooltip", "Tags": "Tags", "Tags - Tooltip": "Tags - Tooltip", + "The user's initScore - Tooltip": "The user's initScore - Tooltip", "View rule": "View rule", "Visible": "Visible", "Website URL": "Website URL", diff --git a/web/src/locales/fr/data.json b/web/src/locales/fr/data.json index 1e7c94f8..bab1ec4b 100644 --- a/web/src/locales/fr/data.json +++ b/web/src/locales/fr/data.json @@ -330,6 +330,7 @@ "Default avatar": "Avatar par défaut", "Edit Organization": "Modifier l'organisation", "Favicon": "Favicon", + "InitScore": "InitScore", "Is profile public": "Is profile public", "Is profile public - Tooltip": "Is profile public - Tooltip", "Modify rule": "Modify rule", @@ -338,6 +339,7 @@ "Soft deletion - Tooltip": "Suppression de soft - infobulle", "Tags": "Tags", "Tags - Tooltip": "Tags - Tooltip", + "The user's initScore - Tooltip": "The user's initScore - Tooltip", "View rule": "View rule", "Visible": "Visible", "Website URL": "URL du site web", diff --git a/web/src/locales/ja/data.json b/web/src/locales/ja/data.json index d00f505b..e8109ac0 100644 --- a/web/src/locales/ja/data.json +++ b/web/src/locales/ja/data.json @@ -330,6 +330,7 @@ "Default avatar": "デフォルトのアバター", "Edit Organization": "組織を編集", "Favicon": "ファビコン", + "InitScore": "InitScore", "Is profile public": "Is profile public", "Is profile public - Tooltip": "Is profile public - Tooltip", "Modify rule": "Modify rule", @@ -338,6 +339,7 @@ "Soft deletion - Tooltip": "ソフト削除 - ツールチップ", "Tags": "Tags", "Tags - Tooltip": "Tags - Tooltip", + "The user's initScore - Tooltip": "The user's initScore - Tooltip", "View rule": "View rule", "Visible": "Visible", "Website URL": "Website URL", diff --git a/web/src/locales/ko/data.json b/web/src/locales/ko/data.json index c66dea2c..05b5c9d2 100644 --- a/web/src/locales/ko/data.json +++ b/web/src/locales/ko/data.json @@ -330,6 +330,7 @@ "Default avatar": "Default avatar", "Edit Organization": "Edit Organization", "Favicon": "Favicon", + "InitScore": "InitScore", "Is profile public": "Is profile public", "Is profile public - Tooltip": "Is profile public - Tooltip", "Modify rule": "Modify rule", @@ -338,6 +339,7 @@ "Soft deletion - Tooltip": "Soft deletion - Tooltip", "Tags": "Tags", "Tags - Tooltip": "Tags - Tooltip", + "The user's initScore - Tooltip": "The user's initScore - Tooltip", "View rule": "View rule", "Visible": "Visible", "Website URL": "Website URL", diff --git a/web/src/locales/ru/data.json b/web/src/locales/ru/data.json index 78b07035..5af89de4 100644 --- a/web/src/locales/ru/data.json +++ b/web/src/locales/ru/data.json @@ -330,6 +330,7 @@ "Default avatar": "Аватар по умолчанию", "Edit Organization": "Изменить организацию", "Favicon": "Иконка", + "InitScore": "InitScore", "Is profile public": "Is profile public", "Is profile public - Tooltip": "Is profile public - Tooltip", "Modify rule": "Modify rule", @@ -338,6 +339,7 @@ "Soft deletion - Tooltip": "Мягкое удаление - Подсказка", "Tags": "Tags", "Tags - Tooltip": "Tags - Tooltip", + "The user's initScore - Tooltip": "The user's initScore - Tooltip", "View rule": "View rule", "Visible": "Visible", "Website URL": "URL сайта", diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json index 78c4469b..cd14eea9 100644 --- a/web/src/locales/zh/data.json +++ b/web/src/locales/zh/data.json @@ -330,6 +330,7 @@ "Default avatar": "默认头像", "Edit Organization": "编辑组织", "Favicon": "图标", + "InitScore": "初始积分", "Is profile public": "用户个人页公开", "Is profile public - Tooltip": "关闭后,只有全局管理员或同组织用户才能访问用户主页", "Modify rule": "修改规则", @@ -338,6 +339,7 @@ "Soft deletion - Tooltip": "启用后,删除用户信息时不会在数据库彻底清除,只会标记为已删除状态", "Tags": "标签集合", "Tags - Tooltip": "可供用户选择的标签的集合", + "The user's initScore - Tooltip": "用户的初始积分", "View rule": "查看规则", "Visible": "是否可见", "Website URL": "网页地址",