admin delete of files

This commit is contained in:
zotlabs 2018-05-02 20:08:59 -07:00
parent 9713436f49
commit e9f49d9d9c
5 changed files with 39 additions and 12 deletions

View File

@ -66,7 +66,7 @@ class Filestorage extends \Zotlabs\Web\Controller {
$perms = get_all_perms($owner, $ob_hash); $perms = get_all_perms($owner, $ob_hash);
if(! $perms['view_storage']) { if(! ($perms['view_storage'] || is_site_admin())){
notice( t('Permission denied.') . EOL); notice( t('Permission denied.') . EOL);
return; return;
} }
@ -75,16 +75,30 @@ class Filestorage extends \Zotlabs\Web\Controller {
// need to return for anyone other than the owner, despite the perms check for now. // need to return for anyone other than the owner, despite the perms check for now.
$is_owner = (((local_channel()) && ($owner == local_channel())) ? true : false); $is_owner = (((local_channel()) && ($owner == local_channel())) ? true : false);
if(! $is_owner) { if(! ($is_owner || is_site_admin())){
info( t('Permission Denied.') . EOL ); info( t('Permission Denied.') . EOL );
return; return;
} }
if(argc() > 3 && argv(3) === 'delete') { if(argc() > 3 && argv(3) === 'delete') {
if(argc() > 4 && argv(4) === 'json')
$json_return = true;
$admin_delete = false;
if(! $perms['write_storage']) { if(! $perms['write_storage']) {
if(is_site_admin()) {
$admin_delete = true;
}
else {
notice( t('Permission denied.') . EOL); notice( t('Permission denied.') . EOL);
if($json_return)
json_return_and_die([ 'success' => false ]);
return; return;
} }
}
$file = intval(argv(2)); $file = intval(argv(2));
$r = q("SELECT hash FROM attach WHERE id = %d AND uid = %d LIMIT 1", $r = q("SELECT hash FROM attach WHERE id = %d AND uid = %d LIMIT 1",
@ -92,21 +106,30 @@ class Filestorage extends \Zotlabs\Web\Controller {
intval($owner) intval($owner)
); );
if(! $r) { if(! $r) {
if($json_return)
json_return_and_die([ 'success' => false ]);
notice( t('File not found.') . EOL); notice( t('File not found.') . EOL);
goaway(z_root() . '/cloud/' . $which); goaway(z_root() . '/cloud/' . $which);
} }
$f = $r[0]; $f = $r[0];
$channel = \App::get_channel();
$channel = channelx_by_n($owner);
$url = get_cloud_url($channel['channel_id'], $channel['channel_address'], $f['hash']); $url = get_cloud_url($channel['channel_id'], $channel['channel_address'], $f['hash']);
attach_delete($owner, $f['hash']); attach_delete($owner, $f['hash']);
if(! $admin_delete) {
$sync = attach_export_data($channel, $f['hash'], true); $sync = attach_export_data($channel, $f['hash'], true);
if($sync) { if($sync) {
build_sync_packet($channel['channel_id'], array('file' => array($sync))); build_sync_packet($channel['channel_id'], array('file' => array($sync)));
} }
}
if(json_return)
json_return_and_die([ 'success' => true ]);
goaway(dirname($url)); goaway(dirname($url));
} }

View File

@ -241,7 +241,7 @@ class Browser extends DAV\Browser\Plugin {
// put the array for this file together // put the array for this file together
$ft['attachId'] = $this->findAttachIdByHash($attachHash); $ft['attachId'] = $this->findAttachIdByHash($attachHash);
$ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath, "cloud/")) . "filestorage/" . $this->auth->getCurrentUser(); $ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath, "cloud/")) . "filestorage/" . $this->auth->owner_nick;
$ft['icon'] = $icon; $ft['icon'] = $icon;
$ft['photo_icon'] = $photo_icon; $ft['photo_icon'] = $photo_icon;
$ft['attachIcon'] = (($size) ? $attachIcon : ''); $ft['attachIcon'] = (($size) ? $attachIcon : '');
@ -276,6 +276,8 @@ class Browser extends DAV\Browser\Plugin {
'$create' => t('Create'), '$create' => t('Create'),
'$upload' => t('Add Files'), '$upload' => t('Add Files'),
'$is_owner' => $is_owner, '$is_owner' => $is_owner,
'$is_admin' => is_site_admin(),
'$admin_delete' => t('Admin Delete'),
'$parentpath' => $parentpath, '$parentpath' => $parentpath,
'$cpath' => bin2hex(\App::$query_string), '$cpath' => bin2hex(\App::$query_string),
'$tiles' => intval($_SESSION['cloud_tiles']), '$tiles' => intval($_SESSION['cloud_tiles']),

View File

@ -1585,8 +1585,8 @@ function get_cloud_url($channel_id, $channel_name, $attachHash) {
} }
} while ($parentHash); } while ($parentHash);
$url = z_root() . '/cloud/' . $channel_name . '/' . $parentFullPath . find_filename_by_hash($channel_id, $attachHash);
$url = z_root() . '/cloud/' . $channel_name . '/' . $parentFullPath . find_filename_by_hash($channel_id, $attachHash);
return $url; return $url;
} }

