Skip to content

Commit

Permalink
introduce share by mail, ui part
Browse files Browse the repository at this point in the history
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
  • Loading branch information
schiessle committed Oct 5, 2016
1 parent 3a0e061 commit 5cf90a3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
31 changes: 27 additions & 4 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,16 @@ public function search($search = '', $itemType = null, $page = 1, $perPage = 200

$shareTypes = [
Share::SHARE_TYPE_USER,
Share::SHARE_TYPE_EMAIL,
Share::SHARE_TYPE_REMOTE
];

if ($this->shareManager->allowGroupSharing()) {
$shareTypes[] = Share::SHARE_TYPE_GROUP;
}

$shareTypes[] = Share::SHARE_TYPE_REMOTE;

if (is_array($shareType)) {
$shareTypes = array_intersect($shareTypes, $shareType);
if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
$shareTypes = array_intersect($shareTypes, $_GET['shareType']);
sort($shareTypes);
} else if (is_numeric($shareType)) {
$shareTypes = array_intersect($shareTypes, [(int) $shareType]);
Expand Down Expand Up @@ -499,6 +499,10 @@ protected function searchSharees($search, $itemType, array $shareTypes, $page, $
$this->getRemote($search);
}

if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) {
$this->getEmail($search);
}

$response = new Http\DataResponse($this->result);

if (sizeof($this->reachedEndFor) < 3) {
Expand All @@ -513,6 +517,25 @@ protected function searchSharees($search, $itemType, array $shareTypes, $page, $
return $response;
}

/**
* add option to send share by mail
*
* @param string $search
*/
protected function getEmail($search) {
$this->result['emails'] = [];

if (substr_count($search, '@') >= 1 && substr_count($search, ' ') === 0 && $this->offset === 0) {
$this->result['exact']['emails'][] = [
'label' => $search,
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $search,
],
];
}
}

/**
* Generates a bunch of pagination links for the current page
*
Expand Down
26 changes: 20 additions & 6 deletions core/js/sharedialogview.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@
var users = result.ocs.data.exact.users.concat(result.ocs.data.users);
var groups = result.ocs.data.exact.groups.concat(result.ocs.data.groups);
var remotes = result.ocs.data.exact.remotes.concat(result.ocs.data.remotes);
var emails = result.ocs.data.exact.emails.concat(result.ocs.data.emails);

var usersLength;
var groupsLength;
var remotesLength;
var emailsLength;

var i, j;

Expand Down Expand Up @@ -212,10 +214,18 @@
break;
}
}
} else if (share.share_type === OC.Share.SHARE_TYPE_EMAIL) {
emailsLength = emails.length;
for (j = 0; j < emailsLength; j++) {
if (emails[j].value.shareWith === share.share_with) {
emails.splice(j, 1);
break;
}
}
}
}

var suggestions = users.concat(groups).concat(remotes);
var suggestions = users.concat(groups).concat(remotes).concat(emails);

if (suggestions.length > 0) {
$('.shareWithField').removeClass('error')
Expand Down Expand Up @@ -268,6 +278,10 @@
sharee: text
});
}
} else if (item.value.shareType === OC.Share.SHARE_TYPE_EMAIL) {
text = t('core', '{sharee} (email)', {
sharee: text
});
}
insert.text(text);
insert.attr('title', item.value.shareWith);
Expand Down Expand Up @@ -392,24 +406,24 @@
var infoTemplate = this._getRemoteShareInfoTemplate();
remoteShareInfo = infoTemplate({
docLink: this.configModel.getFederatedShareDocLink(),
tooltip: t('core', 'Share with people on other ownClouds using the syntax username@example.com/owncloud')
tooltip: t('core', 'Share with people on other servers using the syntax username@example.com/owncloud')
});
}

return remoteShareInfo;
},

_renderSharePlaceholderPart: function () {
var sharePlaceholder = t('core', 'Share with users');
var sharePlaceholder = t('core', 'Share with users, or by mail...');

if (this.configModel.get('allowGroupSharing')) {
if (this.configModel.get('isRemoteShareAllowed')) {
sharePlaceholder = t('core', 'Share with users, groups or remote users…');
sharePlaceholder = t('core', 'Share with users, groups, remote users, or by mail…');
} else {
sharePlaceholder = t('core', 'Share with users or groups…');
sharePlaceholder = t('core', 'Share with users, groups or by mail...');
}
} else if (this.configModel.get('isRemoteShareAllowed')) {
sharePlaceholder = t('core', 'Share with users or remote users');
sharePlaceholder = t('core', 'Share with users, remote users or by mail...');
}

return sharePlaceholder;
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Share/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Constants {
const SHARE_TYPE_USER = 0;
const SHARE_TYPE_GROUP = 1;
const SHARE_TYPE_LINK = 3;
const SHARE_TYPE_EMAIL = 4; // ToDo Check if it is still in use otherwise remove it
const SHARE_TYPE_EMAIL = 4;
const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it
const SHARE_TYPE_REMOTE = 6; // ToDo Check if it is still in use otherwise remove it
const SHARE_TYPE_REMOTE = 6;

const FORMAT_NONE = -1;
const FORMAT_STATUSES = -2;
Expand Down

0 comments on commit 5cf90a3

Please sign in to comment.