0013352: add pin protection to folders
[tine20] / tine20 / Filemanager / js / GrantsPanel.js
1 /*
2  * Tine 2.0
3  *
4  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
5  * @author      Cornelius WeiƟ <c.weiss@metaways.de>
6  * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
7  */
8 Ext.ns('Tine.Filemanager');
9
10 Tine.Filemanager.GrantsPanel = Ext.extend(Ext.Panel, {
11
12     /**
13      * @cfg {Tine.widgets.dialog.EditDialog}
14      */
15     editDialog: null,
16
17     /**
18      * @cfg {Tine.Tinebase.Application} app
19      */
20     app: null,
21
22     /**
23      * @property {Tine.Filemanager.Model.Node} recordClass
24      */
25     recordClass: Tine.Filemanager.Model.Node,
26
27     requiredGrant: 'editGrant',
28     layout: 'fit',
29     border: false,
30
31     initComponent: function() {
32         this.app = this.app || Tine.Tinebase.appMgr.get('Filemanager');
33         this.title = this.title || this.app.i18n._('Grants');
34
35         this.editDialog.on('load', this.onRecordLoad, this);
36         this.editDialog.on('recordUpdate', this.onRecordUpdate, this);
37
38         this.hasOwnGrantsCheckbox = new Ext.form.Checkbox({
39             disabled: true,
40             boxLabel: this.app.i18n._('This folder has own grants'),
41             listeners: {scope: this, check: this.onOwnGrantsCheck}
42         });
43         this.hasOwnRightsDescription = new Ext.form.Label({
44             text: this.app.i18n._("Grants of a folder also apply recursively for all of its sub folders as long they don't have own grants itself.")
45         });
46         this.pinProtectionCheckbox = new Ext.form.Checkbox({
47             disabled: true,
48             boxLabel: this.app.i18n._('This folder is pin protected')
49             // TODO needed?
50             //listeners: {scope: this, check: this.onPinProtectionCheck}
51         });
52         this.pinProtectionDescription = new Ext.form.Label({
53             text: this.app.i18n._("If pin protection is enabled, users have to authenticate with their pin before they can access the folder contents.")
54         });
55         this.grantsGrid = new Tine.widgets.container.GrantsGrid({
56             downloadGrantTitle: 'Download', // i18n._('Download')
57             downloadGrantDescription: 'The grant to download files', // i18n._('The grant to download files')
58             publishGrantTitle: 'Publish', // i18n._('Publish')
59             publishGrantDescription: 'The grant to create anonymous download links for files', // i18n._('The grant to create anonymous download links for files')
60             grantContainer: 'Filemanager_Model_Node',
61             alwaysShowAdminGrant: true,
62             store: new Ext.data.JsonStore({
63                 fields: Tine.Tinebase.Model.Grant,
64                 root: 'grants'
65             }),
66             readOnly: true,
67             flex: 1
68         });
69
70         this.items = [{
71             layout: 'vbox',
72             align: 'stretch',
73             pack: 'start',
74             border: false,
75             items: [{
76                 layout: 'form',
77                 frame: true,
78                 hideLabels: true,
79                 width: '100%',
80                 items: [
81                     this.hasOwnGrantsCheckbox,
82                     this.hasOwnRightsDescription,
83                     this.pinProtectionCheckbox,
84                     this.pinProtectionDescription
85                 ]},
86                 this.grantsGrid
87             ]
88         }];
89
90         this.supr().initComponent.call(this);
91     },
92
93     onOwnGrantsCheck: function(cb, checked) {
94         this.grantsGrid.setReadOnly(!checked);
95         this.pinProtectionCheckbox.setDisabled(!checked);
96     },
97
98     onRecordLoad: function(editDialog, record, ticketFn) {
99         var _ = window.lodash,
100             evalGrants = editDialog.evalGrants,
101             hasRequiredGrant = !evalGrants || _.get(record, record.constructor.getMeta('grantsPath') + '.' + this.requiredGrant);
102
103         this.hasOwnGrantsCheckbox.setDisabled(! lodash.get(record, 'data.account_grants.adminGrant', false)
104             || record.get('type') != 'folder');
105         this.hasOwnGrantsCheckbox.setValue(record.get('acl_node') == record.id);
106         this.pinProtectionCheckbox.setValue(record.get('pin_protected'));
107
108         this.grantsGrid.useGrant('admin', !!String(record.get('path')).match(/^\/shared/));
109         this.grantsGrid.getStore().loadData(record.data);
110
111         this.setReadOnly(! hasRequiredGrant);
112     },
113
114     setReadOnly: function(readOnly) {
115         this.readOnly = readOnly;
116         this.grantsGrid.setReadOnly(readOnly);
117         this.hasOwnGrantsCheckbox.setDisabled(readOnly);
118     },
119
120     onRecordUpdate: function(editDialog, record) {
121         var acl_node = this.hasOwnGrantsCheckbox.getValue() ? record.id : '',
122             grants = [],
123             pin_protected = this.pinProtectionCheckbox.getValue() ? true : false;
124
125         this.grantsGrid.getStore().each(function(r) {grants.push(r.data)});
126
127         record.set('acl_node', acl_node);
128         record.set('grants', '');
129         record.set('grants', grants);
130         record.set('pin_protected', pin_protected);
131     }
132 });