Add user soft deletion.

This commit is contained in:
Gucheng Wang 2021-11-06 15:52:03 +08:00
parent db892333fe
commit 9e920181d2
11 changed files with 72 additions and 19 deletions

View File

@ -152,6 +152,7 @@ func (c *ApiController) Signup() {
IsAdmin: false,
IsGlobalAdmin: false,
IsForbidden: false,
IsDeleted: false,
SignupApplication: application.Name,
Properties: map[string]string{},
}

View File

@ -251,7 +251,7 @@ func (c *ApiController) Login() {
user = object.GetUserByField(application.Organization, "name", userInfo.Username)
}
if user != nil {
if user != nil && user.IsDeleted == false {
// Sign in via OAuth (want to sign up but already have account)
if user.IsForbidden {
@ -293,6 +293,7 @@ func (c *ApiController) Login() {
IsAdmin: false,
IsGlobalAdmin: false,
IsForbidden: false,
IsDeleted: false,
SignupApplication: application.Name,
Properties: properties,
}

View File

@ -102,7 +102,7 @@ func CheckPassword(user *User, password string) string {
func CheckUserPassword(organization string, username string, password string) (*User, string) {
user := GetUserByFields(organization, username)
if user == nil {
if user == nil || user.IsDeleted == true {
return nil, "the user does not exist, please sign up first"
}

View File

@ -67,6 +67,7 @@ func initBuiltInUser() {
IsAdmin: true,
IsGlobalAdmin: true,
IsForbidden: false,
IsDeleted: false,
Properties: make(map[string]string),
}
AddUser(user)

View File

@ -24,13 +24,14 @@ type Organization struct {
Name string `xorm:"varchar(100) notnull pk" json:"name"`
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
DisplayName string `xorm:"varchar(100)" json:"displayName"`
WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"`
Favicon string `xorm:"varchar(100)" json:"favicon"`
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"`
DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"`
DisplayName string `xorm:"varchar(100)" json:"displayName"`
WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"`
Favicon string `xorm:"varchar(100)" json:"favicon"`
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"`
DefaultAvatar string `xorm:"varchar(100)" json:"defaultAvatar"`
EnableSoftDeletion bool `json:"enableSoftDeletion"`
}
func GetOrganizationCount(owner string) int {

View File

@ -51,6 +51,7 @@ type User struct {
IsAdmin bool `json:"isAdmin"`
IsGlobalAdmin bool `json:"isGlobalAdmin"`
IsForbidden bool `json:"isForbidden"`
IsDeleted bool `json:"isDeleted"`
SignupApplication string `xorm:"varchar(100)" json:"signupApplication"`
Hash string `xorm:"varchar(100)" json:"hash"`
PreHash string `xorm:"varchar(100)" json:"preHash"`
@ -199,8 +200,8 @@ func UpdateUser(id string, user *User) bool {
}
affected, err := adapter.Engine.ID(core.PK{owner, name}).Cols("owner", "display_name", "avatar",
"location", "address", "region", "language", "affiliation", "title", "homepage", "bio", "score", "tag", "is_admin", "is_global_admin", "is_forbidden",
"hash", "properties").Update(user)
"location", "address", "region", "language", "affiliation", "title", "homepage", "bio", "score", "tag",
"is_admin", "is_global_admin", "is_forbidden", "is_deleted", "hash", "properties").Update(user)
if err != nil {
panic(err)
}

View File

@ -64,6 +64,7 @@ func createUserFromOriginalUser(originalUser *User, affiliationMap map[int]strin
IsAdmin: false,
IsGlobalAdmin: false,
IsForbidden: originalUser.Deleted != 0,
IsDeleted: false,
Properties: map[string]string{},
}
return user

View File

@ -13,7 +13,7 @@
// limitations under the License.
import React from "react";
import {Button, Card, Col, Input, Row, Select} from 'antd';
import {Button, Card, Col, Input, Row, Select, Switch} from 'antd';
import * as OrganizationBackend from "./backend/OrganizationBackend";
import * as LdapBackend from "./backend/LdapBackend";
import * as Setting from "./Setting";
@ -205,6 +205,16 @@ class OrganizationEditPage extends React.Component {
</Row>
</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"))} :
</Col>
<Col span={1} >
<Switch checked={this.state.organization.enableSoftDeletion} onChange={checked => {
this.updateOrganizationField('enableSoftDeletion', checked);
}} />
</Col>
</Row>
<Row style={{marginTop: '20px'}}>
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("general:LDAPs"), i18next.t("general:LDAPs - Tooltip"))} :

View File

@ -14,7 +14,7 @@
import React from "react";
import {Link} from "react-router-dom";
import {Button, Popconfirm, Table} from 'antd';
import {Button, Popconfirm, Switch, Table} from 'antd';
import moment from "moment";
import * as Setting from "./Setting";
import * as OrganizationBackend from "./backend/OrganizationBackend";
@ -59,6 +59,7 @@ class OrganizationListPage extends React.Component {
PasswordSalt: "",
phonePrefix: "86",
defaultAvatar: "https://casbin.org/img/casbin.svg",
enableSoftDeletion: false,
}
}
@ -158,7 +159,7 @@ class OrganizationListPage extends React.Component {
title: i18next.t("general:Password type"),
dataIndex: 'passwordType',
key: 'passwordType',
width: '100px',
width: '150px',
sorter: (a, b) => a.passwordType.localeCompare(b.passwordType),
},
{
@ -172,7 +173,7 @@ class OrganizationListPage extends React.Component {
title: i18next.t("organization:Default avatar"),
dataIndex: 'defaultAvatar',
key: 'defaultAvatar',
width: '50px',
width: '120px',
render: (text, record, index) => {
return (
<a target="_blank" rel="noreferrer" href={text}>
@ -181,6 +182,18 @@ class OrganizationListPage extends React.Component {
)
}
},
{
title: i18next.t("organization:Soft deletion"),
dataIndex: 'enableSoftDeletion',
key: 'enableSoftDeletion',
width: '140px',
sorter: (a, b) => a.enableSoftDeletion - b.enableSoftDeletion,
render: (text, record, index) => {
return (
<Switch disabled checkedChildren="ON" unCheckedChildren="OFF" checked={text} />
)
}
},
{
title: i18next.t("general:Action"),
dataIndex: '',

View File

@ -353,6 +353,16 @@ class UserEditPage extends React.Component {
}} />
</Col>
</Row>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("user:Is deleted"), i18next.t("user:Is deleted - Tooltip"))} :
</Col>
<Col span={(Setting.isMobile()) ? 22 : 2} >
<Switch checked={this.state.user.isDeleted} onChange={checked => {
this.updateUserField('isDeleted', checked);
}} />
</Col>
</Row>
</React.Fragment>
)
}

View File

@ -67,6 +67,7 @@ class UserListPage extends React.Component {
createdTime: moment().format(),
type: "normal-user",
password: "123",
passwordSalt: "",
displayName: `New User - ${randomName}`,
avatar: "https://casbin.org/img/casbin.svg",
email: "user@example.com",
@ -78,6 +79,7 @@ class UserListPage extends React.Component {
isAdmin: false,
isGlobalAdmin: false,
IsForbidden: false,
isDeleted: false,
properties: {},
}
}
@ -164,7 +166,7 @@ class UserListPage extends React.Component {
title: i18next.t("general:Created time"),
dataIndex: 'createdTime',
key: 'createdTime',
width: '180px',
width: '160px',
sorter: (a, b) => a.createdTime.localeCompare(b.createdTime),
render: (text, record, index) => {
return Setting.getFormattedDate(text);
@ -243,7 +245,7 @@ class UserListPage extends React.Component {
title: i18next.t("user:Is admin"),
dataIndex: 'isAdmin',
key: 'isAdmin',
width: '100px',
width: '110px',
sorter: (a, b) => a.isAdmin - b.isAdmin,
render: (text, record, index) => {
return (
@ -255,7 +257,7 @@ class UserListPage extends React.Component {
title: i18next.t("user:Is global admin"),
dataIndex: 'isGlobalAdmin',
key: 'isGlobalAdmin',
width: '100px',
width: '110px',
sorter: (a, b) => a.isGlobalAdmin - b.isGlobalAdmin,
render: (text, record, index) => {
return (
@ -267,7 +269,7 @@ class UserListPage extends React.Component {
title: i18next.t("user:Is forbidden"),
dataIndex: 'isForbidden',
key: 'isForbidden',
width: '100px',
width: '110px',
sorter: (a, b) => a.isForbidden - b.isForbidden,
render: (text, record, index) => {
return (
@ -275,6 +277,18 @@ class UserListPage extends React.Component {
)
}
},
{
title: i18next.t("user:Is deleted"),
dataIndex: 'isDeleted',
key: 'isDeleted',
width: '110px',
sorter: (a, b) => a.isDeleted - b.isDeleted,
render: (text, record, index) => {
return (
<Switch disabled checkedChildren="ON" unCheckedChildren="OFF" checked={text} />
)
}
},
{
title: i18next.t("general:Action"),
dataIndex: '',