Skip to content

Commit

Permalink
[fix] fixes incorrect copy and delete mywidget states
Browse files Browse the repository at this point in the history
My widgets page will show admin users greyed out copy
and delete buttons, however they still function.  The
problem is the client doesn't seem to understand su
roles, and all the logic does not include that as
and option.

This adds a more nuanced permission set on the selected
widget under $scope.slected.can with a key for each of
the permission types. Where possible, those have been
used, but theres some strangeness going on thats
difficult to follow/tanslate to can permissions.
I left those in place.

fixes #1296
  • Loading branch information
iturgeon committed Jul 4, 2020
1 parent cd0f019 commit 988fa61
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/css/partials/_widget_share_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
text-decoration: none;
font-size: 15px;
position: absolute;
left: 5px;
left: -30px;
top: 30px;
}
.name {
Expand Down
5 changes: 2 additions & 3 deletions src/js/controllers/ctrl-my-widgets-collaboration.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ app.controller('MyWidgetsCollaborationController', function (
$scope.inputs.userSearchInput = ''

if ($scope.selected.widget.guest_access === false && user.is_student) {
$scope.alert.msg =
'Students can not be given access to this widget unless Guest Mode is enabled!'
$scope.alert.title = 'Unable to share with student'
$scope.alert.msg = 'Access must be set to "Guest Mode" to collaborate with students.'
$scope.alert.title = 'Share Not Allowed'
$scope.alert.fatal = false
return
}
Expand Down
12 changes: 2 additions & 10 deletions src/js/controllers/ctrl-my-widgets-selected.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,14 @@ app.controller('MyWidgetsSelectedController', function (
$scope.show.olderScores = true
}

const _canCopy = () =>
[ACCESS.COPY, ACCESS.FULL, ACCESS.SHARE, ACCESS.SU].includes($scope.selected.accessLevel)
const _canDelete = () => [ACCESS.FULL, ACCESS.SU].includes($scope.selected.accessLevel)
const _canShare = () =>
[ACCESS.SHARE, ACCESS.FULL, ACCESS.SU].includes($scope.selected.accessLevel)
const _canView = () =>
[ACCESS.VISIBLE, ACCESS.SHARE, ACCESS.FULL, ACCESS.SU].includes($scope.selected.accessLevel)

const _showCopyDialog = () => {
if (_canCopy()) {
if ($scope.selected.can.copy) {
$scope.show.copyModal = true
}
}

const _showDelete = () => {
if (_canDelete()) {
if ($scope.selected.can.delete) {
$scope.show.deleteDialog = !$scope.show.deleteDialog
}
}
Expand Down
37 changes: 21 additions & 16 deletions src/js/controllers/ctrl-my-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,36 @@ app.controller('MyWidgetsController', function (
// Second half of populateDisplay
// This allows us to update the display before the callback of scores finishes, which speeds up UI
const populateAccess = () => {
// accessLevel == ACCESS.VISIBLE is effectively read-only
if (
($scope.perms.user[$scope.user.id] != null
? $scope.perms.user[$scope.user.id][0]
: undefined) != null
) {
$scope.selected.accessLevel = Number($scope.perms.user[$scope.user.id][0])
const sel = $scope.selected
const perms = $scope.perms
const userId = $scope.user.id
const perm = (perms.user[userId] && perms.user[userId][0]) || ACCESS.VISIBLE
sel.accessLevel = parseInt(perm, 10)
sel.can = {
view: [ACCESS.VISIBLE, ACCESS.COPY, ACCESS.SHARE, ACCESS.FULL, ACCESS.SU].includes(
sel.accessLevel
),
copy: [ACCESS.COPY, ACCESS.SHARE, ACCESS.FULL, ACCESS.SU].includes(sel.accessLevel),
edit: [ACCESS.FULL, ACCESS.SU].includes(sel.accessLevel),
delete: [ACCESS.FULL, ACCESS.SU].includes(sel.accessLevel),
share: [ACCESS.SHARE, ACCESS.FULL, ACCESS.SU].includes(sel.accessLevel),
}

$scope.selected.editable =
$scope.selected.accessLevel > ACCESS.VISIBLE &&
parseInt($scope.selected.widget.widget.is_editable) === 1
sel.editable =
$scope.selected.accessLevel > ACCESS.VISIBLE && parseInt(sel.widget.widget.is_editable) === 1

if ($scope.selected.editable) {
$scope.selected.edit = `/widgets/${$scope.selected.widget.widget.dir}create\#${$scope.selected.widget.id}`
if (sel.editable) {
sel.edit = `/widgets/${sel.widget.widget.dir}create\#${sel.widget.id}`
} else {
$scope.selected.edit = '#'
sel.edit = '#'
}

_countCollaborators()

$scope.selected.shareable = $scope.selected.accessLevel !== ACCESS.VISIBLE
sel.shareable = sel.accessLevel !== ACCESS.VISIBLE // old, but difficult to replace with sel.can.share :/

populateAvailability($scope.selected.widget.open_at, $scope.selected.widget.close_at)
populateAttempts($scope.selected.widget.attempts)
populateAvailability(sel.widget.open_at, sel.widget.close_at)
populateAttempts(sel.widget.attempts)
}

// count up the number of other users collaborating
Expand Down

0 comments on commit 988fa61

Please sign in to comment.