Skip to content

Commit

Permalink
feat: init score in organization (casdoor#1388)
Browse files Browse the repository at this point in the history
* feat: init score in organization

* Update OrganizationEditPage.js

Co-authored-by: hsluoyz <[email protected]>
  • Loading branch information
leo220yuyaodog and hsluoyz authored Dec 10, 2022
1 parent e3c36be commit a51f0d7
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion controllers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions controllers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions object/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
1 change: 1 addition & 0 deletions object/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
13 changes: 11 additions & 2 deletions web/src/OrganizationEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -280,6 +279,16 @@ class OrganizationEditPage extends React.Component {
</Select>
</Col>
</Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 19 : 2}>
{Setting.getLabel(i18next.t("organization:InitScore"), i18next.t("organization:The user's initScore - Tooltip"))} :
</Col>
<Col span={4} >
<InputNumber value={this.state.organization.initScore} onChange={value => {
this.updateOrganizationField("initScore", value);
}} />
</Col>
</Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 19 : 2}>
{Setting.getLabel(i18next.t("organization:Soft deletion"), i18next.t("organization:Soft deletion - Tooltip"))} :
Expand Down
1 change: 1 addition & 0 deletions web/src/UserListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/de/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/en/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/fr/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/ja/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/ko/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/ru/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 сайта",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/zh/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
"Default avatar": "默认头像",
"Edit Organization": "编辑组织",
"Favicon": "图标",
"InitScore": "初始积分",
"Is profile public": "用户个人页公开",
"Is profile public - Tooltip": "关闭后,只有全局管理员或同组织用户才能访问用户主页",
"Modify rule": "修改规则",
Expand All @@ -338,6 +339,7 @@
"Soft deletion - Tooltip": "启用后,删除用户信息时不会在数据库彻底清除,只会标记为已删除状态",
"Tags": "标签集合",
"Tags - Tooltip": "可供用户选择的标签的集合",
"The user's initScore - Tooltip": "用户的初始积分",
"View rule": "查看规则",
"Visible": "是否可见",
"Website URL": "网页地址",
Expand Down

0 comments on commit a51f0d7

Please sign in to comment.