Skip to content

Commit

Permalink
Merge pull request #1515 from cayb0rg/issue/collaborator-support-fix
Browse files Browse the repository at this point in the history
Issue/1502
  • Loading branch information
clpetersonucf authored Oct 12, 2023
2 parents 3784675 + 3fd8e4a commit 49762ed
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
11 changes: 10 additions & 1 deletion fuel/app/classes/materia/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,11 @@ 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())
{
$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);
}
}
Expand All @@ -1078,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;
}
/**
Expand Down
5 changes: 5 additions & 0 deletions fuel/app/classes/materia/msg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/components/my-widgets-collaborate-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
11 changes: 5 additions & 6 deletions src/components/notifications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -143,11 +147,6 @@ const Notifications = (user) => {

// Close notifications
setNavOpen(false)

}
else
{
setErrorMsg('Action failed.');
}
}
})
Expand Down
4 changes: 4 additions & 0 deletions src/util/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 49762ed

Please sign in to comment.