Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,62 @@
</field>
</declaration>
</table>
<table>
<name>*dbprefix*nextnote_shares</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>32</length>
</field>
<field>
<name>guid</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>share_from</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>share_to</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>share_type</name>
<type>integer</type>
<default>0</default>
<notnull>false</notnull>
<length>32</length>
</field>
<field>
<name>share_target</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>permissions</name>
<type>integer</type>
<notnull>true</notnull>
<default>0</default>
<length>1</length>
</field>
<field>
<name>expire_time</name>
<type>datetime</type>
<notnull>false</notnull>
<default>0</default>
<length>1</length>
</field>
</declaration>
</table>
</database>
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.5</version>
<version>1.2.7</version>
<licence>agpl</licence>
<author>Ben Curtis</author>
<author>Sander Brand</author>
Expand Down
82 changes: 82 additions & 0 deletions lib/Db/Share.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Nextcloud - NextNote
*
*
* @copyright Copyright (c) 2017, Sander Brand ([email protected])
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\NextNote\Db;
use \OCP\AppFramework\Db\Entity;

/**
* @method integer getId()
* @method void setId(int $value)
* @method void setGuid(string $value)
* @method string getGuid()
* @method void setShareFrom(string $value)
* @method string getShareFrom()
* @method void setShareTo(string $value)
* @method string getShareTo()
* @method void setShareType(string $value)
* @method string getShareType()
* @method void setShareTarget(string $value)
* @method string getShareTarget()
* @method void setPermissions(string $value)
* @method string getPermissions()
* @method void setExpireTime(string $value)
* @method string getExpireTime()

*/


class Share extends Entity implements \JsonSerializable{

use EntityJSONSerializer;

protected $guid;
protected $shareFrom; //User from
protected $shareTo; // Share to User / group
protected $shareType; // Note (1) or Notebook(2)
protected $shareTarget; //id of the entity
protected $permissions; // int permissions
protected $expireTime; // Expire time of share. 0 to disable


public function __construct() {
// add types in constructor
$this->addType('permissions', 'integer');
$this->addType('shareTarget', 'integer');
$this->addType('shareType', 'integer');
}
/**
* Turns entity attributes into an array
*/
public function jsonSerialize() {
return [
'id' => $this->getId(),
'guid' => $this->getGuid(),
'share_from' => $this->getShareFrom(),
'share_to' => $this->getShareTo(),
'share_type' => $this->getShareType(),
'share_target' => $this->getShareTarget(),
'permissions' => $this->getPermissions(),
'expire_time' => $this->getExpireTime(),
];
}
}
146 changes: 146 additions & 0 deletions lib/Db/ShareMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* Nextcloud - NextNote
*
*
* @copyright Copyright (c) 2017, Sander Brand ([email protected])
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\NextNote\Db;

use OCA\NextNote\Service\NotebookService;
use \OCA\NextNote\Utility\Utils;
use OCP\AppFramework\Db\Entity;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;

class ShareMapper extends Mapper {
private $utils;

public function __construct(IDBConnection $db, Utils $utils) {
parent::__construct($db, 'nextnote_shares');
$this->utils = $utils;
}


/**
* @param $share_id
* @param null $user_id
* @return Share|Share[]
*/
public function find($share_id, $user_id = null) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('nextnote_shares')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share_id)));

if ($user_id) {
$qb->andWhere($qb->expr()->eq('share_from', $qb->createNamedParameter($user_id)));
}

$results = [];
$result = $qb->execute();
while ($item = $result->fetch()) {
/**
* @var $share Share
*/
$share = $this->makeEntityFromDBResult($item);
$results[] = $share;
}
$result->closeCursor();
if (count($results) === 1) {
return reset($results);
}
return $results;

}


/**
* @param $userId
* @return Share[] if not found
*/
public function findSharesFromUser($userId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('nextnote_shares')
->where($qb->expr()->eq('share_from', $qb->createNamedParameter($userId)));


$results = [];
$result = $qb->execute();
while ($item = $result->fetch()) {
/**
* @var $share Share
*/
$share = $this->makeEntityFromDBResult($item);

$results[] = $share;
}
$result->closeCursor();
return $results;
}


/**
* Creates a note
*
* @param Share|Entity $share
* @return Share|Entity
* @internal param $userId
*/
public function insert(Entity $share) {
return parent::insert($share);
}

/**
* Update note
*
* @param Share|Entity $share
* @return Share|Entity
*/
public function updateNote(Entity $share) {
parent::update($share);
return $this->find($share->getId());
}

/**
* Update note
*
* @param Share|Entity $share
* @return Share|Entity
*/
public function delete(Entity $share) {
parent::delete($share);
return $this->find($share->getId());
}

public function makeEntityFromDBResult($arr) {
$share = new Share();
$share->setId($arr['id']);
$share->setGuid($arr['guid']);
$share->setShareFrom($arr['share_from']);
$share->setShareTo($arr['share_to']);
$share->setShareType($arr['share_type']);
$share->setShareTarget($arr['share_target']);
$share->setPermissions($arr['permissions']);
$share->setExpireTime($arr['expire_time']);

return $share;
}
}
65 changes: 65 additions & 0 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Nextcloud - namespace OCA\Nextnote
*
* @copyright Copyright (c) 2016, Sander Brand ([email protected])
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\NextNote\Service;

use OCA\NextNote\Db\Notebook;
use OCA\NextNote\Db\Note;
use OCA\NextNote\Db\ShareMapper;
use OCA\NextNote\Fixtures\ExampleNote;
use OCA\NextNote\Utility\Utils;
use OCA\NextNote\Db\NoteMapper;


class ShareService {

const PERMISSION_CREATE = 4;
const PERMISSION_READ = 1;
const PERMISSION_UPDATE = 2;
const PERMISSION_DELETE = 8;
const PERMISSION_SHARE = 16;
const PERMISSION_ALL = 31;


private $shareMapper;
private $utils;
private $notebookService;

public function __construct(ShareMapper $shareMapper, Utils $utils, NotebookService $notebookService) {
$this->shareMapper = $shareMapper;
$this->utils = $utils;
$this->notebookService = $notebookService;
}

/**
* Get shared notes from a user.
*
* @param $userId
* @param int|bool $deleted
* @return Note[]
*/
public function getSharedNotesFromUser($userId, $deleted = false) {
// Get shares

}
}