Add locked users filter and lock option

This commit is contained in:
hanadi92 2023-09-21 20:42:55 +03:00 committed by Hanadi92
parent 12c22a170b
commit e21e79c78b
7 changed files with 41 additions and 5 deletions

View File

@ -1,3 +1,3 @@
id,displayname,password,is_guest,admin,deactivated id,displayname,password,is_guest,admin,deactivated,locked
@testuser22:example.org,Jane Doe,secretpassword,false,true,false @testuser22:example.org,Jane Doe,secretpassword,false,true,false
,John Doe,,false,false,false ,John Doe,,false,false,false,false

1 id id,displayname,password,is_guest,admin,deactivated,locked displayname password is_guest admin deactivated
2 @testuser22:example.org @testuser22:example.org,Jane Doe,secretpassword,false,true,false Jane Doe secretpassword false true false
3 ,John Doe,,false,false,false,false John Doe false false false

View File

@ -42,6 +42,7 @@ const optionalFields = [
"guest", "guest",
"admin", "admin",
"deactivated", "deactivated",
"locked",
"avatar_url", "avatar_url",
"password", "password",
].sort(); ].sort();
@ -143,6 +144,7 @@ const FilePicker = props => {
is_guest: 0, is_guest: 0,
admin: 0, admin: 0,
deactivated: 0, deactivated: 0,
locked: 0,
password: 0, password: 0,
avatar_url: 0, avatar_url: 0,
id: 0, id: 0,
@ -171,7 +173,7 @@ const FilePicker = props => {
delete line.is_admin; delete line.is_admin;
} }
["is_guest", "admin", "deactivated"].forEach(f => { ["is_guest", "admin", "deactivated", "locked"].forEach(f => {
if (line[f] === "true") { if (line[f] === "true") {
stats[f]++; stats[f]++;
line[f] = true; // we need true booleans instead of strings line[f] = true; // we need true booleans instead of strings

View File

@ -154,6 +154,11 @@ const UserFilter = props => (
source="deactivated" source="deactivated"
alwaysOn alwaysOn
/> />
<BooleanInput
label="resources.users.fields.show_locked"
source="locked"
alwaysOn
/>
</Filter> </Filter>
); );
@ -179,7 +184,7 @@ export const UserList = props => {
<List <List
{...props} {...props}
filters={<UserFilter />} filters={<UserFilter />}
filterDefaultValues={{ guests: true, deactivated: false }} filterDefaultValues={{ guests: true, deactivated: false, locked: false }}
sort={{ field: "name", order: "ASC" }} sort={{ field: "name", order: "ASC" }}
actions={<UserListActions maxResults={10000} />} actions={<UserListActions maxResults={10000} />}
bulkActionButtons={<UserBulkActionButtons />} bulkActionButtons={<UserBulkActionButtons />}
@ -196,6 +201,7 @@ export const UserList = props => {
<BooleanField source="is_guest" /> <BooleanField source="is_guest" />
<BooleanField source="admin" /> <BooleanField source="admin" />
<BooleanField source="deactivated" /> <BooleanField source="deactivated" />
<BooleanField source="locked" />
<DateField <DateField
source="creation_ts" source="creation_ts"
label="resources.users.fields.creation_ts_ms" label="resources.users.fields.creation_ts_ms"
@ -219,6 +225,16 @@ const validateUser = [
const validateAddress = [required(), maxLength(255)]; const validateAddress = [required(), maxLength(255)];
const validateForm = values => {
const errors = {};
if (values.deactivated && values.locked) {
errors.locked = "resources.users.action.update.locked_and_deactivated";
}
return errors;
};
export function generateRandomUser() { export function generateRandomUser() {
const homeserver = localStorage.getItem("home_server"); const homeserver = localStorage.getItem("home_server");
const user_id = const user_id =
@ -348,7 +364,7 @@ export const UserEdit = props => {
const translate = useTranslate(); const translate = useTranslate();
return ( return (
<Edit {...props} title={<UserTitle />} actions={<UserEditActions />}> <Edit {...props} title={<UserTitle />} actions={<UserEditActions />}>
<TabbedForm toolbar={<UserEditToolbar />}> <TabbedForm toolbar={<UserEditToolbar />} validate={validateForm}>
<FormTab <FormTab
label={translate("resources.users.name", { smart_count: 1 })} label={translate("resources.users.name", { smart_count: 1 })}
icon={<PersonPinIcon />} icon={<PersonPinIcon />}
@ -377,6 +393,7 @@ export const UserEdit = props => {
source="deactivated" source="deactivated"
helperText="resources.users.helper.deactivate" helperText="resources.users.helper.deactivate"
/> />
<BooleanInput source="locked" />
<DateField source="creation_ts_ms" showTime options={date_format} /> <DateField source="creation_ts_ms" showTime options={date_format} />
<TextField source="consent_version" /> <TextField source="consent_version" />
</FormTab> </FormTab>

View File

@ -108,8 +108,10 @@ const de = {
is_guest: "Gast", is_guest: "Gast",
admin: "Server Administrator", admin: "Server Administrator",
deactivated: "Deaktiviert", deactivated: "Deaktiviert",
locked: "Gesperrt",
guests: "Zeige Gäste", guests: "Zeige Gäste",
show_deactivated: "Zeige deaktivierte Benutzer", show_deactivated: "Zeige deaktivierte Benutzer",
show_locked: "Zeige gesperrte Benutzer",
user_id: "Suche Benutzer", user_id: "Suche Benutzer",
displayname: "Anzeigename", displayname: "Anzeigename",
password: "Passwort", password: "Passwort",
@ -132,6 +134,10 @@ const de = {
}, },
action: { action: {
erase: "Lösche Benutzerdaten", erase: "Lösche Benutzerdaten",
update: {
locked_and_deactivated:
"Ein Benutzer kann nicht deaktiviert und gesperrt werden.",
},
}, },
}, },
rooms: { rooms: {

View File

@ -107,8 +107,10 @@ const en = {
is_guest: "Guest", is_guest: "Guest",
admin: "Server Administrator", admin: "Server Administrator",
deactivated: "Deactivated", deactivated: "Deactivated",
locked: "locked",
guests: "Show guests", guests: "Show guests",
show_deactivated: "Show deactivated users", show_deactivated: "Show deactivated users",
show_locked: "Show locked users",
user_id: "Search user", user_id: "Search user",
displayname: "Displayname", displayname: "Displayname",
password: "Password", password: "Password",
@ -129,6 +131,9 @@ const en = {
}, },
action: { action: {
erase: "Erase user data", erase: "Erase user data",
update: {
locked_and_deactivated: "A user cannot be deactivated and locked.",
},
}, },
}, },
rooms: { rooms: {

View File

@ -35,6 +35,7 @@ const resourceMap = {
is_guest: !!u.is_guest, is_guest: !!u.is_guest,
admin: !!u.admin, admin: !!u.admin,
deactivated: !!u.deactivated, deactivated: !!u.deactivated,
locked: !!u.locked,
// need timestamp in milliseconds // need timestamp in milliseconds
creation_ts_ms: u.creation_ts * 1000, creation_ts_ms: u.creation_ts * 1000,
}), }),
@ -355,6 +356,7 @@ const dataProvider = {
name, name,
guests, guests,
deactivated, deactivated,
locked,
search_term, search_term,
destination, destination,
valid, valid,
@ -371,6 +373,7 @@ const dataProvider = {
destination: destination, destination: destination,
guests: guests, guests: guests,
deactivated: deactivated, deactivated: deactivated,
locked: locked,
valid: valid, valid: valid,
order_by: field, order_by: field,
dir: getSearchOrder(order), dir: getSearchOrder(order),

View File

@ -19,6 +19,7 @@ describe("dataProvider", () => {
admin: 0, admin: 0,
user_type: null, user_type: null,
deactivated: 0, deactivated: 0,
locked: 0,
displayname: "User One", displayname: "User One",
}, },
{ {
@ -28,6 +29,7 @@ describe("dataProvider", () => {
admin: 1, admin: 1,
user_type: null, user_type: null,
deactivated: 0, deactivated: 0,
locked: 0,
displayname: "User Two", displayname: "User Two",
}, },
], ],
@ -66,6 +68,7 @@ describe("dataProvider", () => {
avatar_url: "mxc://localhost/user1", avatar_url: "mxc://localhost/user1",
admin: false, admin: false,
deactivated: false, deactivated: false,
locked: false,
}) })
); );