Use IMAP permissions to control allowed interactions on the client (#4829)

This commit is contained in:
Thomas Bruederli 2015-03-11 17:17:11 +01:00
parent 8792a668b6
commit 54b47dc753
3 changed files with 48 additions and 15 deletions

View file

@ -226,6 +226,7 @@ class kolab_notes extends rcube_plugin
'title' => $folder->get_title(), 'title' => $folder->get_title(),
'virtual' => true, 'virtual' => true,
'editable' => false, 'editable' => false,
'rights' => 'l',
'group' => 'other virtual', 'group' => 'other virtual',
'class' => 'user', 'class' => 'user',
'parent' => $parent_id, 'parent' => $parent_id,
@ -238,6 +239,7 @@ class kolab_notes extends rcube_plugin
'listname' => $listname, 'listname' => $listname,
'virtual' => true, 'virtual' => true,
'editable' => false, 'editable' => false,
'rights' => 'l',
'group' => $folder->get_namespace(), 'group' => $folder->get_namespace(),
'parent' => $parent_id, 'parent' => $parent_id,
); );
@ -318,15 +320,18 @@ class kolab_notes extends rcube_plugin
{ {
if ($folder->get_namespace() == 'personal') { if ($folder->get_namespace() == 'personal') {
$norename = false; $norename = false;
$readonly = false; $editable = true;
$rights = 'lrswikxtea';
$alarms = true; $alarms = true;
} }
else { else {
$alarms = false; $alarms = false;
$readonly = true; $rights = 'lr';
if (($rights = $folder->get_myrights()) && !PEAR::isError($rights)) { $editable = false;
if (strpos($rights, 'i') !== false) if (($myrights = $folder->get_myrights()) && !PEAR::isError($myrights)) {
$readonly = false; $rights = $myrights;
if (strpos($rights, 't') !== false || strpos($rights, 'd') !== false)
$editable = strpos($rights, 'i');
} }
$info = $folder->get_folder_info(); $info = $folder->get_folder_info();
$norename = $readonly || $info['norename'] || $info['protected']; $norename = $readonly || $info['norename'] || $info['protected'];
@ -338,7 +343,8 @@ class kolab_notes extends rcube_plugin
'name' => $folder->get_name(), 'name' => $folder->get_name(),
'listname' => $folder->get_foldername(), 'listname' => $folder->get_foldername(),
'editname' => $folder->get_foldername(), 'editname' => $folder->get_foldername(),
'editable' => !$readonly, 'editable' => $editable,
'rights' => $rights,
'norename' => $norename, 'norename' => $norename,
'parentfolder' => $folder->get_parent(), 'parentfolder' => $folder->get_parent(),
'subscribed' => (bool)$folder->is_subscribed(), 'subscribed' => (bool)$folder->is_subscribed(),

View file

@ -131,7 +131,7 @@ class kolab_notes_ui
} }
if ($attrib['type'] == 'select') { if ($attrib['type'] == 'select') {
if ($prop['editable']) { if ($prop['editable'] || strpos($prop['rights'], 'i') !== false) {
$select->add($prop['name'], $prop['id']); $select->add($prop['name'], $prop['id']);
} }
} }

View file

@ -113,7 +113,9 @@ function rcube_kolab_notes_ui(settings)
var id = node.id; var id = node.id;
if (me.notebooks[id] && id != me.selected_list) { if (me.notebooks[id] && id != me.selected_list) {
warn_unsaved_changes(function(){ warn_unsaved_changes(function(){
rcmail.enable_command('createnote', 'list-edit', 'list-delete', me.notebooks[id].editable); rcmail.enable_command('createnote', has_permission(me.notebooks[id], 'i'));
rcmail.enable_command('list-edit', has_permission(me.notebooks[id], 'a'));
rcmail.enable_command('list-delete', has_permission(me.notebooks[id], 'xa'));
rcmail.enable_command('list-remove', !me.notebooks[id].default); rcmail.enable_command('list-remove', !me.notebooks[id].default);
fetch_notes(id); // sets me.selected_list fetch_notes(id); // sets me.selected_list
}, },
@ -122,6 +124,9 @@ function rcube_kolab_notes_ui(settings)
notebookslist.select(me.selected_list); notebookslist.select(me.selected_list);
}); });
} }
// unfocus clicked list item
$(notebookslist.get_item(id)).find('a.listname').first().blur();
}); });
notebookslist.addEventListener('subscribe', function(p) { notebookslist.addEventListener('subscribe', function(p) {
var list; var list;
@ -164,7 +169,7 @@ function rcube_kolab_notes_ui(settings)
// register dbl-click handler to open list edit dialog // register dbl-click handler to open list edit dialog
$(rcmail.gui_objects.notebooks).on('dblclick', 'li:not(.virtual) a', function(e) { $(rcmail.gui_objects.notebooks).on('dblclick', 'li:not(.virtual) a', function(e) {
var id = String($(this).closest('li').attr('id')).replace(/^rcmliknb/, ''); var id = String($(this).closest('li').attr('id')).replace(/^rcmliknb/, '');
if (me.notebooks[id] && me.notebooks[id].editable) { if (me.notebooks[id] && has_permission(me.notebooks[id], 'a')) {
list_edit_dialog(id); list_edit_dialog(id);
} }
@ -202,7 +207,7 @@ function rcube_kolab_notes_ui(settings)
list.select(me.selected_note.id); list.select(me.selected_note.id);
}); });
rcmail.enable_command('delete', me.notebooks[me.selected_list] && me.notebooks[me.selected_list].editable && list.selection.length > 0); rcmail.enable_command('delete', me.notebooks[me.selected_list] && has_permission(me.notebooks[me.selected_list], 'td') && list.selection.length > 0);
rcmail.enable_command('sendnote', list.selection.length > 0); rcmail.enable_command('sendnote', list.selection.length > 0);
rcmail.enable_command('print', list.selection.length == 1); rcmail.enable_command('print', list.selection.length == 1);
}) })
@ -430,6 +435,27 @@ function rcube_kolab_notes_ui(settings)
return String(str).replace(/\s+$/, '').replace(/^\s+/, ''); return String(str).replace(/\s+$/, '').replace(/^\s+/, '');
} }
/**
* Check permissions on the given list object
*/
function has_permission(list, perm)
{
// multiple chars means "either of"
if (String(perm).length > 1) {
for (var i=0; i < perm.length; i++) {
if (has_permission(list, perm[i])) {
return true;
}
}
}
if (list.rights && String(list.rights).indexOf(perm) >= 0) {
return true;
}
return (perm == 'i' && list.editable);
}
/** /**
* *
*/ */
@ -492,7 +518,7 @@ function rcube_kolab_notes_ui(settings)
$dialog.dialog('option', { height: Math.min(h-20, form.height()+130), width: Math.min(w-20, form.width()+50) }) $dialog.dialog('option', { height: Math.min(h-20, form.height()+130), width: Math.min(w-20, form.width()+50) })
.dialog('option', 'position', ['center', 'center']); // only works in a separate call (!?) .dialog('option', 'position', ['center', 'center']); // only works in a separate call (!?)
name = $('#noteslist-name').prop('disabled', !list.editable).val(list.editname || list.name); name = $('#noteslist-name').prop('disabled', !has_permission(list, 'a')).val(list.editname || list.name);
name.select(); name.select();
} }
}); });
@ -811,9 +837,9 @@ function rcube_kolab_notes_ui(settings)
return; return;
} }
var list = me.notebooks[data.list] || me.notebooks[me.selected_list] || {}; var list = me.notebooks[data.list] || me.notebooks[me.selected_list] || { rights: 'lrs', editable: false };
content = $('#notecontent').val(data.description), content = $('#notecontent').val(data.description),
readonly = data.readonly || !list.editable, readonly = data.readonly || !(list.editable || !data.uid && has_permission(list,'i')),
attachmentslist = $(rcmail.gui_objects.notesattachmentslist).html(''); attachmentslist = $(rcmail.gui_objects.notesattachmentslist).html('');
$('.notetitle', rcmail.gui_objects.noteviewtitle).val(data.title).prop('disabled', readonly).show(); $('.notetitle', rcmail.gui_objects.noteviewtitle).val(data.title).prop('disabled', readonly).show();
$('.dates .notecreated', rcmail.gui_objects.noteviewtitle).html(Q(data.created || '')); $('.dates .notecreated', rcmail.gui_objects.noteviewtitle).html(Q(data.created || ''));
@ -885,9 +911,10 @@ function rcube_kolab_notes_ui(settings)
if (!data.list) if (!data.list)
data.list = list.id; data.list = list.id;
data.readonly = readonly;
me.selected_note = data; me.selected_note = data;
me.selected_note.id = rcmail.html_identifier_encode(data.uid); me.selected_note.id = rcmail.html_identifier_encode(data.uid);
rcmail.enable_command('save', list.editable && !data.readonly); rcmail.enable_command('save', !readonly);
var html = data.html || data.description; var html = data.html || data.description;
@ -1235,7 +1262,7 @@ function rcube_kolab_notes_ui(settings)
*/ */
function check_change_state(data) function check_change_state(data)
{ {
if (!me.selected_note || me.selected_note.readonly || !me.notebooks[me.selected_note.list || me.selected_list].editable) { if (!me.selected_note || me.selected_note.readonly || !has_permission(me.notebooks[me.selected_note.list || me.selected_list], 'i')) {
return false; return false;
} }