Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust 'this person can edit this widget' checks on My Widgets page, locks widget instances in creator. #49

Merged

Conversation

FrenjaminBanklin
Copy link
Contributor

Closes #48.

Relies on #47.

Detaches the act of locking a widget instance from clicking the 'Edit Widget' button in the My Widgets page and does it in the creator instead.

Only remaining (possible) issue: If a student tries getting clever and goes straight to the create URL of a widget instance, the checks will now prevent the creator from loading - but will still lock that instance.

Either need to consider retooling how the various methods work, or create a new endpoint that can unlock a widget instance.

Copy link
Member

@clpetersonucf clpetersonucf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@clpetersonucf clpetersonucf merged commit 8e96c09 into ucfopen:dev/1.3.0 Apr 4, 2019
Copy link
Member

@iturgeon iturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor things. Looks good though.

@@ -542,7 +556,9 @@ ${msg.toLowerCase()}`,
getQset().then(() => {
if (!$scope.invalid) {
$q(resolve => resolve(inst_id))
.then(widgetSrv.lockWidget)
.then(widgetSrv.getWidget)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should try to do lockWidget, getWidget, and checkUserPublishPerms in parallel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure - if the widget is locked then we shouldn't try to get it, and if we can't get it then we shouldn't bother checking whether the user can publish it. That, and checkUserPublishPerms relies on the full widget data being passed into it from widgetSrv.getWidget.

src/js/controllers/ctrl-selectedwidget.js Show resolved Hide resolved
deferred.resolve(id)
} else {
deferred.reject(
'This widget is currently locked, you will be able to edit this widget when it is no longer being edited by somebody else.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exact string is in ctrl-my-widgets.js. Can we de-duplicate it?


expect(Materia.Coms.Json.send).toHaveBeenCalledWith('widget_instance_lock', [1])
expect(promiseSpy).not.toHaveBeenCalled()
expect(promiseCatch).toHaveBeenCalledWith(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting approach I hadn't thought of. I think it's ok as is, however one shouldn't have to test that promiseSpy wasn't called - if promiseCatch ends up getting called promiseSpy will always be skipped.

FWIW jest has another way to test catching with expect().rejects https://jestjs.io/docs/en/tutorial-async#rejects. Though I realize this is using angular's promise lib - which may not be compatible

FrenjaminBanklin added a commit to FrenjaminBanklin/Materia-Server-Client-Assets that referenced this pull request Apr 4, 2019
@clpetersonucf clpetersonucf mentioned this pull request May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants