From e21e79c78b4fdb1102ad726a3bf6d023143a6874 Mon Sep 17 00:00:00 2001 From: hanadi92 Date: Thu, 21 Sep 2023 20:42:55 +0300 Subject: [PATCH] Add locked users filter and lock option --- public/data/example.csv | 4 ++-- src/components/ImportFeature.js | 4 +++- src/components/users.js | 21 +++++++++++++++++++-- src/i18n/de.js | 6 ++++++ src/i18n/en.js | 5 +++++ src/synapse/dataProvider.js | 3 +++ src/synapse/dataProvider.test.js | 3 +++ 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/public/data/example.csv b/public/data/example.csv index 02933b0..f5ec04f 100644 --- a/public/data/example.csv +++ b/public/data/example.csv @@ -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 -,John Doe,,false,false,false +,John Doe,,false,false,false,false diff --git a/src/components/ImportFeature.js b/src/components/ImportFeature.js index 27bddc1..df89a8d 100644 --- a/src/components/ImportFeature.js +++ b/src/components/ImportFeature.js @@ -42,6 +42,7 @@ const optionalFields = [ "guest", "admin", "deactivated", + "locked", "avatar_url", "password", ].sort(); @@ -143,6 +144,7 @@ const FilePicker = props => { is_guest: 0, admin: 0, deactivated: 0, + locked: 0, password: 0, avatar_url: 0, id: 0, @@ -171,7 +173,7 @@ const FilePicker = props => { delete line.is_admin; } - ["is_guest", "admin", "deactivated"].forEach(f => { + ["is_guest", "admin", "deactivated", "locked"].forEach(f => { if (line[f] === "true") { stats[f]++; line[f] = true; // we need true booleans instead of strings diff --git a/src/components/users.js b/src/components/users.js index 70e60e9..b930079 100644 --- a/src/components/users.js +++ b/src/components/users.js @@ -154,6 +154,11 @@ const UserFilter = props => ( source="deactivated" alwaysOn /> + ); @@ -179,7 +184,7 @@ export const UserList = props => { } - filterDefaultValues={{ guests: true, deactivated: false }} + filterDefaultValues={{ guests: true, deactivated: false, locked: false }} sort={{ field: "name", order: "ASC" }} actions={} bulkActionButtons={} @@ -196,6 +201,7 @@ export const UserList = props => { + { + const errors = {}; + + if (values.deactivated && values.locked) { + errors.locked = "resources.users.action.update.locked_and_deactivated"; + } + + return errors; +}; + export function generateRandomUser() { const homeserver = localStorage.getItem("home_server"); const user_id = @@ -348,7 +364,7 @@ export const UserEdit = props => { const translate = useTranslate(); return ( } actions={}> - }> + } validate={validateForm}> } @@ -377,6 +393,7 @@ export const UserEdit = props => { source="deactivated" helperText="resources.users.helper.deactivate" /> + diff --git a/src/i18n/de.js b/src/i18n/de.js index 0b77fd2..ea726e2 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -108,8 +108,10 @@ const de = { is_guest: "Gast", admin: "Server Administrator", deactivated: "Deaktiviert", + locked: "Gesperrt", guests: "Zeige Gäste", show_deactivated: "Zeige deaktivierte Benutzer", + show_locked: "Zeige gesperrte Benutzer", user_id: "Suche Benutzer", displayname: "Anzeigename", password: "Passwort", @@ -132,6 +134,10 @@ const de = { }, action: { erase: "Lösche Benutzerdaten", + update: { + locked_and_deactivated: + "Ein Benutzer kann nicht deaktiviert und gesperrt werden.", + }, }, }, rooms: { diff --git a/src/i18n/en.js b/src/i18n/en.js index 6bdb033..9ae7551 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -107,8 +107,10 @@ const en = { is_guest: "Guest", admin: "Server Administrator", deactivated: "Deactivated", + locked: "locked", guests: "Show guests", show_deactivated: "Show deactivated users", + show_locked: "Show locked users", user_id: "Search user", displayname: "Displayname", password: "Password", @@ -129,6 +131,9 @@ const en = { }, action: { erase: "Erase user data", + update: { + locked_and_deactivated: "A user cannot be deactivated and locked.", + }, }, }, rooms: { diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index db57ec7..78df693 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -35,6 +35,7 @@ const resourceMap = { is_guest: !!u.is_guest, admin: !!u.admin, deactivated: !!u.deactivated, + locked: !!u.locked, // need timestamp in milliseconds creation_ts_ms: u.creation_ts * 1000, }), @@ -355,6 +356,7 @@ const dataProvider = { name, guests, deactivated, + locked, search_term, destination, valid, @@ -371,6 +373,7 @@ const dataProvider = { destination: destination, guests: guests, deactivated: deactivated, + locked: locked, valid: valid, order_by: field, dir: getSearchOrder(order), diff --git a/src/synapse/dataProvider.test.js b/src/synapse/dataProvider.test.js index a6563b7..e462bc1 100644 --- a/src/synapse/dataProvider.test.js +++ b/src/synapse/dataProvider.test.js @@ -19,6 +19,7 @@ describe("dataProvider", () => { admin: 0, user_type: null, deactivated: 0, + locked: 0, displayname: "User One", }, { @@ -28,6 +29,7 @@ describe("dataProvider", () => { admin: 1, user_type: null, deactivated: 0, + locked: 0, displayname: "User Two", }, ], @@ -66,6 +68,7 @@ describe("dataProvider", () => { avatar_url: "mxc://localhost/user1", admin: false, deactivated: false, + locked: false, }) );