diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2012-07-25 16:33:08 -0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2012-07-25 16:33:08 -0400 |
commit | 4d17ed2f71c8cbb0d34c039aa7953b2427ce5c78 (patch) | |
tree | 136a050983c8feaa993805ffff53d5aad86f9cff | |
parent | 6f58eca5349d8c82f7bba3a7c0f92c0caa8e3749 (diff) | |
download | nextcloud-server-4d17ed2f71c8cbb0d34c039aa7953b2427ce5c78.tar.gz nextcloud-server-4d17ed2f71c8cbb0d34c039aa7953b2427ce5c78.zip |
Make file actions permissions aware
-rw-r--r-- | apps/calendar/js/loader.js | 2 | ||||
-rw-r--r-- | apps/contacts/js/loader.js | 4 | ||||
-rw-r--r-- | apps/files/js/fileactions.js | 54 | ||||
-rw-r--r-- | apps/files/js/files.js | 5 | ||||
-rw-r--r-- | apps/files/templates/part.list.php | 3 | ||||
-rw-r--r-- | apps/files_archive/js/archive.js | 4 | ||||
-rw-r--r-- | apps/files_imageviewer/js/lightbox.js | 2 | ||||
-rw-r--r-- | apps/files_pdfviewer/js/viewer.js | 2 | ||||
-rw-r--r-- | apps/files_sharing/lib/share/file.php | 11 | ||||
-rw-r--r-- | apps/files_sharing/lib/share/folder.php | 13 | ||||
-rw-r--r-- | apps/files_texteditor/js/editor.js | 16 | ||||
-rw-r--r-- | apps/files_versions/js/versions.js | 2 | ||||
-rw-r--r-- | apps/media/js/loader.js | 4 | ||||
-rw-r--r-- | core/js/share.js | 2 | ||||
-rw-r--r-- | lib/files.php | 18 |
15 files changed, 94 insertions, 48 deletions
diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js index cef95afc3aa..57cf5adff0e 100644 --- a/apps/calendar/js/loader.js +++ b/apps/calendar/js/loader.js @@ -75,7 +75,7 @@ Calendar_Import={ } $(document).ready(function(){ if(typeof FileActions !== 'undefined'){ - FileActions.register('text/calendar','importcal', '', Calendar_Import.importdialog); + FileActions.register('text/calendar','importcal', FileActions.PERMISSION_READ, '', Calendar_Import.importdialog); FileActions.setDefault('text/calendar','importcal'); }; }); diff --git a/apps/contacts/js/loader.js b/apps/contacts/js/loader.js index 577ad103064..3b1f4070485 100644 --- a/apps/contacts/js/loader.js +++ b/apps/contacts/js/loader.js @@ -78,9 +78,9 @@ Contacts_Import={ }
$(document).ready(function(){
if(typeof FileActions !== 'undefined'){
- FileActions.register('text/vcard','importaddressbook', '', Contacts_Import.importdialog);
+ FileActions.register('text/vcard','importaddressbook', FileActions.PERMISSION_READ, '', Contacts_Import.importdialog);
FileActions.setDefault('text/vcard','importaddressbook');
- FileActions.register('text/x-vcard','importaddressbook', '', Contacts_Import.importdialog);
+ FileActions.register('text/x-vcard','importaddressbook', FileActions.PERMISSION_READ, '', Contacts_Import.importdialog);
FileActions.setDefault('text/x-vcard','importaddressbook');
};
});
\ No newline at end of file diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 4dc05088eed..d54dd466469 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -1,19 +1,28 @@ FileActions={ + PERMISSION_CREATE:4, + PERMISSION_READ:1, + PERMISSION_UPDATE:2, + PERMISSION_DELETE:8, + PERMISSION_SHARE:16, actions:{}, defaults:{}, icons:{}, currentFile:null, - register:function(mime,name,icon,action){ + register:function(mime,name,permissions,icon,action){ if(!FileActions.actions[mime]){ FileActions.actions[mime]={}; } - FileActions.actions[mime][name]=action; + if (!FileActions.actions[mime][name]) { + FileActions.actions[mime][name] = {}; + } + FileActions.actions[mime][name]['action'] = action; + FileActions.actions[mime][name]['permissions'] = permissions; FileActions.icons[name]=icon; }, setDefault:function(mime,name){ FileActions.defaults[mime]=name; }, - get:function(mime,type){ + get:function(mime,type,permissions){ var actions={}; if(FileActions.actions.all){ actions=$.extend( actions, FileActions.actions.all ) @@ -32,9 +41,15 @@ FileActions={ actions=$.extend( actions, FileActions.actions[type] ) } } - return actions; + var filteredActions = {}; + $.each(actions, function(name, action) { + if (action.permissions & permissions) { + filteredActions[name] = action.action; + } + }); + return filteredActions; }, - getDefault:function(mime,type){ + getDefault:function(mime,type,permissions){ if(mime){ var mimePart=mime.substr(0,mime.indexOf('/')); } @@ -48,22 +63,20 @@ FileActions={ }else{ name=FileActions.defaults.all; } - var actions=this.get(mime,type); + var actions=this.get(mime,type,permissions); return actions[name]; }, - display:function(parent, filename, type){ + display:function(parent){ FileActions.currentFile=parent; $('#fileList span.fileactions, #fileList td.date a.action').remove(); - var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType()); + var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions()); var file=FileActions.getCurrentFile(); if($('tr').filterAttr('data-file',file).data('renaming')){ return; } parent.children('a.name').append('<span class="fileactions" />'); - var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType()); + var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions()); for(name in actions){ - // no rename and share action for the 'Shared' dir - if((name=='Rename' || name =='Share') && type=='dir' && filename=='Shared') { continue; } if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){ var img=FileActions.icons[name]; if(img.call){ @@ -86,16 +99,12 @@ FileActions={ parent.find('a.name>span.fileactions').append(element); } } - if(actions['Delete'] && (type!='dir' || filename != 'Shared')){ // no delete action for the 'Shared' dir + if(actions['Delete']){ var img=FileActions.icons['Delete']; if(img.call){ img=img(file); } - if ($('#dir').val().indexOf('Shared') != -1) { - var html='<a href="#" original-title="' + t('files', 'Unshare') + '" class="action delete" style="display:none" />'; - } else { - var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />'; - } + var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />'; var element=$(html); if(img){ element.append($('<img src="'+img+'"/>')); @@ -131,6 +140,9 @@ FileActions={ }, getCurrentType:function(){ return FileActions.currentFile.parent().attr('data-type'); + }, + getCurrentPermissions:function() { + return FileActions.currentFile.parent().data('permissions'); } } @@ -140,12 +152,12 @@ $(document).ready(function(){ } else { var downloadScope = 'file'; } - FileActions.register(downloadScope,'Download',function(){return OC.imagePath('core','actions/download')},function(filename){ + FileActions.register(downloadScope,'Download', FileActions.PERMISSION_READ, function(){return OC.imagePath('core','actions/download')},function(filename){ window.location=OC.filePath('files', 'ajax', 'download.php') + encodeURIComponent('?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val())); }); }); -FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){ +FileActions.register('all','Delete', FileActions.PERMISSION_DELETE, function(){return OC.imagePath('core','actions/delete')},function(filename){ if(Files.cancelUpload(filename)) { if(filename.substr){ filename=[filename]; @@ -162,11 +174,11 @@ FileActions.register('all','Delete',function(){return OC.imagePath('core','actio } }); -FileActions.register('all','Rename',function(){return OC.imagePath('core','actions/rename')},function(filename){ +FileActions.register('all','Rename', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/rename')},function(filename){ FileList.rename(filename); }); -FileActions.register('dir','Open','',function(filename){ +FileActions.register('dir','Open', FileActions.PERMISSION_READ, '', function(filename){ window.location=OC.linkTo('files', 'index.php') + '&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8d52b742c1b..2f06f15f896 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -56,7 +56,7 @@ $(document).ready(function() { // Sets the file-action buttons behaviour : $('tr').live('mouseenter',function(event) { - FileActions.display($(this).children('td.filename'), $(this).attr('data-file'), $(this).attr('data-type')); + FileActions.display($(this).children('td.filename')); }); $('tr').live('mouseleave',function(event) { FileActions.hide(); @@ -106,7 +106,8 @@ $(document).ready(function() { if(!renaming && !FileList.isLoading(filename)){ var mime=$(this).parent().parent().data('mime'); var type=$(this).parent().parent().data('type'); - var action=FileActions.getDefault(mime,type); + var permissions = $(this).parent().parent().data('permissions'); + var action=FileActions.getDefault(mime,type, permissions); if(action){ action(filename); } diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 4506630c16d..6667b5488af 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -1,5 +1,4 @@ <?php foreach($_['files'] as $file): - $write = ($file['writable']) ? 'true' : 'false'; $simple_file_size = OCP\simple_file_size($file['size']); $simple_size_color = intval(200-$file['size']/(1024*1024)*2); // the bigger the file, the darker the shade of grey; megabytes*2 if($simple_size_color<0) $simple_size_color = 0; @@ -10,7 +9,7 @@ $name = str_replace('%2F','/', $name); $directory = str_replace('+','%20',urlencode($file['directory'])); $directory = str_replace('%2F','/', $directory); ?> - <tr data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-write='<?php echo $write;?>'> + <tr data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-permissions='<?php echo $file['permissions']; ?>'> <td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo OCP\mimetype_icon('dir'); else echo OCP\mimetype_icon($file['mimetype']); ?>)"> <?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" /><?php } ?> <a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$directory.'/'.$name; else echo $_['downloadURL'].$directory.'/'.$name; ?>" title=""> diff --git a/apps/files_archive/js/archive.js b/apps/files_archive/js/archive.js index 9fb9853e299..6bcbe092662 100644 --- a/apps/files_archive/js/archive.js +++ b/apps/files_archive/js/archive.js @@ -7,11 +7,11 @@ $(document).ready(function() { if(typeof FileActions!=='undefined'){ - FileActions.register('application/zip','Open','',function(filename){ + FileActions.register('application/zip','Open', FileActions.PERMISSION_READ, '',function(filename){ window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); FileActions.setDefault('application/zip','Open'); - FileActions.register('application/x-gzip','Open','',function(filename){ + FileActions.register('application/x-gzip','Open', FileActions.PERMISSION_READ, '',function(filename){ window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); }); FileActions.setDefault('application/x-gzip','Open'); diff --git a/apps/files_imageviewer/js/lightbox.js b/apps/files_imageviewer/js/lightbox.js index 31f08456d22..ff12d808bc8 100644 --- a/apps/files_imageviewer/js/lightbox.js +++ b/apps/files_imageviewer/js/lightbox.js @@ -1,6 +1,6 @@ $(document).ready(function() { if(typeof FileActions!=='undefined'){ - FileActions.register('image','View','',function(filename){ + FileActions.register('image','View', FileActions.PERMISSION_READ, '',function(filename){ viewImage($('#dir').val(),filename); }); FileActions.setDefault('image','View'); diff --git a/apps/files_pdfviewer/js/viewer.js b/apps/files_pdfviewer/js/viewer.js index 2c9cbb9b431..29db2ea7f24 100644 --- a/apps/files_pdfviewer/js/viewer.js +++ b/apps/files_pdfviewer/js/viewer.js @@ -40,7 +40,7 @@ $(document).ready(function(){ if(location.href.indexOf("files")!=-1) { PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js'); if(typeof FileActions!=='undefined'){ - FileActions.register('application/pdf','Edit','',function(filename){ + FileActions.register('application/pdf','Edit', FileActions.PERMISSION_READ, '',function(filename){ showPDFviewer($('#dir').val(),filename); }); FileActions.setDefault('application/pdf','Edit'); diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 658c42ee327..dd63539cdfe 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -70,7 +70,14 @@ class OC_Share_Backend_File extends OCP\Share_Backend { // Set target path $file['path'] = $shares[$file['id']]['file_target']; $file['name'] = basename($file['path']); - // TODO Set permissions: $file['writable'] + $file['directory'] = $parameters['folder']; + $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; + $permissions = $shares[$file['id']]['permissions']; + if ($file['type'] == 'file') { + // Remove Create permission if type is file + $permissions &= ~OCP\Share::PERMISSION_CREATE; + } + $file['permissions'] = $permissions; $files[] = $file; } return $files; @@ -85,7 +92,7 @@ class OC_Share_Backend_File extends OCP\Share_Backend { } $size += $file['size']; } - return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false)); + return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ)); } } return array(); diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php index 033e2ba9667..a43ce2b2caf 100644 --- a/apps/files_sharing/lib/share/folder.php +++ b/apps/files_sharing/lib/share/folder.php @@ -43,7 +43,18 @@ class OC_Share_Backend_Folder extends OC_Share_Backend_File { $pos = strpos($result['path'], $folder['item']); $path = substr($result['path'], $pos).substr($parameters['folder'], strlen($folder['file_target'])); $root = substr($result['path'], 0, $pos); - return OC_FileCache::getFolderContent($path, $root, $mimetype_filter); + $files = OC_FileCache::getFolderContent($path, $root, $mimetype_filter); + foreach ($files as &$file) { + $file['directory'] = $parameters['folder']; + $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; + $permissions = $folder['permissions']; + if ($file['type'] == 'file') { + // Remove Create permission if type is file + $permissions &= ~OCP\Share::PERMISSION_CREATE; + } + $file['permissions'] = $permissions; + } + return $files; } }/* else if ($format == self::FORMAT_OPENDIR_ROOT) { $query = OCP\DB::prepare('SELECT name FROM *PREFIX*fscache WHERE id IN ('.$ids.')'); diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js index 70bb74a9101..3784ea1032f 100644 --- a/apps/files_texteditor/js/editor.js +++ b/apps/files_texteditor/js/editor.js @@ -222,9 +222,17 @@ function showFileEditor(dir,filename){ } }); // Add the ctrl+s event - window.aceEditor.commands.addCommand({
name: "save",
bindKey: {
win: "Ctrl-S",
mac: "Command-S",
sender: "editor"
},
exec: function(){ + window.aceEditor.commands.addCommand({ + name: "save", + bindKey: { + win: "Ctrl-S", + mac: "Command-S", + sender: "editor" + }, + exec: function(){ doFileSave(); - }
}); + } + }); }); } else { // Failed to get the file. @@ -297,11 +305,11 @@ $(window).resize(function() { var is_editor_shown = false; $(document).ready(function(){ if(typeof FileActions!=='undefined'){ - FileActions.register('text','Edit','',function(filename){ + FileActions.register('text','Edit', FileActions.PERMISSION_READ, '',function(filename){ showFileEditor($('#dir').val(),filename); }); FileActions.setDefault('text','Edit'); - FileActions.register('application/xml','Edit','',function(filename){ + FileActions.register('application/xml','Edit', FileActions.PERMISSION_READ, '',function(filename){ showFileEditor($('#dir').val(),filename); }); FileActions.setDefault('application/xml','Edit'); diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js index a090fde446e..c5c1553f1a8 100644 --- a/apps/files_versions/js/versions.js +++ b/apps/files_versions/js/versions.js @@ -11,7 +11,7 @@ $(document).ready(function() { $(document).ready(function(){ if (typeof FileActions !== 'undefined') { // Add history button to files/index.php - FileActions.register('file','History',function(){return OC.imagePath('core','actions/history')},function(filename){ + FileActions.register('file','History', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/history')},function(filename){ if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback diff --git a/apps/media/js/loader.js b/apps/media/js/loader.js index 393f8ba914e..ffe9c1cdd61 100644 --- a/apps/media/js/loader.js +++ b/apps/media/js/loader.js @@ -45,8 +45,8 @@ $(document).ready(function() { // FileActions.register('application/ogg','Add to playlist','',addAudio); if(typeof FileActions!=='undefined'){ - FileActions.register('audio','Play','',playAudio); - FileActions.register('application/ogg','','Play',playAudio); + FileActions.register('audio','Play', FileActions.PERMISSION_READ, '',playAudio); + FileActions.register('application/ogg', FileActions.PERMISSION_READ, '','Play',playAudio); FileActions.setDefault('audio','Play'); FileActions.setDefault('application/ogg','Play'); } diff --git a/core/js/share.js b/core/js/share.js index 42002ea7985..4cff9ec1a67 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -164,7 +164,7 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { OC.Share.loadIcons('file'); - FileActions.register('all', 'Share', function(filename) { + FileActions.register('all', 'Share', FileActions.PERMISSION_SHARE, function(filename) { // Return the correct sharing icon if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback var item = $('#dir').val() + '/' + filename; diff --git a/lib/files.php b/lib/files.php index f7a7aecc167..fee71b777b3 100644 --- a/lib/files.php +++ b/lib/files.php @@ -36,7 +36,7 @@ class OC_Files { $files = array(); if (substr($directory, 0, 7) == '/Shared') { if ($directory == '/Shared') { - $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP, array('mimetype_filter' => $mimetype_filter)); + $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter)); } else { $pos = strpos($directory, '/', 8); // Get shared folder name @@ -49,15 +49,23 @@ class OC_Files { } } else { $files = OC_FileCache::getFolderContent($directory, false, $mimetype_filter); + foreach ($files as &$file) { + $file['directory'] = $directory; + $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; + $permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE; + if ($file['type'] == 'dir' && $file['writable']) { + $permissions |= OCP\Share::PERMISSION_CREATE; + } + if ($file['writable']) { + $permissions |= OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE; + } + $file['permissions'] = $permissions; + } if ($directory == '') { // Add 'Shared' folder $files = array_merge($files, OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT)); } } - foreach ($files as &$file) { - $file['directory'] = $directory; - $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; - } usort($files, "fileCmp");//TODO: remove this once ajax is merged return $files; } |