From e679de8893ef219d8084abe8c81e599a788a26a7 Mon Sep 17 00:00:00 2001 From: Cay Henning Date: Thu, 5 Oct 2023 15:42:21 -0400 Subject: [PATCH 1/3] Adds warning when trying to add a student collaborator to non-guest widget --- fuel/app/classes/materia/api/v1.php | 4 +++- fuel/app/classes/materia/msg.php | 5 +++++ src/components/my-widgets-collaborate-dialog.jsx | 11 +++++++++-- src/components/notifications.jsx | 11 +++++------ src/util/api.js | 4 ++++ 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/fuel/app/classes/materia/api/v1.php b/fuel/app/classes/materia/api/v1.php index b173b7be3..7c7ccc351 100644 --- a/fuel/app/classes/materia/api/v1.php +++ b/fuel/app/classes/materia/api/v1.php @@ -1058,7 +1058,9 @@ static public function permissions_set($item_type, $item_id, $perms_array) if ($is_enabled && Perm_Manager::is_student($new_perms->user_id)) { // guest mode isn't enabled - don't give this student access - if ( ! $inst->allows_guest_players()) continue; + if ( ! $inst->allows_guest_players()) { + return Msg::student_collab(); + } Perm_Manager::set_user_game_asset_perms($item_id, $new_perms->user_id, [Perm::VISIBLE => $is_enabled], $new_perms->expiration); } } diff --git a/fuel/app/classes/materia/msg.php b/fuel/app/classes/materia/msg.php index ede1cf363..2ef6a4a54 100644 --- a/fuel/app/classes/materia/msg.php +++ b/fuel/app/classes/materia/msg.php @@ -60,6 +60,11 @@ static public function no_perm() return new Msg('You do not have permission to access the requested content', 'Permission Denied', Msg::WARN); } + static public function student_collab() + { + return new Msg('Students cannot be added as collaborators to widgets that have guest access disabled.', 'Share Not Allowed', Msg::ERROR); + } + static public function student() { return new Msg('Students are unable to receive notifications via Materia', 'No Notifications', Msg::NOTICE); diff --git a/src/components/my-widgets-collaborate-dialog.jsx b/src/components/my-widgets-collaborate-dialog.jsx index ea0c0d28d..02115a08c 100644 --- a/src/components/my-widgets-collaborate-dialog.jsx +++ b/src/components/my-widgets-collaborate-dialog.jsx @@ -167,8 +167,15 @@ const MyWidgetsCollaborateDialog = ({onClose, inst, myPerms, otherUserPerms, set setUserPerms.mutate({ instId: inst.id, permsObj: permsObj, - successFunc: () => { - if (mounted.current) { + successFunc: (data) => { + if (data && data.type == 'error') + { + if (data.title == "Share Not Allowed") + { + setState({...state, shareNotAllowed: true}) + } + } + else if (mounted.current) { if (delCurrUser) { queryClient.invalidateQueries('widgets') } diff --git a/src/components/notifications.jsx b/src/components/notifications.jsx index 1357abe8f..a09cd2b83 100644 --- a/src/components/notifications.jsx +++ b/src/components/notifications.jsx @@ -121,7 +121,11 @@ const Notifications = (user) => { instId: notif.item_id, permsObj: userPerms, successFunc: (data) => { - if (data.status == 200) + if (!data || data.title == "error") + { + setErrorMsg('Action failed.'); + } + else if (data) { // Redirect to widget if (!window.location.pathname.includes('my-widgets')) @@ -143,11 +147,6 @@ const Notifications = (user) => { // Close notifications setNavOpen(false) - - } - else - { - setErrorMsg('Action failed.'); } } }) diff --git a/src/util/api.js b/src/util/api.js index 1008d1b4d..91231e41f 100644 --- a/src/util/api.js +++ b/src/util/api.js @@ -337,6 +337,10 @@ export const apiGetUserPermsForInstance = instId => { export const apiSetUserInstancePerms = ({ instId, permsObj }) => { return fetch('/api/json/permissions_set', fetchOptions({ body: `data=${formatFetchBody([objectTypes.WIDGET_INSTANCE, instId, permsObj])}` })) + .then(resp => { + if (resp.status === 204 || resp.status === 502) return null + return resp.json() + }) } export const apiCanEditWidgets = arrayOfWidgetIds => { From 1b8e0575cf6c7218bf08b9c5f4186d9d0b3f36d5 Mon Sep 17 00:00:00 2001 From: Cay Henning Date: Thu, 5 Oct 2023 15:53:48 -0400 Subject: [PATCH 2/3] PHP syntax error fix --- fuel/app/classes/materia/api/v1.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fuel/app/classes/materia/api/v1.php b/fuel/app/classes/materia/api/v1.php index 7c7ccc351..48278c7ca 100644 --- a/fuel/app/classes/materia/api/v1.php +++ b/fuel/app/classes/materia/api/v1.php @@ -1058,7 +1058,8 @@ static public function permissions_set($item_type, $item_id, $perms_array) if ($is_enabled && Perm_Manager::is_student($new_perms->user_id)) { // guest mode isn't enabled - don't give this student access - if ( ! $inst->allows_guest_players()) { + if ( ! $inst->allows_guest_players()) + { return Msg::student_collab(); } Perm_Manager::set_user_game_asset_perms($item_id, $new_perms->user_id, [Perm::VISIBLE => $is_enabled], $new_perms->expiration); From 3fd8e4ac9b48b47cceaca80b38ef9a4048b17211 Mon Sep 17 00:00:00 2001 From: Cay Henning Date: Tue, 10 Oct 2023 16:39:29 -0400 Subject: [PATCH 3/3] Continues instead of returning when attempting to add student --- fuel/app/classes/materia/api/v1.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fuel/app/classes/materia/api/v1.php b/fuel/app/classes/materia/api/v1.php index 48278c7ca..509e66ab8 100644 --- a/fuel/app/classes/materia/api/v1.php +++ b/fuel/app/classes/materia/api/v1.php @@ -1060,7 +1060,8 @@ static public function permissions_set($item_type, $item_id, $perms_array) // guest mode isn't enabled - don't give this student access if ( ! $inst->allows_guest_players()) { - return Msg::student_collab(); + $refused[] = $new_perms->user_id; + continue; } Perm_Manager::set_user_game_asset_perms($item_id, $new_perms->user_id, [Perm::VISIBLE => $is_enabled], $new_perms->expiration); } @@ -1081,6 +1082,11 @@ static public function permissions_set($item_type, $item_id, $perms_array) \Model_Notification::send_item_notification($cur_user_id, $new_perms->user_id, $item_type, $item_id, $notification_mode, $new_perm); } + if (count($refused) > 0) + { + return Msg::student_collab(); + } + return true; } /**