From 5cee2f4c5e83f285b05fbed3b3673f8a739b2102 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 9 Jun 2021 22:37:28 -0400 Subject: [PATCH] more permissions --- migrations/2021-05-15-071534_users/up.sql | 6 ++--- .../endpoints/users/session_info.rs | 12 +++++++++ src/http_server/web_utils/session_checker.rs | 26 ++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/migrations/2021-05-15-071534_users/up.sql b/migrations/2021-05-15-071534_users/up.sql index dacf161d03..36cdc55b65 100644 --- a/migrations/2021-05-15-071534_users/up.sql +++ b/migrations/2021-05-15-071534_users/up.sql @@ -122,15 +122,15 @@ CREATE TABLE user_roles ( -- Usage can_use_tts BOOLEAN NOT NULL DEFAULT FALSE, can_use_w2l BOOLEAN NOT NULL DEFAULT FALSE, + can_delete_own_tts_results BOOLEAN NOT NULL DEFAULT FALSE, + can_delete_own_w2l_results BOOLEAN NOT NULL DEFAULT FALSE, + can_delete_own_account BOOLEAN NOT NULL DEFAULT FALSE, -- Contribution can_upload_tts_models BOOLEAN NOT NULL DEFAULT FALSE, can_upload_w2l_templates BOOLEAN NOT NULL DEFAULT FALSE, can_delete_own_tts_models BOOLEAN NOT NULL DEFAULT FALSE, - can_delete_own_tts_results BOOLEAN NOT NULL DEFAULT FALSE, can_delete_own_w2l_templates BOOLEAN NOT NULL DEFAULT FALSE, - can_delete_own_w2l_results BOOLEAN NOT NULL DEFAULT FALSE, - can_delete_own_account BOOLEAN NOT NULL DEFAULT FALSE, -- Moderation can_approve_w2l_templates BOOLEAN NOT NULL DEFAULT FALSE, diff --git a/src/http_server/endpoints/users/session_info.rs b/src/http_server/endpoints/users/session_info.rs index bd09472eb6..ae2060c9d4 100644 --- a/src/http_server/endpoints/users/session_info.rs +++ b/src/http_server/endpoints/users/session_info.rs @@ -34,6 +34,9 @@ pub struct UserInfo { // Usage permissions: pub can_use_tts: bool, pub can_use_w2l: bool, + pub can_delete_own_tts_results: bool, + pub can_delete_own_w2l_results: bool, + pub can_delete_own_account: bool, // Contribution permissions: pub can_upload_tts_models: bool, @@ -47,8 +50,11 @@ pub struct UserInfo { pub can_edit_other_users_tts_models: bool, pub can_edit_other_users_w2l_templates: bool, pub can_delete_other_users_tts_models: bool, + pub can_delete_other_users_tts_results: bool, pub can_delete_other_users_w2l_templates: bool, + pub can_delete_other_users_w2l_results: bool, pub can_ban_users: bool, + pub can_delete_users: bool, } #[derive(Serialize)] @@ -126,6 +132,9 @@ pub async fn session_info_handler( // Usage permissions: can_use_tts: session_data.can_use_tts, can_use_w2l: session_data.can_use_w2l, + can_delete_own_tts_results: session_data.can_delete_own_tts_results, + can_delete_own_w2l_results: session_data.can_delete_own_w2l_results, + can_delete_own_account: session_data.can_delete_own_account, // Contribution permissions: can_upload_tts_models: session_data.can_upload_tts_models, @@ -139,8 +148,11 @@ pub async fn session_info_handler( can_edit_other_users_tts_models: session_data.can_edit_other_users_tts_models, can_edit_other_users_w2l_templates: session_data.can_edit_other_users_w2l_templates, can_delete_other_users_tts_models: session_data.can_delete_other_users_tts_models, + can_delete_other_users_tts_results: session_data.can_delete_other_users_tts_results, can_delete_other_users_w2l_templates: session_data.can_delete_other_users_w2l_templates, + can_delete_other_users_w2l_results: session_data.can_delete_other_users_w2l_results, can_ban_users: session_data.can_ban_users, + can_delete_users: session_data.can_delete_users, }); } } diff --git a/src/http_server/web_utils/session_checker.rs b/src/http_server/web_utils/session_checker.rs index 9c52114c26..1de8b5f8ca 100644 --- a/src/http_server/web_utils/session_checker.rs +++ b/src/http_server/web_utils/session_checker.rs @@ -46,6 +46,9 @@ pub struct SessionUserRecord { // Usage pub can_use_tts: bool, pub can_use_w2l: bool, + pub can_delete_own_tts_results: bool, + pub can_delete_own_w2l_results: bool, + pub can_delete_own_account: bool, // Contribution pub can_upload_tts_models: bool, @@ -59,8 +62,11 @@ pub struct SessionUserRecord { pub can_edit_other_users_tts_models: bool, pub can_edit_other_users_w2l_templates: bool, pub can_delete_other_users_tts_models: bool, + pub can_delete_other_users_tts_results: bool, pub can_delete_other_users_w2l_templates: bool, + pub can_delete_other_users_w2l_results: bool, pub can_ban_users: bool, + pub can_delete_users: bool, } pub struct SessionUserRawDbRecord { @@ -88,6 +94,9 @@ pub struct SessionUserRawDbRecord { // Usage pub can_use_tts: Option, pub can_use_w2l: Option, + pub can_delete_own_tts_results: Option, + pub can_delete_own_w2l_results: Option, + pub can_delete_own_account: Option, // Contribution pub can_upload_tts_models: Option, @@ -101,8 +110,11 @@ pub struct SessionUserRawDbRecord { pub can_edit_other_users_tts_models: Option, pub can_edit_other_users_w2l_templates: Option, pub can_delete_other_users_tts_models: Option, + pub can_delete_other_users_tts_results: Option, pub can_delete_other_users_w2l_templates: Option, + pub can_delete_other_users_w2l_results: Option, pub can_ban_users: Option, + pub can_delete_users: Option, } impl SessionChecker { @@ -192,6 +204,9 @@ SELECT user_roles.can_use_tts, user_roles.can_use_w2l, + user_roles.can_delete_own_tts_results, + user_roles.can_delete_own_w2l_results, + user_roles.can_delete_own_account, user_roles.can_upload_tts_models, user_roles.can_upload_w2l_templates, @@ -203,8 +218,11 @@ SELECT user_roles.can_edit_other_users_tts_models, user_roles.can_edit_other_users_w2l_templates, user_roles.can_delete_other_users_tts_models, + user_roles.can_delete_other_users_tts_results, user_roles.can_delete_other_users_w2l_templates, - user_roles.can_ban_users + user_roles.can_delete_other_users_w2l_results, + user_roles.can_ban_users, + user_roles.can_delete_users FROM users LEFT OUTER JOIN user_sessions @@ -244,6 +262,9 @@ WHERE user_sessions.token = ? // Usage can_use_tts: convert_optional_db_bool_default_false(raw_user_record.can_use_tts), can_use_w2l: convert_optional_db_bool_default_false(raw_user_record.can_use_w2l), + can_delete_own_tts_results: convert_optional_db_bool_default_false(raw_user_record.can_delete_own_tts_results), + can_delete_own_w2l_results: convert_optional_db_bool_default_false(raw_user_record.can_delete_own_w2l_results), + can_delete_own_account: convert_optional_db_bool_default_false(raw_user_record.can_delete_own_account), // Contribution can_upload_tts_models: convert_optional_db_bool_default_false(raw_user_record.can_upload_tts_models), can_upload_w2l_templates: convert_optional_db_bool_default_false(raw_user_record.can_upload_w2l_templates), @@ -255,8 +276,11 @@ WHERE user_sessions.token = ? can_edit_other_users_tts_models: convert_optional_db_bool_default_false(raw_user_record.can_edit_other_users_tts_models), can_edit_other_users_w2l_templates: convert_optional_db_bool_default_false(raw_user_record.can_edit_other_users_w2l_templates), can_delete_other_users_tts_models: convert_optional_db_bool_default_false(raw_user_record.can_delete_other_users_tts_models), + can_delete_other_users_tts_results: convert_optional_db_bool_default_false(raw_user_record.can_delete_other_users_tts_results), can_delete_other_users_w2l_templates: convert_optional_db_bool_default_false(raw_user_record.can_delete_other_users_w2l_templates), + can_delete_other_users_w2l_results: convert_optional_db_bool_default_false(raw_user_record.can_delete_other_users_w2l_results), can_ban_users: convert_optional_db_bool_default_false(raw_user_record.can_ban_users), + can_delete_users: convert_optional_db_bool_default_false(raw_user_record.can_delete_users) , }; Ok(Some(result_user_record))