Completed
Push — master ( abe26e...97d0fb )
by Sander
9s
created

VaultService::getById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 2
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\Service;
25
26
use OCA\Passman\Db\Vault;
27
use OCP\IConfig;
28
use OCP\AppFramework\Db\DoesNotExistException;
29
30
use OCA\Passman\Db\VaultMapper;
31
32
33
class VaultService {
34
35
	private $vaultMapper;
36
37
	public function __construct(VaultMapper $vaultMapper) {
38
		$this->vaultMapper = $vaultMapper;
39
	}
40
41
	/**
42
	 * Get vaults from a user.
43
	 * @param $userId
44
	 * @return \OCA\Passman\Db\Vault[]
45
	 */
46
	public function getByUser($userId) {
47
		return $this->vaultMapper->findVaultsFromUser($userId);
48
	}
49
50
	/**
51
	 * Get a single vault
52
	 * @param $vault_id
53
	 * @param $user_id
54
	 * @return \OCA\Passman\Db\Vault[]
55
	 */
56
	public function getById($vault_id, $user_id) {
57
		$vault = $this->vaultMapper->find($vault_id, $user_id);
58
		return $vault;
59
	}
60
61
	/**
62
	 * Get a single vault.
63
	 * @param $vault_guid
64
	 * @param $user_id
65
	 * @return \OCA\Passman\Db\Vault
66
	 */
67
	public function getByGuid($vault_guid, $user_id) {
68
		$vault = $this->vaultMapper->findByGuid($vault_guid, $user_id);
69
		return $vault;
70
	}
71
72
	/**
73
	 * Create a new vault.
74
	 * @param $vault_name
75
	 * @param $userId
76
	 * @return \OCA\Passman\Db\Vault
77
	 */
78
	public function createVault($vault_name, $userId) {
79
		return $this->vaultMapper->create($vault_name, $userId);
80
	}
81
82
	/**
83
	 * Update vault
84
	 * @param $vault
85
	 */
86
	public function updateVault($vault) {
87
		return $this->vaultMapper->updateVault($vault);
88
	}
89
90
	/**
91
	 * Update last access time of a vault.
92
	 * @param $vault_id
93
	 * @param $user_id
94
	 */
95
	public function setLastAccess($vault_id, $user_id){
96
		return $this->vaultMapper->setLastAccess($vault_id, $user_id);
97
	}
98
99
	/**
100
	 * Uodate sharing keys of a vault.
101
	 * @param $vault_id
102
	 * @param $privateKey
103
	 * @param $publicKey
104
	 */
105
	public function updateSharingKeys($vault_id, $privateKey, $publicKey){
106
		return $this->vaultMapper->updateSharingKeys($vault_id, $privateKey, $publicKey);
107
	}
108
109
	/**
110
	 * Delete a vault from user
111
	 * @param string $vault_guid
112
	 * @param string $user_id
113
	 */
114
	public function deleteVault($vault_guid, $user_id){
115
		$vault = $this->getByGuid($vault_guid, $user_id);
116
		if($vault instanceof Vault) {
117
			$this->vaultMapper->deleteVault($vault);
118
		}
119
	}
120
}