add acl selection to files upload via /cloud (still missing from directory creation)

This commit is contained in:
redmatrix 2016-07-24 20:27:59 -07:00
parent b5f2b4af35
commit 271f85be3b
3 changed files with 76 additions and 7 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace Zotlabs\Module;
require_once('include/attach.php');
require_once('include/channel.php');
require_once('include/photos.php');
class File_upload extends \Zotlabs\Web\Controller {
function post() {
$channel = (($_REQUEST['channick']) ? get_channel_by_nick($_REQUEST['channick']) : null);
if(! $channel) {
logger('channel not found');
killme();
}
$_REQUEST['source'] = 'file_upload';
if($channel['channel_id'] != local_channel()) {
$_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']);
$_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']);
$_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']);
$_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']);
}
if($_REQUEST['directory_name'])
$r = attach_mkdir($channel,get_observer_hash(),$_REQUEST);
else
$r = attach_store($channel,get_observer_hash(), '', $_REQUEST);
goaway(z_root() . '/' . $_REQUEST['return_url']);
}
}

View File

@ -274,6 +274,22 @@ class Browser extends DAV\Browser\Plugin {
// SimpleCollection, we won't need to show the panel either. // SimpleCollection, we won't need to show the panel either.
if (get_class($node) === 'Sabre\\DAV\\SimpleCollection') if (get_class($node) === 'Sabre\\DAV\\SimpleCollection')
return; return;
require_once('include/acl_selectors.php');
$aclselect = null;
$lockstate = '';
if($this->auth-owner_id) {
$channel = channelx_by_n($this->auth->owner_id);
if($channel) {
$acl = new \Zotlabs\Access\AccessList($channel);
$channel_acl = $acl->get();
$lockstate = (($acl->is_private()) ? 'lock' : 'unlock');
$aclselect = ((local_channel() == $this->auth->owner_id) ? populate_acl($channel_acl,false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_storage')) : '');
}
}
// Storage and quota for the account (all channels of the owner of this directory)! // Storage and quota for the account (all channels of the owner of this directory)!
$limit = engr_units_to_bytes(service_class_fetch($owner, 'attach_upload_limit')); $limit = engr_units_to_bytes(service_class_fetch($owner, 'attach_upload_limit'));
@ -293,7 +309,6 @@ class Browser extends DAV\Browser\Plugin {
userReadableSize($limit), userReadableSize($limit),
round($used / $limit, 1) * 100); round($used / $limit, 1) * 100);
} }
// prepare quota for template // prepare quota for template
$quota = array(); $quota = array();
$quota['used'] = $used; $quota['used'] = $used;
@ -307,6 +322,10 @@ class Browser extends DAV\Browser\Plugin {
'$upload_header' => t('Upload file'), '$upload_header' => t('Upload file'),
'$upload_submit' => t('Upload'), '$upload_submit' => t('Upload'),
'$quota' => $quota, '$quota' => $quota,
'$channick' => $this->auth->owner_nick,
'$aclselect' => $aclselect,
'$lockstate' => $lockstate,
'$return_url' => \App::$cmd,
'$dragdroptext' => t('Drop files here to immediately upload') '$dragdroptext' => t('Drop files here to immediately upload')
)); ));
} }

View File

@ -2,25 +2,37 @@
<label for="files-mkdir">{{$folder_header}}</label> <label for="files-mkdir">{{$folder_header}}</label>
<form method="post" action=""> <form method="post" action="">
<input type="hidden" name="sabreAction" value="mkcol"> <input type="hidden" name="sabreAction" value="mkcol">
<input id="files-mkdir" type="text" name="name" class="form-control form-group"> <input id="files-mkdir" type="text" name="dirname" class="form-control form-group">
<button class="btn btn-primary btn-sm pull-right" type="submit" value="{{$folder_submit}}">{{$folder_submit}}</button> <button class="btn btn-primary btn-sm pull-right" type="submit" value="{{$folder_submit}}">{{$folder_submit}}</button>
</form> </form>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div id="files-upload-tools" class="section-content-tools-wrapper"> <div id="files-upload-tools" class="section-content-tools-wrapper">
{{if $quota.limit || $quota.used}}<div class="{{if $quota.warning}}section-content-danger-wrapper{{else}}section-content-info-wrapper{{/if}}">{{if $quota.warning}}<strong>{{$quota.warning}} </strong>{{/if}}{{$quota.desc}}</div>{{/if}} {{if $quota.limit || $quota.used}}<div class="{{if $quota.warning}}section-content-danger-wrapper{{else}}section-content-info-wrapper{{/if}}">{{if $quota.warning}}<strong>{{$quota.warning}} </strong>{{/if}}{{$quota.desc}}</div>{{/if}}
<form id="ajax-upload-files" method="post" action="" enctype="multipart/form-data"> <form id="ajax-upload-files" method="post" action="file_upload" enctype="multipart/form-data">
<input type="hidden" name="sabreAction" value="put"> <input type="hidden" name="channick" value="{{$channick}}" />
<input type="hidden" name="return_url" value="{{$return_url}}" />
<div> <div>
<div id="filedrag" style="height: 7em;"><br>{{$dragdroptext}}</div> <div id="filedrag" style="height: 7em;"><br>{{$dragdroptext}}</div>
</div> </div>
<div id="file-upload-list"></div> <div id="file-upload-list"></div>
<div class="clear"></div> <div class="clear"></div>
{{$aclselect}}
<label for="files-upload">{{$upload_header}}</label> <label for="files-upload">{{$upload_header}}</label>
<div class="clear"></div> <div class="clear"></div>
<input class="form-group pull-left" id="files-upload" type="file" name="file" style="width: 70%;"> <input class="form-group pull-left" id="files-upload" type="file" name="userfile" style="width: 70%;">
<button class="btn btn-primary btn-sm pull-right" type="submit" value="{{$upload_submit}}">{{$upload_submit}}</button> <div class="pull-right btn-group">
<div class="btn-group">
{{if $lockstate}}
<button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" onclick="return false;">
<i id="jot-perms-icon" class="fa fa-{{$lockstate}}"></i>
</button>
{{/if}}
<button id="dbtn-submit" class="btn btn-primary btn-sm pull-right" type="submit" name="submit" value="{{$upload_submit}}">{{$upload_submit}}</button>
</div>
</div>
</form> </form>
<div class="clear"></div> <div class="clear"></div>
<hr/> <hr/>
</div> </div>