Completed
Branch master (8ca3ab)
by Sander
03:07
created

SharingACLMapper::getVaultEntries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
6
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Passman\Db;
25
26
27
use OCP\AppFramework\Db\Mapper;
28
use OCP\IDBConnection;
29
use OCP\IUser;
30
use OCA\Passman\Utility\Utils;
31
32
class SharingACLMapper extends Mapper {
33
    const TABLE_NAME = '*PREFIX*passman_sharing_acl';
34
35
    public function __construct(IDBConnection $db) {
36
        parent::__construct($db, 'passman_sharing_acl');
37
    }
38
39
    public function createACLEntry(SharingACL $acl){
40
        return $this->insert($acl);
41
    }
42
43
    /**
44
     * Gets the currently accepted share requests from the given user for the given vault guid
45
     * @param $user_id
46
     * @param $vault_guid
47
     * @return SharingACL[]
48
     */
49 1
    public function getVaultEntries($user_id, $vault_guid) {
50 1
        $q = "SELECT * FROM ". self::TABLE_NAME ." WHERE user_id = ? AND vault_guid = ?";
51 1
        return $this->findEntities($q, [$user_id, $vault_guid]);
52
    }
53
54
    /**
55
     * Gets the acl for a given item guid
56
     * @param $user_id
57
     * @param $item_guid
58
     * @return SharingACL
59
     */
60 1
    public function getItemACL($user_id, $item_guid) {
61 1
        $q = "SELECT * FROM " . self::TABLE_NAME . " WHERE item_guid = ? AND ";
62 1
        $filter = [$item_guid];
63 1
        $q .= ($user_id === null) ? 'user_id is null' : 'user_id = ? ';
64 1
        if ($user_id !== null){
65 1
			$filter[] = $user_id;
66
        }
67
68 1
        return $this->findEntity($q, $filter);
69
    }
70
71
    /**
72
     * Update the acl for a given item guid
73
     * @param $user_id
74
     * @param $item_guid
75
     * @return SharingACL
76
     */
77 1
    public function updateCredentialACL(SharingACL $sharingACL) {
78 1
        return $this->update($sharingACL);
79
    }
80
81
    /**
82
     * Gets the currently accepted share requests from the given user for the given vault guid
83
     * @param $user_id
84
     * @param $vault_id
85
     * @return SharingACL[]
86
     */
87 1
    public function getCredentialAclList($item_guid) {
88 1
        $q = "SELECT * FROM ". self::TABLE_NAME ." WHERE item_guid = ?";
89 1
        return $this->findEntities($q, [$item_guid]);
90
    }
91
92 1
    public function deleteShareACL(SharingACL $ACL){
93 1
    	return $this->delete($ACL);
94
	}
95
}