-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add annotation access controls at the folder level #905
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ac8f7ee
Add annotation access controls at the folder level
eagw e3d7e98
Add missing newline
eagw f6dcd6c
Fix linting issues
eagw 06302c7
Replace `yield` with `return`
eagw d350560
Add hierarchy widget to index to import it
eagw 0e1adec
Add count method for girder count header
eagw 335a5d5
Merge master into folder-access-control to fix CI
eagw dd6f410
Make endpoint to set access list for folder annots
eagw b231867
Fix lint error
eagw 329af9f
Improve endpoint user expectations
eagw ed036e9
Fix lint
eagw cbed60e
Remove extra line
eagw b832046
Fix issue from lint fix
eagw 6ee1943
Fix duplicate annotation returns from pipeline
eagw 666ee38
Add time limit and count to update access endpoint
eagw 7b3786f
Remove default value from `setAccessList` call
eagw 62a6b50
Remove unnecessary `HierarchyWidget` wrapper
eagw 5337f0a
Fix HTML inconsistency
eagw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
girder_annotation/girder_large_image_annotation/web_client/views/hierarchyWidget.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import $ from 'jquery'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to add the HierarchyWidget to the views/index.js file to get it imported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See d350560 |
||
|
||
import { wrap } from '@girder/core/utilities/PluginUtils'; | ||
import { restRequest } from '@girder/core/rest'; | ||
import AccessWidget from '@girder/core/views/widgets/AccessWidget'; | ||
import HierarchyWidget from '@girder/core/views/widgets/HierarchyWidget'; | ||
|
||
import AnnotationModel from '../models/AnnotationModel'; | ||
|
||
wrap(HierarchyWidget, 'render', function (render) { | ||
render.call(this); | ||
|
||
if (this.parentModel.get('_modelType') === 'folder') { | ||
ownAnnotation(this, this.parentModel.id); | ||
} | ||
}); | ||
|
||
function ownAnnotation(root, folderId) { | ||
restRequest({ | ||
type: 'GET', | ||
url: 'annotation/folder/' + folderId + '/present', | ||
data: { | ||
recurse: true | ||
} | ||
}).done((ownsAnnot) => { | ||
if (ownsAnnot) { | ||
addAccessControl(root); | ||
} | ||
}); | ||
} | ||
|
||
function addAccessControl(root) { | ||
if (root.$('.g-edit-annotation-access').length === 0) { | ||
if (root.$('.g-folder-actions-menu > .divider').length > 0) { | ||
root.$('.g-folder-actions-menu > .divider').before( | ||
'<li role="presentation">' + | ||
'<a class="g-edit-annotation-access" role="menuitem">' + | ||
'<i class="icon-lock"></i>' + | ||
'Annotation access control' + | ||
'</a>' + | ||
'</li>' | ||
); | ||
} else { | ||
root.$('ul.g-folder-actions-menu').append( | ||
'<li role="presentation">' + | ||
'<a class="g-edit-annotation-access" role="menuitem">' + | ||
'<i class="icon-lock"></i>' + | ||
'Annotation access control' + | ||
'</a>' + | ||
'</li>' | ||
); | ||
} | ||
root.events['click .g-edit-annotation-access'] = editAnnotAccess; | ||
root.delegateEvents(); | ||
} | ||
} | ||
|
||
function editAnnotAccess() { | ||
restRequest({ | ||
type: 'GET', | ||
url: 'annotation/folder/' + this.parentModel.get('_id'), | ||
data: { | ||
recurse: true, | ||
limit: 1 | ||
} | ||
}).done((resp) => { | ||
const model = new AnnotationModel(resp[0]); | ||
model.get('annotation').name = 'Your Annotations'; | ||
model.save = () => {}; | ||
model.updateAccess = (settings) => { | ||
const access = { | ||
access: model.get('access'), | ||
public: model.get('public'), | ||
publicFlags: model.get('publicFlags') | ||
}; | ||
const defaultUpdateModel = new AnnotationModel(); | ||
defaultUpdateModel.id = this.parentModel.get('_id'); | ||
defaultUpdateModel.altUrl = 'annotation/folder'; | ||
defaultUpdateModel.set(access); | ||
defaultUpdateModel.updateAccess(settings); | ||
model.trigger('g:accessListSaved'); | ||
}; | ||
model.fetchAccess(true) | ||
.done(() => { | ||
new AccessWidget({// eslint-disable-line no-new | ||
el: $('#g-dialog-container'), | ||
modelType: 'annotation', | ||
model, | ||
hideRecurseOption: false, | ||
parentView: this | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
export default HierarchyWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you choose to have recurse default to false for this endpoint (and true on the present endpoint)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was that when you think of an endpoint that gets annotations from a folder someone is more likely to assume that it's just returning the annotations from that folder and not all other folders it contains as well. Whereas with the present endpoint I thought they'd be more likely to use it when trying to determine if a user owns any annotations in the folder or its subfolders. But I realize this logic isn't very intuitive, so I could change it so they're both the same.