View File

@ -1057,7 +1057,9 @@ function doprofilelike(ident, verb) {
$.get('like/' + ident + '?verb=' + verb, function() { window.location.href=window.location.href; }); $.get('like/' + ident + '?verb=' + verb, function() { window.location.href=window.location.href; });
} }
function dropItem(url, object) { function dropItem(url, object) {
var confirm = confirmDelete(); var confirm = confirmDelete();
if(confirm) { if(confirm) {
$('body').css('cursor', 'wait'); $('body').css('cursor', 'wait');

View File

@ -65,10 +65,10 @@
<td class="cloud-index-tool">{{$item.attachIcon}}</td> <td class="cloud-index-tool">{{$item.attachIcon}}</td>
<td class="cloud-index-tool"><div id="file-edit-{{$item.attachId}}" class="spinner-wrapper"><div class="spinner s"></div></div></td> <td class="cloud-index-tool"><div id="file-edit-{{$item.attachId}}" class="spinner-wrapper"><div class="spinner s"></div></div></td>
<td class="cloud-index-tool"><i class="fakelink fa fa-pencil" onclick="filestorage(event, '{{$nick}}', {{$item.attachId}});"></i></td> <td class="cloud-index-tool"><i class="fakelink fa fa-pencil" onclick="filestorage(event, '{{$nick}}', {{$item.attachId}});"></i></td>
<td class="cloud-index-tool"><a href="#" title="{{$delete}}" onclick="dropItem('{{$item.fileStorageUrl}}/{{$item.attachId}}/delete', '#cloud-index-{{$item.attachId}},#cloud-tools-{{$item.attachId}}'); return false;"><i class="fa fa-trash-o drop-icons"></i></a></td> <td class="cloud-index-tool"><a href="#" title="{{$delete}}" onclick="dropItem('{{$item.fileStorageUrl}}/{{$item.attachId}}/delete/json', '#cloud-index-{{$item.attachId}},#cloud-tools-{{$item.attachId}}'); return false;"><i class="fa fa-trash-o drop-icons"></i></a></td>
{{else}} {{else}}
<td></td><td></td><td></td><td></td> <td></td><td></td><td></td>{{if $is_admin}}<td class="cloud-index-tool"><a href="#" title="{{$admin_delete}}" onclick="dropItem('{{$item.fileStorageUrl}}/{{$item.attachId}}/delete/json', '#cloud-index-{{$item.attachId}},#cloud-tools-{{$item.attachId}}'); return false;"><i class="fa fa-trash-o drop-icons"></i></a>{{else}}<td>{{/if}}</td>
{{/if}} {{/if}}
<td>{{*{{$item.type}}*}}</td> <td>{{*{{$item.type}}*}}</td>
<td class="d-none d-md-table-cell">{{$item.sizeFormatted}}</td> <td class="d-none d-md-table-cell">{{$item.sizeFormatted}}</td>