Skip to content

Commit

Permalink
Merge pull request #107 from brantje/stripOldSharing
Browse files Browse the repository at this point in the history
Strip old sharing
  • Loading branch information
brantje authored Apr 14, 2018
2 parents 1270a77 + 858c3ed commit 84b38cd
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 2,491 deletions.
3 changes: 1 addition & 2 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

13 changes: 0 additions & 13 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,13 @@
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>grouping</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
<default></default>
</field>
<field>
<name>notebook</name>
<type>integer</type>
<notnull>true</notnull>
<length>32</length>
<default></default>
</field>
<field>
<name>shared</name>
<type>clob</type>
<notnull>true</notnull>
<default></default>
</field>
<field>
<name>mtime</name>
<type>integer</type>
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>NextNote</name>
<summary>NextNote</summary>
<description>NextNote</description>
<version>1.2.4</version>
<version>1.2.5</version>
<licence>agpl</licence>
<author>Ben Curtis</author>
<author>Sander Brand</author>
Expand Down
33 changes: 5 additions & 28 deletions controller/noteapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,28 +36,23 @@
use OCP\ILogger;
use \OCP\IRequest;
use OCP\IUserManager;
use OCP\Share;



class NoteApiController extends ApiController {

private $config;
private $noteService;
private $shareBackend;
private $userManager;
private $shareManager;
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;
}

/**
Expand Down Expand Up @@ -164,9 +156,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) {
Expand Down Expand Up @@ -194,10 +184,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]);
Expand All @@ -213,20 +199,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']);
Expand Down
9 changes: 1 addition & 8 deletions controller/notebookapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
24 changes: 4 additions & 20 deletions controller/shareapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

use \OCP\AppFramework\ApiController;
use \OCP\IRequest;
use OC\Share\Share;
use OCA\NextNote\Fixtures\ShareFix;


class ShareApiController extends ApiController {
Expand All @@ -28,44 +26,30 @@ 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'));
}

}

/**
* @NoAdminRequired
* @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;

}

/**
* @NoAdminRequired
* @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;

}

/**
* @NoAdminRequired
* @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;

}
}
16 changes: 1 addition & 15 deletions controller/translationcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
33 changes: 33 additions & 0 deletions js/animations.js
Original file line number Diff line number Diff line change
@@ -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';
}
});
});
Loading

0 comments on commit 84b38cd

Please sign in to comment.