mirror of
https://github.com/documize/community.git
synced 2025-07-25 08:09:43 +02:00
refined category permission checks
This commit is contained in:
parent
4d989e2497
commit
3a9675eb14
11 changed files with 149 additions and 22 deletions
|
@ -44,6 +44,20 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, DropdownMixin
|
|||
this.get('categoryService').getAll(this.get('folder.id')).then((c) => {
|
||||
this.set('category', c);
|
||||
|
||||
// get summary of documents and users for each category in space
|
||||
this.get('categoryService').getSummary(this.get('folder.id')).then((s) => {
|
||||
c.forEach((cat) => {
|
||||
let docs = _.findWhere(s, {categoryId: cat.get('id'), type: 'documents'});
|
||||
let docCount = is.not.undefined(docs) ? docs.count : 0;
|
||||
|
||||
let users = _.findWhere(s, {categoryId: cat.get('id'), type: 'users'});
|
||||
let userCount = is.not.undefined(users) ? users.count : 0;
|
||||
|
||||
cat.set('documents', docCount);
|
||||
cat.set('users', userCount);
|
||||
});
|
||||
});
|
||||
|
||||
// get users that this space admin user can see
|
||||
this.get('userService').getAll().then((users) => {
|
||||
// set up Everyone user
|
||||
|
@ -132,12 +146,12 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, DropdownMixin
|
|||
let users = this.get('users');
|
||||
let category = this.get('category').findBy('id', catId);
|
||||
|
||||
this.get('categoryService').getViewers(category.get('id')).then((viewers) => {
|
||||
this.get('categoryService').getPermissions(category.get('id')).then((viewers) => {
|
||||
// mark those users as selected that have already been given permission
|
||||
// to see the current category;
|
||||
|
||||
users.forEach((user) => {
|
||||
let selected = viewers.isAny('id', user.get('id'));
|
||||
let userId = user.get('id') === '0' ? '' : user.get('id');
|
||||
let selected = viewers.isAny('whoId', userId);
|
||||
user.set('selected', selected);
|
||||
});
|
||||
|
||||
|
@ -173,17 +187,22 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, DropdownMixin
|
|||
let viewers = [];
|
||||
|
||||
users.forEach((user) => {
|
||||
let userId = user.get('id');
|
||||
if (userId === "0") userId = '';
|
||||
|
||||
let v = {
|
||||
orgId: this.get('folder.orgId'),
|
||||
folderId: this.get('folder.id'),
|
||||
categoryId: category.get('id'),
|
||||
userId: user.get('id')
|
||||
userId: userId
|
||||
};
|
||||
|
||||
viewers.push(v);
|
||||
});
|
||||
|
||||
this.get('categoryService').setViewers(category.get('id'), viewers).then( () => {});
|
||||
this.get('categoryService').setViewers(category.get('id'), viewers).then(() => {
|
||||
this.load();
|
||||
});
|
||||
|
||||
this.closeDropdown();
|
||||
}
|
||||
|
|
|
@ -17,5 +17,9 @@ export default Model.extend({
|
|||
folderId: attr('string'),
|
||||
category: attr('string'),
|
||||
created: attr(),
|
||||
revised: attr()
|
||||
revised: attr(),
|
||||
|
||||
// fields used by UI only
|
||||
documents: attr(),
|
||||
users: attr(),
|
||||
});
|
||||
|
|
|
@ -85,10 +85,19 @@ export default BaseService.extend({
|
|||
});
|
||||
},
|
||||
|
||||
// Get list of users who can see given category
|
||||
getViewers(categoryId) {
|
||||
// Get viewer permission records for given category
|
||||
getPermissions(categoryId) {
|
||||
return this.get('ajax').request(`category/${categoryId}/permission`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
return response;
|
||||
});
|
||||
},
|
||||
|
||||
// Get list of users who can see given category
|
||||
getUsers(categoryId) {
|
||||
return this.get('ajax').request(`category/${categoryId}/user`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
|
||||
|
@ -109,4 +118,13 @@ export default BaseService.extend({
|
|||
data: JSON.stringify(viewers)
|
||||
});
|
||||
},
|
||||
|
||||
// Get count of documents and users associated with each category in given space.
|
||||
getSummary(spaceId) {
|
||||
return this.get('ajax').request(`category/space/${spaceId}/summary`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
return response;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
{{else}}
|
||||
<div class="category">
|
||||
<div class="name">{{cat.category}}</div>
|
||||
<div class="info">7 documents, 14 people</div>
|
||||
<div class="info">{{cat.documents}} documents, {{cat.users}} people</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="pull-right buttons">
|
||||
|
@ -66,12 +66,8 @@
|
|||
{{ui/ui-list-picker items=categoryUsers nameField='fullname'}}
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="flat-button" {{action 'onGrantCancel'}}>
|
||||
cancel
|
||||
</div>
|
||||
<div class="flat-button flat-blue" {{action 'onGrantAccess'}}>
|
||||
grant access
|
||||
</div>
|
||||
<div class="flat-button" {{action 'onGrantCancel'}}>cancel</div>
|
||||
<div class="flat-button flat-blue" {{action 'onGrantAccess'}}>grant access</div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue