diff --git a/appinfo/app.php b/appinfo/app.php
index ab7ff9e..f87e851 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -31,5 +31,4 @@
$app = new Application(); // \AppInfo\Application();
$app->registerNavigationEntry();
-\OC\Share\Share::registerBackend ('nextnote', '\OCA\NextNote\ShareBackend\NextNoteShareBackend');
-\OCP\App::registerAdmin('nextnote', 'admin');
+
diff --git a/controller/noteapicontroller.php b/controller/noteapicontroller.php
index 0d13c8a..eaa42ca 100644
--- a/controller/noteapicontroller.php
+++ b/controller/noteapicontroller.php
@@ -25,12 +25,9 @@
use OCA\NextNote\Db\Notebook;
use OCA\NextNote\Db\Note;
-use OCA\NextNote\Fixtures\ShareFix;
use OCA\NextNote\Service\NotebookService;
use OCA\NextNote\Service\NoteService;
-use OCA\NextNote\ShareBackend\NextNoteShareBackend;
use OCA\NextNote\Utility\NotFoundJSONResponse;
-use OCA\NextNote\Utility\UnauthorizedJSONResponse;
use OCA\NextNote\Utility\Utils;
use \OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\JSONResponse;
@@ -39,7 +36,7 @@
use OCP\ILogger;
use \OCP\IRequest;
use OCP\IUserManager;
-use OCP\Share;
+
class NoteApiController extends ApiController {
@@ -52,15 +49,12 @@ class NoteApiController extends ApiController {
private $notebookService;
public function __construct($appName, IRequest $request,
- ILogger $logger, IConfig $config, NoteService $noteService, NotebookService $groupService,
- NextNoteShareBackend $shareBackend, IUserManager $userManager, Share\IManager $shareManager) {
+ ILogger $logger, IConfig $config, NoteService $noteService, NotebookService $groupService,IUserManager $userManager) {
parent::__construct($appName, $request);
$this->config = $config;
$this->noteService = $noteService;
$this->notebookService = $groupService;
- $this->shareBackend = $shareBackend;
$this->userManager = $userManager;
- $this->shareManager = $shareManager;
}
/**
@@ -164,9 +158,7 @@ public function update($id, $title, $content, $deleted, $notebook_id) {
$note->setGuid(Utils::GUID());
}
- if (!$this->shareBackend->checkPermissions(Constants::PERMISSION_UPDATE, $note)) {
- return new UnauthorizedJSONResponse();
- }
+
if(!empty($notebook_id)){
$notebook = $this->notebookService->find($notebook_id);
if($notebook instanceof Notebook) {
@@ -194,10 +186,6 @@ public function delete($id) {
return new NotFoundJSONResponse();
}
- if (!$this->shareBackend->checkPermissions(Constants::PERMISSION_DELETE, $entity)) {
- return new UnauthorizedJSONResponse();
- }
-
$this->noteService->delete($id);
$result = (object)['success' => true];
\OC_Hook::emit('OCA\NextNote', 'post_delete_note', ['note_id' => $id]);
@@ -213,20 +201,11 @@ private function formatApiResponse($note) {
$acl = [
'permissions' => Constants::PERMISSION_ALL
];
- if ($uid !== $note['uid']) {
- $aclRoles = ShareFix::getItemSharedWith('nextnote', $note['id'], 'populated_shares');
- $acl['permissions'] = $aclRoles['permissions'];
- }
+
$note['owner'] = Utils::getUserInfo($note['uid']);
$note['permissions'] = $acl['permissions'];
- $shared_with = ShareFix::getUsersItemShared('nextnote', $note['id'], $note['uid']);
- foreach ($shared_with as &$u) {
- $info = Utils::getUserInfo($u);
- if($info) {
- $u = $info;
- }
- }
+ $shared_with = [];
$note['shared_with'] = ($note['uid'] == $uid) ? $shared_with : [$uid];
unset($note['uid']);
diff --git a/controller/notebookapicontroller.php b/controller/notebookapicontroller.php
index 45ee79a..2830efd 100644
--- a/controller/notebookapicontroller.php
+++ b/controller/notebookapicontroller.php
@@ -24,36 +24,29 @@
namespace OCA\NextNote\Controller;
use OCA\NextNote\Db\Notebook;
-use OCA\NextNote\Fixtures\ShareFix;
use OCA\NextNote\Service\NotebookService;
-use OCA\NextNote\Service\NoteService;
-use OCA\NextNote\ShareBackend\NextNoteShareBackend;
use OCA\NextNote\Utility\NotFoundJSONResponse;
use OCA\NextNote\Utility\UnauthorizedJSONResponse;
use OCA\NextNote\Utility\Utils;
use \OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\JSONResponse;
-use OCP\Constants;
use OCP\IConfig;
use OCP\ILogger;
use \OCP\IRequest;
use OCP\IUserManager;
-use OCP\Share;
class NotebookApiController extends ApiController {
private $config;
private $notebookService;
- private $shareBackend;
private $userManager;
public function __construct($appName, IRequest $request,
- ILogger $logger, IConfig $config, NotebookService $notebookService, NextNoteShareBackend $shareBackend, IUserManager $userManager) {
+ ILogger $logger, IConfig $config, NotebookService $notebookService, IUserManager $userManager) {
parent::__construct($appName, $request);
$this->config = $config;
$this->notebookService = $notebookService;
- $this->shareBackend = $shareBackend;
$this->userManager = $userManager;
}
diff --git a/controller/shareapicontroller.php b/controller/shareapicontroller.php
index 0890e71..c930a03 100644
--- a/controller/shareapicontroller.php
+++ b/controller/shareapicontroller.php
@@ -13,8 +13,6 @@
use \OCP\AppFramework\ApiController;
use \OCP\IRequest;
-use OC\Share\Share;
-use OCA\NextNote\Fixtures\ShareFix;
class ShareApiController extends ApiController {
@@ -28,9 +26,7 @@ public function __construct($appName, IRequest $request) {
* @NoCSRFRequired
*/
public function getShares($noteid, $shared_with_me, $reshares) {
- if ($reshares) {
- return array_values(Share::getItemShared('nextnote', $noteid, 'shares'));
- }
+
}
/**
@@ -38,15 +34,7 @@ public function getShares($noteid, $shared_with_me, $reshares) {
* @NoCSRFRequired
*/
public function share($noteid, $shareType, $shareWith, $publicUpload, $password, $permissions) {
- $shareType = intval($shareType);
- //Todo check if resharing is allowed
- if($shareType === 1){
- $result = ShareFix::shareItem('nextnote', intval($noteid), intval($shareType), $shareWith, intval($permissions));
- } else {
- $result = Share::shareItem('nextnote', intval($noteid), intval($shareType), $shareWith, intval($permissions));
- }
- \OC_Hook::emit('OCA\NextNote', 'post_share_note', ['note_id' => $noteid]);
- return $result;
+
}
/**
@@ -54,9 +42,7 @@ public function share($noteid, $shareType, $shareWith, $publicUpload, $password,
* @NoCSRFRequired
*/
public function unshare($itemSource, $shareType, $shareWith) {
- $result = Share::unshare('nextnote', intval($itemSource), intval($shareType), $shareWith);
- \OC_Hook::emit('OCA\NextNote', 'post_unshare_note', ['note_id' => $itemSource]);
- return $result;
+
}
/**
@@ -64,8 +50,6 @@ public function unshare($itemSource, $shareType, $shareWith) {
* @NoCSRFRequired
*/
public function setpermissions($itemSource, $shareType, $shareWith, $permissions) {
- $result = ShareFix::setPermissions('nextnote', intval($itemSource), intval($shareType), $shareWith, intval($permissions));
- \OC_Hook::emit('OCA\NextNote', 'post_update_note_share_permissions', ['note_id' => $itemSource]);
- return $result;
+
}
}
\ No newline at end of file
diff --git a/controller/translationcontroller.php b/controller/translationcontroller.php
index 2687bd0..b176a32 100644
--- a/controller/translationcontroller.php
+++ b/controller/translationcontroller.php
@@ -23,25 +23,11 @@
namespace OCA\NextNote\Controller;
-use OCA\NextNote\Db\Notebook;
-use OCA\NextNote\Db\Note;
-use OCA\NextNote\Fixtures\ShareFix;
-use OCA\NextNote\Service\NotebookService;
-use OCA\NextNote\Service\NoteService;
-use OCA\NextNote\ShareBackend\NextNoteShareBackend;
-use OCA\NextNote\Utility\NotFoundJSONResponse;
-use OCA\NextNote\Utility\UnauthorizedJSONResponse;
-use OCA\NextNote\Utility\Utils;
+
use \OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\JSONResponse;
-use OCP\Constants;
-use OCP\IConfig;
use OCP\IL10N;
-use OCP\ILogger;
use \OCP\IRequest;
-use OCP\IUserManager;
-use OCP\Share;
-
class TranslationController extends ApiController {
diff --git a/js/animations.js b/js/animations.js
new file mode 100644
index 0000000..2889dd1
--- /dev/null
+++ b/js/animations.js
@@ -0,0 +1,33 @@
+$(document).ready(function () {
+ var isSingleViewMode = (app_config.user.view_mode === 'single');
+ var $body = $('body');
+ if(isSingleViewMode){
+ $('#ownnote').find('.view-container').width('200%');
+ }
+ $body.on('click', '.file.pointer, #new', function (e) {
+ if ($(window).width() <= 994 || isSingleViewMode) {
+ setTimeout(function () {
+ $('#ownnote').animate({scrollLeft: $(window).width()}, 750);
+ }, 50);
+ }
+ });
+ $body.on('click', '#canceledit, #grouplist .group', function (e) {
+ if ($(window).width() <= 994 || isSingleViewMode) {
+ $('#ownnote').animate({scrollLeft: 0}, 750);
+ }
+ });
+
+ $body.on('click', '.toggle-view-mode', function () {
+ if(app_config.user.view_mode === 'single') {
+ $('#ownnote').find('.view-container').animate({width: '100%'}, 750);
+ $(this).find('i').removeClass('fa-arrows-h').addClass('fa-columns');
+ isSingleViewMode = false;
+ app_config.user.view_mode = 'col';
+ } else if(app_config.user.view_mode === 'col'){
+ $('#ownnote').find('.view-container').animate({width: '200%'}, 750);
+ $(this).find('i').removeClass('fa-columns').addClass('fa-arrows-h');
+ isSingleViewMode = true;
+ app_config.user.view_mode = 'single';
+ }
+ });
+});
diff --git a/js/share.js b/js/share.js
deleted file mode 100644
index 3dbbf0f..0000000
--- a/js/share.js
+++ /dev/null
@@ -1,1316 +0,0 @@
-/* global Ownnote, escapeHTML */
-window.Ownnote = {};
-window.Ownnote.Share = {};
-
-(function ($, Ownnote) {
- "use strict";
-
- /**
- * @typedef {Object} Ownnote.Share.Types.ShareInfo
- * @property {Number} share_type
- * @property {Number} permissions
- * @property {Number} file_source optional
- * @property {Number} item_source
- * @property {String} token
- * @property {String} share_with
- * @property {String} share_with_displayname
- * @property {String} mail_send
- * @property {String} displayname_file_owner
- * @property {String} displayname_owner
- * @property {String} uid_owner
- * @property {String} uid_file_owner
- * @property {String} expiration optional
- * @property {Number} stime
- */
-
- // copied and stripped out from the old core
- var Share = {
- SHARE_TYPE_USER: 0,
- SHARE_TYPE_GROUP: 1,
- SHARE_TYPE_LINK: 3,
- SHARE_TYPE_EMAIL: 4,
- SHARE_TYPE_REMOTE: 6,
-
- itemShares: [],
-
- /**
- * Shares for the currently selected file.
- * (for which the dropdown is open)
- *
- * Key is item type and value is an array or
- * shares of the given item type.
- */
- currentShares: {},
-
- /**
- * Whether the share dropdown is opened.
- */
- droppedDown: false,
-
- /**
- *
- * @param path {String} path to the file/folder which should be shared
- * @param shareType {Number} 0 = user; 1 = group; 3 = public link; 6 = federated cloud
- * share
- * @param shareWith {String} user / group id with which the file should be shared
- * @param publicUpload {Boolean} allow public upload to a public shared folder
- * @param password {String} password to protect public link Share with
- * @param permissions {Number} 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31
- * = all (default: 31, for public shares: 1)
- * @param callback {Function} method to call back after a successful share creation
- * @param errorCallback {Function} method to call back after a failed share creation
- *
- * @returns {*}
- */
- share: function (noteid, shareType, shareWith, publicUpload, password, permissions, callback, errorCallback) {
-
- return $.ajax({
- url: OC.generateUrl('/apps/nextnote/') + 'api/v2/sharing/shares',
- type: 'POST',
- data: {
- noteid: noteid,
- shareType: shareType,
- shareWith: shareWith,
- publicUpload: publicUpload,
- password: password,
- permissions: permissions
- },
- dataType: 'json'
- }).done(function (result) {
- if (result) {
- var data = {
- id: noteid
- };
- if (callback) {
- callback(data);
- }
- }
- }).fail(function (xhr) {
- var result = xhr.responseJSON;
- if (_.isFunction(errorCallback)) {
- errorCallback(result);
- } else {
- var msg = t('core', 'Error');
- if (result.ocs && result.ocs.meta.message) {
- msg = result.ocs.meta.message;
- }
- OC.dialogs.alert(msg, t('core', 'Error while sharing'));
- }
- });
- },
- /**
- *
- * @param {Number} shareId
- * @param {Function} callback
- */
- unshare: function (shareId, shareType, shareWith, callback) {
- var url = OC.generateUrl('/apps/nextnote/') + 'api/v2/sharing/shares/' + shareId;
- url += '?' + $.param({
- 'shareType': shareType,
- 'shareWith': shareWith
- });
- $.ajax({
- url: url,
- type: 'DELETE'
- }).done(function () {
- if (callback) {
- callback();
- }
- }).fail(function () {
- OC.dialogs.alert(t('core', 'Error while unsharing'), t('core', 'Error'));
-
- });
- },
- /**
- *
- * @param {Number} shareId
- * @param {Number} permissions
- */
- setPermissions: function (shareId, shareType, shareWith, permissions) {
- var url = OC.generateUrl('/apps/nextnote/') + 'api/v2/sharing/shares/' + shareId + '/permissions';
- $.ajax({
- url: url,
- type: 'PUT',
- data: {
- shareType: shareType,
- shareWith: shareWith,
- permissions: permissions
- }
- }).fail(function () {
- OC.dialogs.alert(t('core', 'Error while changing permissions'),
- t('core', 'Error'));
- });
- },
- /**
- *
- * @param {String} itemType
- * @param {String} path
- * @param {String} appendTo
- * @param {String} link
- * @param {Number} possiblePermissions
- * @param {String} filename
- */
- showDropDown: function (itemType, path, appendTo, link, possiblePermissions, filename) {
- // This is a sync AJAX request on the main thread...
- var data = this._loadShares(path);
- var dropDownEl;
- var self = this;
- var html = '
';
- if (data !== false && data[0] && !_.isUndefined(data[0].uid_owner) &&
- data[0].uid_owner !== OC.currentUser
- ) {
- html += '
';
- if (oc_config.enable_avatars === true) {
- html += '
';
- }
-
- if (data[0].share_type == this.SHARE_TYPE_GROUP) {
- html += t('core', 'Shared with you and the group {group} by {owner}', {
- group: data[0].share_with,
- owner: data[0].displayname_owner
- });
- } else {
- html += t('core', 'Shared with you by {owner}',
- {owner: data[0].displayname_owner});
- }
- html += ' ';
- // reduce possible permissions to what the original share allowed
- possiblePermissions = possiblePermissions & data[0].permissions;
- }
-
- if (possiblePermissions & OC.PERMISSION_SHARE) {
- // Determine the Allow Public Upload status.
- // Used later on to determine if the
- // respective checkbox should be checked or
- // not.
- var publicUploadEnabled = $('#Ownnote').data('allow-public-upload');
- if (typeof publicUploadEnabled == 'undefined') {
- publicUploadEnabled = 'no';
- }
- var allowPublicUploadStatus = false;
-
- $.each(data, function (key, value) {
- if (value.share_type === self.SHARE_TYPE_LINK) {
- allowPublicUploadStatus =
- (value.permissions & OC.PERMISSION_CREATE) ? true : false;
- return true;
- }
- });
-
- var sharePlaceholder = t('core', 'Share with users or groups …');
- if (oc_appconfig.core.remoteShareAllowed) {
- sharePlaceholder = t('core', 'Share with users, groups or remote users …');
- }
-
- html += '
' + t('core', 'Share') +
- ' ';
- html +=
- '
';
- if (oc_appconfig.core.remoteShareAllowed) {
- var federatedCloudSharingDoc =
- '
';
- html += federatedCloudSharingDoc.replace('{docLink}',
- oc_appconfig.core.federatedCloudShareDoc);
- }
- html += '
';
- html += '
';
- var linksAllowed = $('#allowShareWithLink').val() === 'yes';
- var defaultExpireMessage = '';
- if (link && linksAllowed) {
- html += '
';
- html += '
';
- html +=
- '
' +
- '
' + t('core', 'Share link') + ' ';
- html += '
';
-
-
- if ((itemType === 'folder' || itemType === 'file') &&
- oc_appconfig.core.defaultExpireDateEnforced) {
- defaultExpireMessage =
- t('core',
- 'The public link will expire no later than {days} days after it is created',
- {'days': oc_appconfig.core.defaultExpireDate}) + '
';
- }
-
- html += '
' + t('core', 'Link') +
- ' ';
- html += '
';
- html +=
- '
' +
- '
' +
- t('core', 'Password protect') + ' ';
- html += '
';
- html += '' +
- t('core', 'Password') + ' ';
- html += ' ';
- html += ' ';
- html += '
';
-
- if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE) &&
- publicUploadEnabled === 'yes') {
- html += '
';
- html += ' ';
- html +=
- ' ';
- html += '' +
- t('core', 'Allow editing') + ' ';
- html += '
';
- }
-
- var mailPublicNotificationEnabled = $('input:hidden[name=mailPublicNotificationEnabled]').val();
- if (mailPublicNotificationEnabled === 'yes') {
- html += '
';
- }
- }
-
- html += '
';
- html +=
- ' ' +
- '' +
- t('core', 'Set expiration date') + ' ';
- html += '' +
- t('core', 'Expiration') + ' ';
- html += ' ';
- if (defaultExpireMessage) {
- html += '' + defaultExpireMessage + ' ';
- }
-
- html += '
';
- dropDownEl = $(html);
- dropDownEl = dropDownEl.appendTo(appendTo);
-
-
- // trigger remote share info tooltip
- if (oc_appconfig.core.remoteShareAllowed) {
- $('.shareWithRemoteInfo').tooltip({placement: 'top'});
- }
-
- //Get owner avatars
- if (oc_config.enable_avatars === true && data !== false && data[0] !== false &&
- !_.isUndefined(data[0]) && !_.isUndefined(data[0].uid_owner)) {
- dropDownEl.find(".avatar").avatar(data[0].uid, 32);
- }
-
- // Reset item shares
- this.itemShares = [];
- this.currentShares = {};
- if (data) {
- $.each(data, function (index, share) {
- if (share.share_type === self.SHARE_TYPE_LINK) {
- self.showLink(share.id, share.token, share.share_with);
- } else {
- if (share.share_with !== OC.currentUser || share.share_type !== self.SHARE_TYPE_USER) {
- if (share.share_type === self.SHARE_TYPE_REMOTE) {
- self._addShareWith(share.id,
- share.share_type,
- share.share_with,
- share.share_with_displayname,
- share.permissions,
- OC.PERMISSION_READ | OC.PERMISSION_UPDATE |
- OC.PERMISSION_CREATE,
- share.mail_send,
- share.item_source,
- false);
- } else {
- self._addShareWith(share.id,
- share.share_type,
- share.share_with,
- share.share_with_displayname,
- share.permissions,
- possiblePermissions,
- share.mail_send,
- share.item_source,
- false);
- }
- }
- }
- if (share.expiration != null) {
- var expireDate = moment(share.expiration, 'YYYY-MM-DD').format(
- 'DD-MM-YYYY');
- self.showExpirationDate(expireDate, share.stime);
- }
- });
- }
- $('#shareWith').autocomplete({
- minLength: 1,
- delay: 750,
- source: function (search, response) {
- var $loading = $('#dropdown .shareWithLoading');
- $loading.removeClass('hidden');
- // Can be replaced with Sharee API
- // https://github.com/owncloud/core/pull/18234
- $.get('/ocs/v1.php/apps/files_sharing/api/v1/sharees?format=json&search=' + search.term.trim() + '&perPage=200&itemType=' + itemType, {
- fetch: 'getShareWith',
- search: search.term.trim(),
- perPage: 200,
- itemShares: this.itemShares,
- itemType: itemType
- }, function (result) {
- var sharees = result.ocs.data;
-
- var results = [];
-
- for (var key in sharees) {
- if (sharees.hasOwnProperty(key)) {
- if (sharees[key]) {
- if (!sharees[key].hasOwnProperty('circles')) {
- results = results.concat(sharees[key])
- }
- }
- }
- }
-
- $loading.addClass('hidden');
- if (result.ocs.meta.status === 'ok') {
- $("#shareWith").autocomplete("option", "autoFocus", true);
- response(results);
- } else {
- response();
- }
- }).fail(function () {
- $('#dropdown').find('.shareWithLoading').addClass('hidden');
- OC.Notification.show(t('core', 'An error occured. Please try again'));
- window.setTimeout(OC.Notification.hide, 5000);
- });
- },
- focus: function (event) {
- event.preventDefault();
- },
- select: function (event, selected) {
- event.stopPropagation();
- var $dropDown = $('#dropdown');
- var itemSource = $dropDown.data('item-source');
- var expirationDate = '';
- if ($('#expirationCheckbox').is(':checked') === true) {
- expirationDate = $("#expirationDate").val();
- }
- var shareType = selected.item.value.shareType;
- var shareWith = selected.item.value.shareWith;
- $(this).val(shareWith);
- // Default permissions are Edit (CRUD) and Share
- // Check if these permissions are possible
- var permissions = OC.PERMISSION_READ;
- if (shareType === Ownnote.Share.SHARE_TYPE_REMOTE) {
- permissions =
- OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_READ;
- } else {
- if (possiblePermissions & OC.PERMISSION_UPDATE) {
- permissions = permissions | OC.PERMISSION_UPDATE;
- }
- if (possiblePermissions & OC.PERMISSION_CREATE) {
- permissions = permissions | OC.PERMISSION_CREATE;
- }
- if (possiblePermissions & OC.PERMISSION_DELETE) {
- permissions = permissions | OC.PERMISSION_DELETE;
- }
- if (oc_appconfig.core.resharingAllowed &&
- (possiblePermissions & OC.PERMISSION_SHARE)) {
- permissions = permissions | OC.PERMISSION_SHARE;
- }
- }
-
- var $input = $(this);
- var $loading = $dropDown.find('.shareWithLoading');
- $loading.removeClass('hidden');
- $input.val(t('core', 'Adding user...'));
- $input.prop('disabled', true);
- Ownnote.Share.share(
- itemSource,
- shareType,
- shareWith,
- 0,
- null,
- permissions,
- function (data) {
- var posPermissions = possiblePermissions;
- if (shareType === Ownnote.Share.SHARE_TYPE_REMOTE) {
- posPermissions = permissions;
- }
- Ownnote.Share._addShareWith(data.id, shareType, shareWith,
- selected.item.label,
- permissions, posPermissions, false, itemSource, false);
- });
- $input.prop('disabled', false);
- $loading.addClass('hidden');
- $('#shareWith').val('');
- return false;
- }
- }).data("ui-autocomplete")._renderItem = function (ul, item) {
- // customize internal _renderItem function to display groups and users
- // differently
- var insert = $("
");
- var text = item.label;
- if (item.value.shareType === Ownnote.Share.SHARE_TYPE_GROUP) {
- text = text + ' (' + t('core', 'group') + ')';
- } else if (item.value.shareType === Ownnote.Share.SHARE_TYPE_REMOTE) {
- text = text + ' (' + t('core', 'remote') + ')';
- }
- insert.text(text);
- if (item.value.shareType === Ownnote.Share.SHARE_TYPE_GROUP) {
- insert = insert.wrapInner(' ');
- }
- return $("")
- .addClass(
- (item.value.shareType ===
- Ownnote.Share.SHARE_TYPE_GROUP) ? 'group' : 'user')
- .append(insert)
- .appendTo(ul);
- };
-
- if (link && linksAllowed && $('#email').length != 0) {
- $('#email').autocomplete({
- minLength: 1,
- source: function (search, response) {
- $.get(OC.filePath('core', 'ajax', 'share.php'), {
- fetch: 'getShareWithEmail',
- search: search.term
- }, function (result) {
- if (result.status == 'success' && result.data.length > 0) {
- response(result.data);
- }
- });
- },
- select: function (event, item) {
- $('#email').val(item.item.email);
- return false;
- }
- })
- .data("ui-autocomplete")._renderItem = function (ul, item) {
- return $(' ')
- .append('' + escapeHTML(item.displayname) + " " +
- escapeHTML(item.email) + ' ')
- .appendTo(ul);
- };
- }
-
- } else {
- html += ' ';
- html += ' ';
- dropDownEl = $(html);
- dropDownEl.appendTo(appendTo);
- }
- dropDownEl.attr('data-item-source-name', filename);
- $('#dropdown').slideDown(OC.menuSpeed, function () {
- Ownnote.Share.droppedDown = true;
- });
- if ($('html').hasClass('lte9')) {
- $('#dropdown input[placeholder]').placeholder();
- }
- $('#shareWith').focus();
- if (!link) {
- $('#expiration').hide();
- }
- },
- /**
- *
- * @param callback
- */
- hideDropDown: function (callback) {
- this.currentShares = null;
- $('#dropdown').slideUp(OC.menuSpeed, function () {
- Ownnote.Share.droppedDown = false;
- $('#dropdown').remove();
- if (typeof FileActions !== 'undefined') {
- $('tr').removeClass('mouseOver');
- }
- if (callback) {
- callback.call();
- }
- });
- },
- /**
- *
- * @param id
- * @param token
- * @param password
- */
- showLink: function (id, token, password) {
- var $linkCheckbox = $('#linkCheckbox');
- this.itemShares[this.SHARE_TYPE_LINK] = true;
- $linkCheckbox.attr('checked', true);
- $linkCheckbox.attr('data-id', id);
- var $linkText = $('#linkText');
-
- var link = parent.location.protocol + '//' + location.host +
- OC.generateUrl('/apps/' + Ownnote.appName + '/s/') + token;
-
- $linkText.val(link);
- $linkText.slideDown(OC.menuSpeed);
- $linkText.css('display', 'block');
- if (oc_appconfig.core.enforcePasswordForPublicLink === false || password === null) {
- $('#showPassword+label').show();
- }
- if (password != null) {
- $('#linkPass').slideDown(OC.menuSpeed);
- $('#showPassword').attr('checked', true);
- $('#linkPassText').attr('placeholder', '**********');
- }
- $('#expiration').show();
- $('#emailPrivateLink #email').show();
- $('#emailPrivateLink #emailButton').show();
- $('#allowPublicUploadWrapper').show();
- },
- /**
- *
- */
- hideLink: function () {
- $('#linkText').slideUp(OC.menuSpeed);
- $('#defaultExpireMessage').hide();
- $('#showPassword+label').hide();
- $('#linkPass').slideUp(OC.menuSpeed);
- $('#emailPrivateLink #email').hide();
- $('#emailPrivateLink #emailButton').hide();
- $('#allowPublicUploadWrapper').hide();
- },
- /**
- * Displays the expiration date field
- *
- * @param {String} date current expiration date
- * @param {Date|Number|String} [shareTime] share timestamp in seconds, defaults to now
- */
- showExpirationDate: function (date, shareTime) {
- var $expirationDate = $('#expirationDate');
- var $expirationCheckbox = $('#expirationCheckbox');
- var now = new Date();
- // min date should always be the next day
- var minDate = new Date();
- minDate.setDate(minDate.getDate() + 1);
- var datePickerOptions = {
- minDate: minDate,
- maxDate: null
- };
- // TODO: hack: backend returns string instead of integer
- shareTime = this._parseTime(shareTime);
- if (_.isNumber(shareTime)) {
- shareTime = new Date(shareTime * 1000);
- }
- if (!shareTime) {
- shareTime = now;
- }
- $expirationCheckbox.attr('checked', true);
- $expirationDate.val(date);
- $expirationDate.slideDown(OC.menuSpeed);
- $expirationDate.css('display', 'block');
- $expirationDate.datepicker({
- dateFormat: 'dd-mm-yy'
- });
- if (oc_appconfig.core.defaultExpireDateEnforced) {
- $expirationCheckbox.attr('disabled', true);
- shareTime = OC.Util.stripTime(shareTime).getTime();
- // max date is share date + X days
- datePickerOptions.maxDate =
- new Date(shareTime + oc_appconfig.core.defaultExpireDate * 24 * 3600 * 1000);
- }
- if (oc_appconfig.core.defaultExpireDateEnabled) {
- $('#defaultExpireMessage').slideDown(OC.menuSpeed);
- }
- $.datepicker.setDefaults(datePickerOptions);
- },
- /**
- * Get the default Expire date
- *
- * @return {String} The expire date
- */
- getDefaultExpirationDate: function () {
- var expireDateString = '';
- if (oc_appconfig.core.defaultExpireDateEnabled) {
- var date = new Date().getTime();
- var expireAfterMs = oc_appconfig.core.defaultExpireDate * 24 * 60 * 60 * 1000;
- var expireDate = new Date(date + expireAfterMs);
- var month = expireDate.getMonth() + 1;
- var year = expireDate.getFullYear();
- var day = expireDate.getDate();
- expireDateString = year + "-" + month + '-' + day + ' 00:00:00';
- }
- return expireDateString;
- },
- /**
- * Loads all shares associated with a path
- *
- * @param path
- *
- * @returns {Ownnote.Share.Types.ShareInfo|Boolean}
- * @private
- */
- _loadShares: function (noteid) {
- var data = false;
- var url = OC.generateUrl('/apps/nextnote/') + 'api/v2/sharing/shares';
- $.ajax({
- url: url,
- type: 'GET',
- data: {
- noteid: noteid,
- shared_with_me: true
- },
- async: false
- }).done(function (result) {
- data = result;
- $.ajax({
- url: url,
- type: 'GET',
- data: {
- noteid: noteid,
- reshares: true
- },
- async: false
- }).done(function (result) {
- data = _.union(data, result);
- })
-
- });
-
- if (data === false) {
- OC.dialogs.alert(t('Ownnote', 'Error while retrieving shares'),
- t('core', 'Error'));
- }
-
- return data;
- },
- /**
- *
- * @param shareId
- * @param shareType
- * @param shareWith
- * @param shareWithDisplayName
- * @param permissions
- * @param possiblePermissions
- * @param mailSend
- *
- * @private
- */
- _addShareWith: function (shareId, shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend, itemSource) {
- var shareItem = {
- share_id: shareId,
- share_type: shareType,
- share_with: shareWith,
- share_with_displayname: shareWithDisplayName,
- permissions: permissions,
- itemSource: itemSource,
- };
- if (shareType === this.SHARE_TYPE_GROUP) {
- shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'group') + ')';
- }
- if (shareType === this.SHARE_TYPE_REMOTE) {
- shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote') + ')';
- }
- if (!this.itemShares[shareType]) {
- this.itemShares[shareType] = [];
- }
- this.itemShares[shareType].push(shareWith);
-
- var editChecked = '',
- createChecked = '',
- updateChecked = '',
- deleteChecked = '',
- shareChecked = '';
- if (permissions & OC.PERMISSION_CREATE) {
- createChecked = 'checked="checked"';
- editChecked = 'checked="checked"';
- }
- if (permissions & OC.PERMISSION_UPDATE) {
- updateChecked = 'checked="checked"';
- editChecked = 'checked="checked"';
- }
- if (permissions & OC.PERMISSION_DELETE) {
- deleteChecked = 'checked="checked"';
- editChecked = 'checked="checked"';
- }
- if (permissions & OC.PERMISSION_SHARE) {
- shareChecked = 'checked="checked"';
- }
- var html = '
';
- var showCrudsButton;
- html +=
- ' ';
- if (oc_config.enable_avatars === true) {
- html += '
';
- }
- html += '' + escapeHTML(shareWithDisplayName) + ' ';
- var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
- if (mailNotificationEnabled === 'yes' &&
- shareType !== this.SHARE_TYPE_REMOTE) {
- var checked = '';
- if (mailSend === 1) {
- checked = 'checked';
- }
- html +=
- ' ';
- html +=
- '' + t('core', 'notify by email') + ' ';
- }
- html += '';
- if (oc_appconfig.core.resharingAllowed &&
- (possiblePermissions & OC.PERMISSION_SHARE)) {
- html += ' ';
- html += '' +
- t('core', 'can share') + ' ';
- }
- /*if (possiblePermissions & OC.PERMISSION_CREATE ||
- possiblePermissions & OC.PERMISSION_UPDATE ||
- possiblePermissions & OC.PERMISSION_DELETE) {
- html += ' ';
- html += '' +
- t('core', 'can edit') + ' ';
- }*/
- if (shareType !== this.SHARE_TYPE_REMOTE) {
- showCrudsButton = ' ';
- }
- //html += '';
- if (possiblePermissions & OC.PERMISSION_UPDATE) {
- html += ' ';
- html += '' +
- t('core', 'can edit') + ' ';
- }
- if (possiblePermissions & OC.PERMISSION_DELETE) {
- html += ' ';
- html += '' +
- t('core', 'delete') + ' ';
- }
- html += '';
- //html += '
';
- html += ' ';
- html = $(html).appendTo('#shareWithList');
- if (oc_config.enable_avatars === true) {
- if (shareType === this.SHARE_TYPE_USER) {
- html.find('.avatar').avatar(escapeHTML(shareWith), 32);
- } else {
- //Add sharetype to generate different seed if there is a group and use with
- // the same name
- html.find('.avatar').imageplaceholder(
- escapeHTML(shareWith) + ' ' + shareType);
- }
- }
- // insert cruds button into last label element
- var lastLabel = html.find('>label:last');
- if (lastLabel.exists()) {
- lastLabel.append(showCrudsButton);
- }
- else {
- html.find('.cruds').before(showCrudsButton);
- }
- if (!this.currentShares[shareType]) {
- this.currentShares[shareType] = [];
- }
- this.currentShares[shareType].push(shareItem);
- },
- /**
- * Parses a string to an valid integer (unix timestamp)
- * @param time
- * @returns {*}
- * @internal Only used to work around a bug in the backend
- * @private
- */
- _parseTime: function (time) {
- if (_.isString(time)) {
- // skip empty strings and hex values
- if (time === '' || (time.length > 1 && time[0] === '0' && time[1] === 'x')) {
- return null;
- }
- time = parseInt(time, 10);
- if (isNaN(time)) {
- time = null;
- }
- }
- return time;
- }
- };
-
- Ownnote.Share = Share;
-})(jQuery, Ownnote);
-
-$(document).ready(function () {
-
- if (typeof monthNames != 'undefined') {
- // min date should always be the next day
- var minDate = new Date();
- minDate.setDate(minDate.getDate() + 1);
- $.datepicker.setDefaults({
- monthNames: monthNames,
- monthNamesShort: $.map(monthNames, function (v) {
- return v.slice(0, 3) + '.';
- }),
- dayNames: dayNames,
- dayNamesMin: $.map(dayNames, function (v) {
- return v.slice(0, 2);
- }),
- dayNamesShort: $.map(dayNames, function (v) {
- return v.slice(0, 3) + '.';
- }),
- firstDay: firstDay,
- minDate: minDate
- });
- }
- $(document).on('click', 'a.share', function (event) {
- event.stopPropagation();
- if ($(this).data('item-type') !== undefined && $(this).data('path') !== undefined) {
- var itemType = $(this).data('item-type');
- var path = $(this).data('path');
- var appendTo = $(this).parent().parent();
- var link = false;
- var possiblePermissions = $(this).data('possible-permissions');
- if ($(this).data('link') !== undefined && $(this).data('link') == true) {
- link = true;
- }
- // Ownnote.Share.showDropDown(itemType, path, appendTo, link, possiblePermissions);
-
- if (Ownnote.Share.droppedDown) {
- if (path != $('#dropdown').data('path')) {
- Ownnote.Share.hideDropDown(function () {
- Ownnote.Share.showDropDown(itemType, path, appendTo, link,
- possiblePermissions);
- });
- } else {
- Ownnote.Share.hideDropDown();
- }
- } else {
- Ownnote.Share.showDropDown(itemType, path, appendTo, link, possiblePermissions);
- }
- }
- });
-
- $(this).click(function (event) {
- var target = $(event.target);
- var isMatched = !target.is('.drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon')
- && !target.closest('#ui-datepicker-div').length &&
- !target.closest('.ui-autocomplete').length;
- if (Ownnote.Share.droppedDown && isMatched &&
- $('#dropdown').has(event.target).length === 0) {
- Ownnote.Share.hideDropDown();
- }
- });
-
- $(document).on('click', '#dropdown .showCruds', function (e) {
-
- $(this).parent().find('.cruds').toggle();
- return false;
- });
-
- $(document).on('click', '#dropdown .unshare', function () {
- var $li = $(this).closest('li');
- var shareType = $li.data('share-type');
- var shareWith = $li.attr('data-share-with');
- var shareId = $li.attr('data-id');
- var itemSource = $li.data('item-source');
- var $button = $(this);
-
- if (!$button.is('a')) {
- $button = $button.closest('a');
- }
-
- if ($button.hasClass('icon-loading-small')) {
- // deletion in progress
- return false;
- }
- $button.empty().addClass('icon-loading-small');
- Ownnote.Share.unshare(itemSource, shareType, shareWith, function () {
- $li.remove();
- var index = Ownnote.Share.itemShares[shareType].indexOf(shareWith);
- Ownnote.Share.itemShares[shareType].splice(index, 1);
- // updated list of shares
- Ownnote.Share.currentShares[shareType].splice(index, 1);
- // todo: update listing
- });
-
- return false;
- });
-
- $(document).on('change', '#dropdown .permissions', function () {
- var $li = $(this).closest('li');
- var checkboxes = $('.permissions', $li);
- if ($(this).attr('name') == 'edit') {
- var checked = $(this).is(':checked');
- // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
- $(checkboxes).filter('input[name="create"]').attr('checked', checked);
- $(checkboxes).filter('input[name="update"]').attr('checked', checked);
- $(checkboxes).filter('input[name="delete"]').attr('checked', checked);
- } else {
- // Uncheck Edit if Create, Update, and Delete are not checked
- if (!$(this).is(':checked')
- && !$(checkboxes).filter('input[name="create"]').is(':checked')
- && !$(checkboxes).filter('input[name="update"]').is(':checked')
- && !$(checkboxes).filter('input[name="delete"]').is(':checked')) {
- $(checkboxes).filter('input[name="edit"]').attr('checked', false);
- // Check Edit if Create, Update, or Delete is checked
- } else if (($(this).attr('name') == 'create'
- || $(this).attr('name') == 'update'
- || $(this).attr('name') == 'delete')) {
- $(checkboxes).filter('input[name="edit"]').attr('checked', true);
- }
- }
- var permissions = OC.PERMISSION_READ;
- $(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(
- function (index, checkbox) {
- permissions += $(checkbox).data('permissions');
- });
- Ownnote.Share.setPermissions(
- $li.attr('data-item-source'),
- $li.attr('data-share-type'),
- $li.attr('data-share-with'),
- permissions
- );
- });
-
- $(document).on('change', '#dropdown #linkCheckbox', function () {
- var $dropDown = $('#dropdown');
- var path = $dropDown.data('item-source');
- var shareId = $('#linkCheckbox').data('id');
- var shareWith = '';
- var publicUpload = 0;
- var $loading = $dropDown.find('#link .icon-loading-small');
- var $button = $(this);
-
- if (!$loading.hasClass('hidden')) {
- // already in progress
- return false;
- }
-
- if (this.checked) {
- // Reset password placeholder
- $('#linkPassText').attr('placeholder',
- t('core', 'Choose a password for the public link'));
- // Reset link
- $('#linkText').val('');
- $('#showPassword').prop('checked', false);
- $('#linkPass').hide();
- $('#sharingDialogAllowPublicUpload').prop('checked', false);
- $('#expirationCheckbox').prop('checked', false);
- $('#expirationDate').hide();
- var expireDateString = '';
- // Create a link
- if (oc_appconfig.core.enforcePasswordForPublicLink === false) {
- expireDateString = Ownnote.Share.getDefaultExpirationDate();
- $loading.removeClass('hidden');
- $button.addClass('hidden');
- $button.prop('disabled', true);
- Ownnote.Share.share(
- path,
- Ownnote.Share.SHARE_TYPE_LINK,
- shareWith,
- publicUpload,
- null,
- OC.PERMISSION_READ,
- function (data) {
- $loading.addClass('hidden');
- $button.removeClass('hidden');
- $button.prop('disabled', false);
- Ownnote.Share.showLink(data.id, data.token, null);
- });
- } else {
- $('#linkPass').slideToggle(OC.menuSpeed);
- $('#linkPassText').focus();
- }
- if (expireDateString !== '') {
- Ownnote.Share.showExpirationDate(expireDateString);
- }
- } else {
- // Delete private link
- Ownnote.Share.hideLink();
- $('#expiration').slideUp(OC.menuSpeed);
- if ($('#linkText').val() !== '') {
- $loading.removeClass('hidden');
- $button.addClass('hidden');
- $button.prop('disabled', true);
- Ownnote.Share.unshare(shareId, function () {
- $loading.addClass('hidden');
- $button.removeClass('hidden');
- $button.prop('disabled', false);
- Ownnote.Share.itemShares[Ownnote.Share.SHARE_TYPE_LINK] = false;
- });
- }
- }
- });
-
- $(document).on('click', '#dropdown #linkText', function () {
- $(this).focus();
- $(this).select();
- });
-
- // Handle the Allow Public Upload Checkbox
- $(document).on('click', '#sharingDialogAllowPublicUpload', function () {
-
- // Gather data
- var $dropDown = $('#dropdown');
- var shareId = $('#linkCheckbox').data('id');
- var allowPublicUpload = $(this).is(':checked');
- var $button = $(this);
- var $loading = $dropDown.find('#allowPublicUploadWrapper .icon-loading-small');
-
- if (!$loading.hasClass('hidden')) {
- // already in progress
- return false;
- }
-
- // Update the share information
- $button.addClass('hidden');
- $button.prop('disabled', true);
- $loading.removeClass('hidden');
- //(path, shareType, shareWith, publicUpload, password, permissions)
- $.ajax({
- url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'shares/' + shareId +
- '?format=json',
- type: 'PUT',
- data: {
- publicUpload: allowPublicUpload
- }
- }).done(function () {
- $loading.addClass('hidden');
- $button.removeClass('hidden');
- $button.prop('disabled', false);
- });
- });
-
- $(document).on('click', '#dropdown #showPassword', function () {
- $('#linkPass').slideToggle(OC.menuSpeed);
- if (!$('#showPassword').is(':checked')) {
- var shareId = $('#linkCheckbox').data('id');
- var $loading = $('#showPassword .icon-loading-small');
-
- $loading.removeClass('hidden');
- $.ajax({
- url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'shares/' + shareId +
- '?format=json',
- type: 'PUT',
- data: {
- password: null
- }
- }).done(function () {
- $loading.addClass('hidden');
- $('#linkPassText').attr('placeholder',
- t('core', 'Choose a password for the public link'));
- });
- } else {
- $('#linkPassText').focus();
- }
- });
-
- $(document).on('focusout keyup', '#dropdown #linkPassText', function (event) {
- var linkPassText = $('#linkPassText');
- if (linkPassText.val() != '' && (event.type == 'focusout' || event.keyCode == 13)) {
- var dropDown = $('#dropdown');
- var $loading = dropDown.find('#linkPass .icon-loading-small');
- var shareId = $('#linkCheckbox').data('id');
-
- $loading.removeClass('hidden');
- $.ajax({
- url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'shares/' + shareId +
- '?format=json',
- type: 'PUT',
- data: {
- password: $('#linkPassText').val()
- }
- }).done(function (data) {
- $loading.addClass('hidden');
- linkPassText.val('');
- linkPassText.attr('placeholder', t('core', 'Password protected'));
-
- if (oc_appconfig.core.enforcePasswordForPublicLink) {
- Ownnote.Share.showLink(data.id, data.token, "password set");
- }
- }).fail(function (xhr) {
- var result = xhr.responseJSON;
- $loading.addClass('hidden');
- linkPassText.val('');
- linkPassText.attr('placeholder', result.data.message);
- });
- }
- });
-
- $(document).on('click', '#dropdown #expirationCheckbox', function () {
- if (this.checked) {
- Ownnote.Share.showExpirationDate('');
- } else {
- var shareId = $('#linkCheckbox').data('id');
- $.ajax({
- url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'shares/' + shareId +
- '?format=json',
- type: 'PUT',
- data: {
- expireDate: ''
- }
- }).done(function () {
- $('#expirationDate').slideUp(OC.menuSpeed);
- if (oc_appconfig.core.defaultExpireDateEnforced === false) {
- $('#defaultExpireMessage').slideDown(OC.menuSpeed);
- }
- }).fail(function () {
- OC.dialogs.alert(t('core', 'Error unsetting expiration date'),
- t('core', 'Error'));
- });
- }
- });
-
- $(document).on('change', '#dropdown #expirationDate', function () {
- var shareId = $('#linkCheckbox').data('id');
- if (!shareId) {
- return;
- }
- $(this).tooltip('hide');
- $(this).removeClass('error');
-
- $.ajax({
- url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'shares/' + shareId +
- '?format=json',
- type: 'PUT',
- data: {
- expireDate: $(this).val()
- }
- }).done(function () {
- if (oc_appconfig.core.defaultExpireDateEnforced === 'no') {
- $('#defaultExpireMessage').slideUp(OC.menuSpeed);
- }
- }).fail(function (xhr) {
- var result = xhr.responseJSON;
- var expirationDateField = $('#dropdown #expirationDate');
- if (result && !result.ocs.meta.message) {
- expirationDateField.attr('original-title',
- t('core', 'Error setting expiration date'));
- } else {
- expirationDateField.attr('original-title', result.ocs.meta.message);
- }
- expirationDateField.tooltip({placement: 'top'});
- expirationDateField.tooltip('show');
- expirationDateField.addClass('error');
- });
- });
-
-
- $(document).on('submit', '#dropdown #emailPrivateLink', function (event) {
- event.preventDefault();
- var link = $('#linkText').val();
- var itemType = $('#dropdown').data('item-type');
- var itemSource = $('#dropdown').data('item-source');
- var fileName = $('.last').children()[0].innerText;
- var email = $('#email').val();
- var expirationDate = '';
- if ($('#expirationCheckbox').is(':checked') === true) {
- expirationDate = $("#expirationDate").val();
- }
- if (email != '') {
- $('#email').prop('disabled', true);
- $('#email').val(t('core', 'Sending ...'));
- $('#emailButton').prop('disabled', true);
-
- $.post(OC.filePath('core', 'ajax', 'share.php'), {
- action: 'email',
- toaddress: email,
- link: link,
- file: fileName,
- itemType: itemType,
- itemSource: itemSource,
- expiration: expirationDate
- },
- function (result) {
- $('#email').prop('disabled', false);
- $('#emailButton').prop('disabled', false);
- if (result && result.status == 'success') {
- $('#email').css('font-weight', 'bold').val(t('core', 'Email sent'));
- setTimeout(function () {
- $('#email').css('font-weight', 'normal').val('');
- }, 2000);
- } else {
- OC.dialogs.alert(result.data.message, t('core', 'Error while sharing'));
- }
- });
- }
- });
-
- $(document).on('click', '#dropdown input[name=mailNotification]', function () {
- var $li = $(this).closest('li');
- var itemType = $('#dropdown').data('item-type');
- var itemSource = $('a.share').data('item-source');
- var action = '';
- if (this.checked) {
- action = 'informRecipients';
- } else {
- action = 'informRecipientsDisabled';
- }
- var shareType = $li.data('share-type');
- var shareWith = $li.attr('data-share-with');
- $.post(OC.filePath('core', 'ajax', 'share.php'), {
- action: action,
- recipient: shareWith,
- shareType: shareType,
- itemSource: itemSource,
- itemType: itemType
- }, function (result) {
- if (result.status !== 'success') {
- OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning'));
- }
- });
-
- });
-});
-
-$(document).ready(function () {
- var isSingleViewMode = (app_config.user.view_mode === 'single');
- var $body = $('body');
- if(isSingleViewMode){
- $('#ownnote').find('.view-container').width('200%');
- }
- $body.on('click', '.file.pointer, #new', function (e) {
- if ($(window).width() <= 994 || isSingleViewMode) {
- setTimeout(function () {
- $('#ownnote').animate({scrollLeft: $(window).width()}, 750);
- }, 50);
- }
- });
- $body.on('click', '#canceledit, #grouplist .group', function (e) {
- if ($(window).width() <= 994 || isSingleViewMode) {
- $('#ownnote').animate({scrollLeft: 0}, 750);
- }
- });
-
- $body.on('click', '.toggle-view-mode', function () {
- if(app_config.user.view_mode === 'single') {
- $('#ownnote').find('.view-container').animate({width: '100%'}, 750);
- $(this).find('i').removeClass('fa-arrows-h').addClass('fa-columns');
- isSingleViewMode = false;
- app_config.user.view_mode = 'col';
- } else if(app_config.user.view_mode === 'col'){
- $('#ownnote').find('.view-container').animate({width: '200%'}, 750);
- $(this).find('i').removeClass('fa-columns').addClass('fa-arrows-h');
- isSingleViewMode = true;
- app_config.user.view_mode = 'single';
- }
- });
-});
diff --git a/lib/Fixtures/ShareFix.php b/lib/Fixtures/ShareFix.php
deleted file mode 100644
index 77a4982..0000000
--- a/lib/Fixtures/ShareFix.php
+++ /dev/null
@@ -1,886 +0,0 @@
-.
- *
- */
-
-namespace OCA\NextNote\Fixtures;
-
-use OC\Share\Helper;
-use OC\Share\Share;
-use OCA\NextNote\Utility\Utils;
-
-class ShareFix extends Share {
-
- private static function log($level, $message, $context) {
- \OC::$server->getLogger()->log($level, $message, $context);
- }
-
- /**
- * Set the permissions of an item for a specific user or group
- *
- * @param string $itemType
- * @param string $itemSource
- * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string $shareWith User or group the item is being shared with
- * @param int $permissions CRUDS permissions
- * @return boolean true on success or false on failure
- * @throws \Exception when trying to grant more permissions then the user has himself
- */
- public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
- $l = \OC::$server->getL10N('lib');
- $connection = \OC::$server->getDatabaseConnection();
-
- $intArrayToLiteralArray = function ($intArray, $eb) {
- return array_map(function ($int) use ($eb) {
- return $eb->literal((int)$int, 'integer');
- }, $intArray);
- };
- $sanitizeItem = function ($item) {
- $item['id'] = (int)$item['id'];
- $item['premissions'] = (int)$item['permissions'];
- return $item;
- };
-
- if ($rootItem = self::getItems($itemType, $itemSource, $shareType, $shareWith,
- \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) {
- // Check if this item is a reshare and verify that the permissions
- // granted don't exceed the parent shared item
- if (isset($rootItem['parent'])) {
- $qb = $connection->getQueryBuilder();
- $qb->select('permissions')
- ->from('share')
- ->where($qb->expr()->eq('id', $qb->createParameter('id')))
- ->setParameter(':id', $rootItem['parent']);
- $dbresult = $qb->execute();
-
- $result = $dbresult->fetch();
- $dbresult->closeCursor();
- if (~(int)$result['permissions'] & $permissions) {
- $message = 'Setting permissions for %s failed,'
- . ' because the permissions exceed permissions granted to %s';
- $message_t = $l->t('Setting permissions for %s failed, because the permissions exceed permissions granted to %s', array($itemSource, \OC_User::getUser()));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSource, \OC_User::getUser()), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- }
- $qb = $connection->getQueryBuilder();
- $qb->update('share')
- ->set('permissions', $qb->createParameter('permissions'))
- ->where($qb->expr()->eq('id', $qb->createParameter('id')))
- ->setParameter(':id', $rootItem['id'])
- ->setParameter(':permissions', $permissions);
- $qb->execute();
- if ($itemType === 'file' || $itemType === 'folder') {
- \OC_Hook::emit('NextNote\Fixtures\ShareFix', 'post_update_permissions', array(
- 'itemType' => $itemType,
- 'itemSource' => $itemSource,
- 'shareType' => $shareType,
- 'shareWith' => $shareWith,
- 'uidOwner' => \OC_User::getUser(),
- 'permissions' => $permissions,
- 'path' => $rootItem['path'],
- 'share' => $rootItem
- ));
- }
-
- // Share id's to update with the new permissions
- $ids = [];
- $items = [];
-
- // Check if permissions were removed
- if ((int)$rootItem['permissions'] & ~$permissions) {
- // If share permission is removed all reshares must be deleted
- if (($rootItem['permissions'] & \OCP\Constants::PERMISSION_SHARE) && (~$permissions & \OCP\Constants::PERMISSION_SHARE)) {
- // delete all shares, keep parent and group children
- Helper::delete($rootItem['id'], true, null, null, true);
- }
-
- // Remove permission from all children
- $parents = [$rootItem['id']];
- while (!empty($parents)) {
- $parents = $intArrayToLiteralArray($parents, $qb->expr());
- $qb = $connection->getQueryBuilder();
- $qb->select('id', 'permissions', 'item_type')
- ->from('share')
- ->where($qb->expr()->in('parent', $parents));
- $result = $qb->execute();
- // Reset parents array, only go through loop again if
- // items are found that need permissions removed
- $parents = [];
- while ($item = $result->fetch()) {
- $item = $sanitizeItem($item);
-
- $items[] = $item;
- // Check if permissions need to be removed
- if ($item['permissions'] & ~$permissions) {
- // Add to list of items that need permissions removed
- $ids[] = $item['id'];
- $parents[] = $item['id'];
- }
- }
- $result->closeCursor();
- }
-
- // Remove the permissions for all reshares of this item
- if (!empty($ids)) {
- $ids = "'" . implode("','", $ids) . "'";
- // TODO this should be done with Doctrine platform objects
- if (\OC::$server->getConfig()->getSystemValue("dbtype") === 'oci') {
- $andOp = 'BITAND(`permissions`, ?)';
- } else {
- $andOp = '`permissions` & ?';
- }
- $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `permissions` = ' . $andOp
- . ' WHERE `id` IN (' . $ids . ')');
- $query->execute(array($permissions));
- }
-
- }
-
- /*
- * Permissions were added
- * Update all USERGROUP shares. (So group shares where the user moved their mountpoint).
- */
- if ($permissions & ~(int)$rootItem['permissions']) {
- $qb = $connection->getQueryBuilder();
- $qb->select('id', 'permissions', 'item_type')
- ->from('share')
- ->where($qb->expr()->eq('parent', $qb->createParameter('parent')))
- ->andWhere($qb->expr()->eq('share_type', $qb->createParameter('share_type')))
- ->andWhere($qb->expr()->neq('permissions', $qb->createParameter('shareDeleted')))
- ->setParameter(':parent', (int)$rootItem['id'])
- ->setParameter(':share_type', 2)
- ->setParameter(':shareDeleted', 0);
- $result = $qb->execute();
-
- $ids = [];
- while ($item = $result->fetch()) {
- $item = $sanitizeItem($item);
- $items[] = $item;
- $ids[] = $item['id'];
- }
- $result->closeCursor();
-
- // Add permssions for all USERGROUP shares of this item
- if (!empty($ids)) {
- $ids = $intArrayToLiteralArray($ids, $qb->expr());
-
- $qb = $connection->getQueryBuilder();
- $qb->update('share')
- ->set('permissions', $qb->createParameter('permissions'))
- ->where($qb->expr()->in('id', $ids))
- ->setParameter(':permissions', $permissions);
- $qb->execute();
- }
- }
-
- foreach ($items as $item) {
- \OC_Hook::emit('OCP\Share', 'post_update_permissions', ['share' => $item]);
- }
-
- return true;
- }
- $message = 'Setting permissions for %s failed, because the item was not found';
- $message_t = $l->t('Setting permissions for %s failed, because the item was not found', array($itemSource));
-
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSource), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
-
- /**
- * Get the item of item type shared with the current user
- *
- * @param string $itemType
- * @param string $itemTarget
- * @param int $format (optional) Format type must be defined by the backend
- * @param mixed $parameters (optional)
- * @param boolean $includeCollections (optional)
- * @return mixed Return depends on format
- */
- public static function getItemSharedWith($itemType, $itemTarget, $format = parent::FORMAT_NONE,
- $parameters = null, $includeCollections = false) {
-
- return self::getItems($itemType, $itemTarget, parent::$shareTypeUserAndGroups, \OC_User::getUser(), null, self::FORMAT_NONE,
- $parameters, 1, $includeCollections);
- }
-
-
- /**
- * Get all users an item is shared with
- *
- * @param string $itemType
- * @param string $itemSource
- * @return array Return array of users
- */
- public static function getUsersItemShared($itemType, $itemSource) {
-
- $users = array();
- $queryArgs = [
- $itemType,
- $itemSource
- ];
- $where = '`item_type` = ?';
- $where .= ' AND `item_source`= ?';
- $q = 'SELECT * FROM `*PREFIX*share` WHERE ' . $where;
- $query = \OC_DB::prepare($q);
-
- $result = $query->execute($queryArgs);
- while ($row = $result->fetchRow()) {
- if ($row['share_type'] == self::SHARE_TYPE_USER) {
- $u = Utils::getUserInfo($row['share_with']);
- $users[] = $u['display_name'];
- }
- if ($row['share_type'] == self::SHARE_TYPE_GROUP) {
- $users[] = $row['share_with'];
- }
- }
-
- return $users;
- }
-
-
- /**
- * Share an item with a user, group, or via private link
- *
- * @param string $itemType
- * @param string $itemSource
- * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string $shareWith User or group the item is being shared with
- * @param int $permissions CRUDS
- * @param string $itemSourceName
- * @param \DateTime|null $expirationDate
- * @param bool|null $passwordChanged
- * @return boolean|string Returns true on success or false on failure, Returns token on success for links
- * @throws \OC\HintException when the share type is remote and the shareWith is invalid
- * @throws \Exception
- * @since 5.0.0 - parameter $itemSourceName was added in 6.0.0, parameter $expirationDate was added in 7.0.0, parameter $passwordChanged added in 9.0.0
- */
- public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null) {
-
- $backend = self::getBackend($itemType);
- $l = \OC::$server->getL10N('lib');
-
- if ($backend->isShareTypeAllowed($shareType) === false) {
- $message = 'Sharing %s failed, because the backend does not allow shares from type %i';
- $message_t = $l->t('Sharing %s failed, because the backend does not allow shares from type %i', array($itemSourceName, $shareType));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $shareType), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
-
- $uidOwner = \OC_User::getUser();
- $shareWithinGroupOnly = self::shareWithGroupMembersOnly();
-
- if (is_null($itemSourceName)) {
- $itemSourceName = $itemSource;
- }
- $itemName = $itemSourceName;
-
- //Validate expirationDate
- if ($expirationDate !== null) {
- try {
- /*
- * Reuse the validateExpireDate.
- * We have to pass time() since the second arg is the time
- * the file was shared, since it is not shared yet we just use
- * the current time.
- */
- $expirationDate = self::validateExpireDate($expirationDate->format('Y-m-d'), time(), $itemType, $itemSource);
- } catch (\Exception $e) {
- throw new \OC\HintException($e->getMessage(), $e->getMessage(), 404);
- }
- }
-
- // Verify share type and sharing conditions are met
- if ($shareType === self::SHARE_TYPE_USER) {
- if ($shareWith == $uidOwner) {
- $message = 'Sharing %s failed, because you can not share with yourself';
- $message_t = $l->t('Sharing %s failed, because you can not share with yourself', [$itemName]);
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- if (!\OC::$server->getUserManager()->userExists($shareWith)) {
- $message = 'Sharing %s failed, because the user %s does not exist';
- $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- if ($shareWithinGroupOnly) {
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
- $userOwner = $userManager->get($uidOwner);
- $userShareWith = $userManager->get($shareWith);
- $groupsOwner = [];
- $groupsShareWith = [];
- if ($userOwner) {
- $groupsOwner = $groupManager->getUserGroupIds($userOwner);
- }
- if ($userShareWith) {
- $groupsShareWith = $groupManager->getUserGroupIds($userShareWith);
- }
- $inGroup = array_intersect($groupsOwner, $groupsShareWith);
- if (empty($inGroup)) {
- $message = 'Sharing %s failed, because the user '
- . '%s is not a member of any groups that %s is a member of';
- $message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemName, $shareWith, $uidOwner));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemName, $shareWith, $uidOwner), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- }
- // Check if the item source is already shared with the user, either from the same owner or a different user
- if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups,
- $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
- // Only allow the same share to occur again if it is the same
- // owner and is not a user share, this use case is for increasing
- // permissions for a specific user
- if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
- $message = 'Sharing %s failed, because this item is already shared with %s';
- $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- }
- if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_USER,
- $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
- // Only allow the same share to occur again if it is the same
- // owner and is not a user share, this use case is for increasing
- // permissions for a specific user
- if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
- $message = 'Sharing %s failed, because this item is already shared with user %s';
- $message_t = $l->t('Sharing %s failed, because this item is already shared with user %s', array($itemSourceName, $shareWith));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::ERROR);
- throw new \Exception($message_t);
- }
- }
- } else if ($shareType === self::SHARE_TYPE_GROUP) {
- if (!\OC::$server->getGroupManager()->groupExists($shareWith)) {
- $message = 'Sharing %s failed, because the group %s does not exist';
- $message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- if ($shareWithinGroupOnly) {
- $group = \OC::$server->getGroupManager()->get($shareWith);
- $user = \OC::$server->getUserManager()->get($uidOwner);
- if (!$group || !$user || !$group->inGroup($user)) {
- $message = 'Sharing %s failed, because '
- . '%s is not a member of the group %s';
- $message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $uidOwner, $shareWith), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- }
- // Check if the item source is already shared with the group, either from the same owner or a different user
- // The check for each user in the group is done inside the put() function
- if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith,
- null, self::FORMAT_NONE, null, 1, true, true)) {
-
- if ($checkExists['share_with'] === $shareWith && $checkExists['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) {
- $message = 'Sharing %s failed, because this item is already shared with %s';
- $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- }
- // Convert share with into an array with the keys group and users
- $group = $shareWith;
- $shareWith = array();
- $shareWith['group'] = $group;
-
-
- $groupObject = \OC::$server->getGroupManager()->get($group);
- $userIds = [];
- if ($groupObject) {
- $users = $groupObject->searchUsers('');
- foreach ($users as $user) {
- $userIds[] = $user->getUID();
- }
- }
-
-
- $shareWith['users'] = array_diff($userIds, array($uidOwner));
- } else {
- // Future share types need to include their own conditions
- $message = 'Share type %s is not valid for %s';
- $message_t = $l->t('Share type %s is not valid for %s', array($shareType, $itemSource));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $shareType, $itemSource), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
-
- // Put the item into the database
- $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName, $expirationDate);
-
- return $result ? true : false;
- }
-
- /**
- * Put shared item into the database
- *
- * @param string $itemType Item type
- * @param string $itemSource Item source
- * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string $shareWith User or group the item is being shared with
- * @param string $uidOwner User that is the owner of shared item
- * @param int $permissions CRUDS permissions
- * @param boolean|array $parentFolder Parent folder target (optional)
- * @param string $token (optional)
- * @param string $itemSourceName name of the source item (optional)
- * @param \DateTime $expirationDate (optional)
- * @throws \Exception
- * @return mixed id of the new share or false
- */
- private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
- $permissions, $parentFolder = null, $token = null, $itemSourceName = null, \DateTime $expirationDate = null) {
-
- $queriesToExecute = array();
- $suggestedItemTarget = null;
- $groupFileTarget = $fileTarget = $suggestedFileTarget = $filePath = '';
- $groupItemTarget = $itemTarget = $fileSource = $parent = 0;
-
- $result = self::checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate);
- if (!empty($result)) {
- $parent = $result['parent'];
- $itemSource = $result['itemSource'];
- $fileSource = $result['fileSource'];
- $suggestedItemTarget = $result['suggestedItemTarget'];
- $suggestedFileTarget = $result['suggestedFileTarget'];
- $filePath = $result['filePath'];
- }
-
- $isGroupShare = false;
- if ($shareType == self::SHARE_TYPE_GROUP) {
- $isGroupShare = true;
- if (isset($shareWith['users'])) {
- $users = $shareWith['users'];
- } else {
- $group = \OC::$server->getGroupManager()->get($shareWith['group']);
- if ($group) {
- $users = $group->searchUsers('');
- $userIds = [];
- foreach ($users as $user) {
- $userIds[] = $user->getUID();
- }
- $users = $userIds;
- } else {
- $users = [];
- }
- }
- // remove current user from list
- if (in_array(\OC::$server->getUserSession()->getUser()->getUID(), $users)) {
- unset($users[array_search(\OC::$server->getUserSession()->getUser()->getUID(), $users)]);
- }
- $groupItemTarget = Helper::generateTarget($itemType, $itemSource,
- $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget);
- $groupFileTarget = Helper::generateTarget($itemType, $itemSource,
- $shareType, $shareWith['group'], $uidOwner, $filePath);
-
- // add group share to table and remember the id as parent
- $queriesToExecute['groupShare'] = array(
- 'itemType' => $itemType,
- 'itemSource' => $itemSource,
- 'itemTarget' => $groupItemTarget,
- 'shareType' => $shareType,
- 'shareWith' => $shareWith['group'],
- 'uidOwner' => $uidOwner,
- 'permissions' => $permissions,
- 'shareTime' => time(),
- 'fileSource' => $fileSource,
- 'fileTarget' => $groupFileTarget,
- 'token' => $token,
- 'parent' => $parent,
- 'expiration' => $expirationDate,
- );
-
- } else {
- $users = array($shareWith);
- $itemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
- $suggestedItemTarget);
- }
-
- $run = true;
- $error = '';
- $preHookData = array(
- 'itemType' => $itemType,
- 'itemSource' => $itemSource,
- 'shareType' => $shareType,
- 'uidOwner' => $uidOwner,
- 'permissions' => $permissions,
- 'fileSource' => $fileSource,
- 'expiration' => $expirationDate,
- 'token' => $token,
- 'run' => &$run,
- 'error' => &$error
- );
-
- $preHookData['itemTarget'] = $isGroupShare ? $groupItemTarget : $itemTarget;
- $preHookData['shareWith'] = $isGroupShare ? $shareWith['group'] : $shareWith;
-
- \OC_Hook::emit(\OCP\Share::class, 'pre_shared', $preHookData);
-
- if ($run === false) {
- throw new \Exception($error);
- }
-
- foreach ($users as $user) {
- $sourceId = ($itemType === 'file' || $itemType === 'folder') ? $fileSource : $itemSource;
- $sourceExists = self::getItemSharedWithBySource($itemType, $sourceId, self::FORMAT_NONE, null, true, $user);
-
- $userShareType = $isGroupShare ? self::$shareTypeGroupUserUnique : $shareType;
-
- if ($sourceExists && $sourceExists['item_source'] === $itemSource) {
- $fileTarget = $sourceExists['file_target'];
- $itemTarget = $sourceExists['item_target'];
-
- // for group shares we don't need a additional entry if the target is the same
- if ($isGroupShare && $groupItemTarget === $itemTarget) {
- continue;
- }
-
- } elseif (!$sourceExists && !$isGroupShare) {
-
- $itemTarget = Helper::generateTarget($itemType, $itemSource, $userShareType, $user,
- $uidOwner, $suggestedItemTarget, $parent);
- if (isset($fileSource)) {
- if ($parentFolder) {
- if ($parentFolder === true) {
- $fileTarget = Helper::generateTarget('file', $filePath, $userShareType, $user,
- $uidOwner, $suggestedFileTarget, $parent);
- if ($fileTarget != $groupFileTarget) {
- $parentFolders[$user]['folder'] = $fileTarget;
- }
- } else if (isset($parentFolder[$user])) {
- $fileTarget = $parentFolder[$user]['folder'] . $itemSource;
- $parent = $parentFolder[$user]['id'];
- }
- } else {
- $fileTarget = Helper::generateTarget('file', $filePath, $userShareType,
- $user, $uidOwner, $suggestedFileTarget, $parent);
- }
- } else {
- $fileTarget = null;
- }
-
- } else {
-
- // group share which doesn't exists until now, check if we need a unique target for this user
-
- $itemTarget = Helper::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $user,
- $uidOwner, $suggestedItemTarget, $parent);
-
- // do we also need a file target
- if (isset($fileSource)) {
- $fileTarget = Helper::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $user,
- $uidOwner, $suggestedFileTarget, $parent);
- } else {
- $fileTarget = null;
- }
-
- if (($itemTarget === $groupItemTarget) &&
- (!isset($fileSource) || $fileTarget === $groupFileTarget)) {
- continue;
- }
- }
-
- $queriesToExecute[] = array(
- 'itemType' => $itemType,
- 'itemSource' => $itemSource,
- 'itemTarget' => $itemTarget,
- 'shareType' => $userShareType,
- 'shareWith' => $user,
- 'uidOwner' => $uidOwner,
- 'permissions' => $permissions,
- 'shareTime' => time(),
- 'fileSource' => $fileSource,
- 'fileTarget' => $fileTarget,
- 'token' => $token,
- 'parent' => $parent,
- 'expiration' => $expirationDate,
- );
-
- }
-
- $id = false;
- if ($isGroupShare) {
- $id = self::insertShare($queriesToExecute['groupShare']);
- // Save this id, any extra rows for this group share will need to reference it
- $parent = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share');
- unset($queriesToExecute['groupShare']);
- }
-
- foreach ($queriesToExecute as $shareQuery) {
- $shareQuery['parent'] = $parent;
- $id = self::insertShare($shareQuery);
- }
-
- $postHookData = array(
- 'itemType' => $itemType,
- 'itemSource' => $itemSource,
- 'parent' => $parent,
- 'shareType' => $shareType,
- 'uidOwner' => $uidOwner,
- 'permissions' => $permissions,
- 'fileSource' => $fileSource,
- 'id' => $parent,
- 'token' => $token,
- 'expirationDate' => $expirationDate,
- );
-
- $postHookData['shareWith'] = $isGroupShare ? $shareWith['group'] : $shareWith;
- $postHookData['itemTarget'] = $isGroupShare ? $groupItemTarget : $itemTarget;
- $postHookData['fileTarget'] = $isGroupShare ? $groupFileTarget : $fileTarget;
-
- \OC_Hook::emit(\OCP\Share::class, 'post_shared', $postHookData);
-
-
- return $id ? $id : false;
- }
-
- /**
- * @param string $itemType
- * @param string $itemSource
- * @param int $shareType
- * @param string $shareWith
- * @param string $uidOwner
- * @param int $permissions
- * @param string|null $itemSourceName
- * @param null|\DateTime $expirationDate
- */
- private static function checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate) {
- $backend = self::getBackend($itemType);
-
- $l = \OC::$server->getL10N('lib');
- $result = array();
-
- $column = ($itemType === 'file' || $itemType === 'folder') ? 'file_source' : 'item_source';
-
- $checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true);
- if ($checkReshare) {
- // Check if attempting to share back to owner
- if ($checkReshare['uid_owner'] == $shareWith && $shareType == self::SHARE_TYPE_USER) {
- $message = 'Sharing %s failed, because the user %s is the original sharer';
- $message_t = $l->t('Sharing failed, because the user %s is the original sharer', [$shareWith]);
-
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- }
-
- if ($checkReshare && $checkReshare['uid_owner'] !== \OC_User::getUser()) {
- // Check if share permissions is granted
- if (self::isResharingAllowed() && (int)$checkReshare['permissions'] & \OCP\Constants::PERMISSION_SHARE) {
- if (~(int)$checkReshare['permissions'] & $permissions) {
- $message = 'Sharing %s failed, because the permissions exceed permissions granted to %s';
- $message_t = $l->t('Sharing %s failed, because the permissions exceed permissions granted to %s', array($itemSourceName, $uidOwner));
-
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName, $uidOwner), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- } else {
- // TODO Don't check if inside folder
- $result['parent'] = $checkReshare['id'];
-
- $result['expirationDate'] = $expirationDate;
- // $checkReshare['expiration'] could be null and then is always less than any value
- if (isset($checkReshare['expiration']) && $checkReshare['expiration'] < $expirationDate) {
- $result['expirationDate'] = $checkReshare['expiration'];
- }
-
- // only suggest the same name as new target if it is a reshare of the
- // same file/folder and not the reshare of a child
- if ($checkReshare[$column] === $itemSource) {
- $result['filePath'] = $checkReshare['file_target'];
- $result['itemSource'] = $checkReshare['item_source'];
- $result['fileSource'] = $checkReshare['file_source'];
- $result['suggestedItemTarget'] = $checkReshare['item_target'];
- $result['suggestedFileTarget'] = $checkReshare['file_target'];
- } else {
- $result['filePath'] = ($backend instanceof \OCP\Share_Backend_File_Dependent) ? $backend->getFilePath($itemSource, $uidOwner) : null;
- $result['suggestedItemTarget'] = null;
- $result['suggestedFileTarget'] = null;
- $result['itemSource'] = $itemSource;
- $result['fileSource'] = ($backend instanceof \OCP\Share_Backend_File_Dependent) ? $itemSource : null;
- }
- }
- } else {
- $message = 'Sharing %s failed, because resharing is not allowed';
- $message_t = $l->t('Sharing %s failed, because resharing is not allowed', array($itemSourceName));
-
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- } else {
- $result['parent'] = null;
- $result['suggestedItemTarget'] = null;
- $result['suggestedFileTarget'] = null;
- $result['itemSource'] = $itemSource;
- $result['expirationDate'] = $expirationDate;
- if (!$backend->isValidSource($itemSource, $uidOwner)) {
- $message = 'Sharing %s failed, because the sharing backend for '
- . '%s could not find its source';
- $message_t = $l->t('Sharing %s failed, because the sharing backend for %s could not find its source', array($itemSource, $itemType));
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSource, $itemType), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- if ($backend instanceof \OCP\Share_Backend_File_Dependent) {
- $result['filePath'] = $backend->getFilePath($itemSource, $uidOwner);
- if ($itemType == 'file' || $itemType == 'folder') {
- $result['fileSource'] = $itemSource;
- } else {
- $meta = \OC\Files\Filesystem::getFileInfo($result['filePath']);
- $result['fileSource'] = $meta['fileid'];
- }
- if ($result['fileSource'] == -1) {
- $message = 'Sharing %s failed, because the file could not be found in the file cache';
- $message_t = $l->t('Sharing %s failed, because the file could not be found in the file cache', array($itemSource));
-
- self::log('NextNote\Fixtures\ShareFix', sprintf($message, $itemSource), \OCP\Util::DEBUG);
- throw new \Exception($message_t);
- }
- } else {
- $result['filePath'] = null;
- $result['fileSource'] = null;
- }
- }
-
- return $result;
- }
-
- /**
- *
- * @param array $shareData
- * @return mixed false in case of a failure or the id of the new share
- */
- private static function insertShare(array $shareData) {
-
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` ('
- . ' `item_type`, `item_source`, `item_target`, `share_type`,'
- . ' `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,'
- . ' `file_target`, `token`, `parent`, `expiration`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)');
- $query->bindValue(1, $shareData['itemType']);
- $query->bindValue(2, $shareData['itemSource']);
- $query->bindValue(3, $shareData['itemTarget']);
- $query->bindValue(4, $shareData['shareType']);
- $query->bindValue(5, $shareData['shareWith']);
- $query->bindValue(6, $shareData['uidOwner']);
- $query->bindValue(7, $shareData['permissions']);
- $query->bindValue(8, $shareData['shareTime']);
- $query->bindValue(9, $shareData['fileSource']);
- $query->bindValue(10, $shareData['fileTarget']);
- $query->bindValue(11, $shareData['token']);
- $query->bindValue(12, $shareData['parent']);
- $query->bindValue(13, $shareData['expiration'], 'datetime');
- $result = $query->execute();
-
- $id = false;
- if ($result) {
- $id = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share');
- }
-
- return $id;
-
- }
-
- /**
- * validate expiration date if it meets all constraints
- *
- * @param string $expireDate well formatted date string, e.g. "DD-MM-YYYY"
- * @param string $shareTime timestamp when the file was shared
- * @param string $itemType
- * @param string $itemSource
- * @return \DateTime validated date
- * @throws \Exception when the expire date is in the past or further in the future then the enforced date
- */
- private static function validateExpireDate($expireDate, $shareTime, $itemType, $itemSource) {
- $l = \OC::$server->getL10N('lib');
- $date = new \DateTime($expireDate);
- $today = new \DateTime('now');
-
- // if the user doesn't provide a share time we need to get it from the database
- // fall-back mode to keep API stable, because the $shareTime parameter was added later
- $defaultExpireDateEnforced = \OCP\Util::isDefaultExpireDateEnforced();
- if ($defaultExpireDateEnforced && $shareTime === null) {
- $items = self::getItemShared($itemType, $itemSource);
- $firstItem = reset($items);
- $shareTime = (int)$firstItem['stime'];
- }
-
- if ($defaultExpireDateEnforced) {
- // initialize max date with share time
- $maxDate = new \DateTime();
- $maxDate->setTimestamp($shareTime);
- $maxDays = \OC::$server->getConfig()->getAppValue('core', 'shareapi_expire_after_n_days', '7');
- $maxDate->add(new \DateInterval('P' . $maxDays . 'D'));
- if ($date > $maxDate) {
- $warning = 'Cannot set expiration date. Shares cannot expire later than ' . $maxDays . ' after they have been shared';
- $warning_t = $l->t('Cannot set expiration date. Shares cannot expire later than %s after they have been shared', array($maxDays));
- self::log('NextNote\Fixtures\ShareFix', $warning, \OCP\Util::WARN);
- throw new \Exception($warning_t);
- }
- }
-
- if ($date < $today) {
- $message = 'Cannot set expiration date. Expiration date is in the past';
- $message_t = $l->t('Cannot set expiration date. Expiration date is in the past');
- self::log('NextNote\Fixtures\ShareFix', $message, \OCP\Util::WARN);
- throw new \Exception($message_t);
- }
-
- return $date;
- }
-
- public static function getPermissions($itemType, $itemSource, $uid) {
- $uid = \OC::$server->getUserSession()->getUser();
- $gm = \OC::$server->getGroupManager();
-
- $users = array();
- $queryArgs = [
- $itemType,
- $itemSource,
- $uid->getUID()
- ];
- $where = '`item_type` = ?';
- $where .= ' AND `item_source`= ?';
- $where .= ' AND (`share_with` = ? AND `share_type`= 0 ';
-
- $user_groups = $gm->getUserGroupIds($uid);
-
- foreach ($user_groups as $group) {
- $where .= ' OR (`share_with` = ? AND `share_type`=1)';
- $queryArgs[] = $group;
- }
- $where .= ')';
-
- $q = 'SELECT * FROM `*PREFIX*share` WHERE ' . $where;
-
-
- $query = \OC_DB::prepare($q);
-
- $result = $query->execute($queryArgs);
- $permissions = 0;
- while ($row = $result->fetchRow()) {
- if ($row['permissions'] > $permissions) {
- $permissions = $row['permissions'];
- }
- }
-
-
- return $permissions;
- }
-
-}
\ No newline at end of file
diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php
index 37e632c..f8258bf 100644
--- a/lib/Service/NoteService.php
+++ b/lib/Service/NoteService.php
@@ -26,8 +26,6 @@
use OCA\NextNote\Db\Notebook;
use OCA\NextNote\Db\Note;
use OCA\NextNote\Fixtures\ExampleNote;
-use OCA\NextNote\Fixtures\ShareFix;
-use OCA\NextNote\ShareBackend\NextNoteShareBackend;
use OCA\NextNote\Utility\Utils;
use OCA\NextNote\Db\NoteMapper;
@@ -36,13 +34,11 @@ class NoteService {
private $noteMapper;
private $utils;
- private $sharing;
private $groupService;
- public function __construct(NoteMapper $noteMapper, Utils $utils, NextNoteShareBackend $shareBackend, NotebookService $groupService) {
+ public function __construct(NoteMapper $noteMapper, Utils $utils,NotebookService $groupService) {
$this->noteMapper = $noteMapper;
$this->utils = $utils;
- $this->sharing = $shareBackend;
$this->groupService = $groupService;
}
@@ -68,7 +64,8 @@ public function findNotesFromUser($userId, $deleted = false, $grouping = false)
$dbNotes[$n->getId()] = $n;
}
- $sharedNotes = $this->sharing->getSharedNotes();
+ //$sharedNotes = $this->sharing->getSharedNotes();
+ $sharedNotes = [];
$notes = array_merge($dbNotes, $sharedNotes);
return $notes;
}
diff --git a/lib/Service/NotebookService.php b/lib/Service/NotebookService.php
index 21174e5..0d59c28 100644
--- a/lib/Service/NotebookService.php
+++ b/lib/Service/NotebookService.php
@@ -25,7 +25,6 @@
use OCA\NextNote\Db\Notebook;
use OCA\NextNote\Db\NotebookMapper;
-use OCA\NextNote\ShareBackend\NextNoteShareBackend;
use OCA\NextNote\Utility\Utils;
use OCP\AppFramework\Db\Entity;
@@ -34,12 +33,10 @@ class NotebookService {
private $notebookMapper;
private $utils;
- private $sharing;
- public function __construct(NotebookMapper $notebookMapper, Utils $utils, NextNoteShareBackend $shareBackend) {
+ public function __construct(NotebookMapper $notebookMapper, Utils $utils) {
$this->notebookMapper = $notebookMapper;
$this->utils = $utils;
- $this->sharing = $shareBackend;
}
diff --git a/lib/ShareBackend/NextNoteShareBackend.php b/lib/ShareBackend/NextNoteShareBackend.php
index 5033882..1d652ee 100644
--- a/lib/ShareBackend/NextNoteShareBackend.php
+++ b/lib/ShareBackend/NextNoteShareBackend.php
@@ -51,11 +51,11 @@ public function getSharedNotes(){
*/
public function isValidSource($itemSource, $uidOwner) {
// todo: real test
- // id => 1, has admin
+ // id => 1, has admin
// has owner this note?
return true;
}
-
+
/**
* Get a unique name of the item for the specified user
* @param string $itemSource
@@ -124,7 +124,7 @@ public function formatItems($items, $format, $parameters = null) {
return $results;
}
-
+
/**
* Check if a given share type is allowd by the back-end
*
@@ -150,16 +150,6 @@ public function isShareTypeAllowed($shareType) {
* @return bool|int
*/
public function checkPermissions($permission, $note) {
- // gather information
- $uid = \OC::$server->getUserSession()->getUser()->getUID();
- // owner is allowed to do everything
- if ($uid === $note->getUid()) {
- return true;
- }
-
- // check share permissions
- $gotPerm = ShareFix::getPermissions('nextnote', $note->getId(), $uid);
-
- return $gotPerm & $permission;
+ return true;
}
}
\ No newline at end of file
diff --git a/templates/main.php b/templates/main.php
index e1ace2c..55facf9 100644
--- a/templates/main.php
+++ b/templates/main.php
@@ -40,7 +40,7 @@
script('nextnote', 'app/app');
script('nextnote', 'app/routes');
script('nextnote', 'templates');
-script('nextnote', 'share');
+script('nextnote', 'animations');
script('nextnote', 'app/controllers/MainCtrl');
script('nextnote', 'app/controllers/NoteListCtrl');
script('nextnote', 'app/controllers/NoteViewCtrl');
diff --git a/templates/views/list.html b/templates/views/list.html
index ac5a35a..085b0b1 100644
--- a/templates/views/list.html
+++ b/templates/views/list.html
@@ -85,29 +85,29 @@
-