mirror of
https://github.com/nextcloud/passman.git
synced 2025-11-10 22:22:38 +08:00
parent
f7cb2a4c6d
commit
6dc3ddf63f
5 changed files with 115 additions and 147 deletions
|
|
@ -43,39 +43,23 @@ class CredentialService {
|
||||||
public function updateCredential($credential) {
|
public function updateCredential($credential) {
|
||||||
return $this->credentialMapper->updateCredential($credential);
|
return $this->credentialMapper->updateCredential($credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Credential $credential
|
|
||||||
*/
|
|
||||||
public function upd($credential) {
|
public function upd($credential) {
|
||||||
return $this->credentialMapper->upd($credential);
|
return $this->credentialMapper->upd($credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Credential $credential
|
|
||||||
*/
|
|
||||||
public function deleteCredential($credential){
|
public function deleteCredential($credential){
|
||||||
return $this->credentialMapper->deleteCredential($credential);
|
return $this->credentialMapper->deleteCredential($credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param integer $vault_id
|
|
||||||
*/
|
|
||||||
public function getCredentialsByVaultId($vault_id, $user_id) {
|
public function getCredentialsByVaultId($vault_id, $user_id) {
|
||||||
return $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id);
|
return $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param integer $vault_id
|
|
||||||
*/
|
|
||||||
public function getRandomCredentialByVaultId($vault_id, $user_id) {
|
public function getRandomCredentialByVaultId($vault_id, $user_id) {
|
||||||
$credentials = $this->credentialMapper->getRandomCredentialByVaultId($vault_id, $user_id);
|
$credentials = $this->credentialMapper->getRandomCredentialByVaultId($vault_id, $user_id);
|
||||||
return array_pop($credentials);
|
return array_pop($credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param integer $timestamp
|
|
||||||
*/
|
|
||||||
public function getExpiredCredentials($timestamp) {
|
public function getExpiredCredentials($timestamp) {
|
||||||
return $this->credentialMapper->getExpiredCredentials($timestamp);
|
return $this->credentialMapper->getExpiredCredentials($timestamp);
|
||||||
}
|
}
|
||||||
|
|
@ -93,10 +77,6 @@ class CredentialService {
|
||||||
|
|
||||||
throw new DoesNotExistException("Did expect one result but found none when executing");
|
throw new DoesNotExistException("Did expect one result but found none when executing");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param integer $credential_id
|
|
||||||
*/
|
|
||||||
public function getCredentialLabelById($credential_id){
|
public function getCredentialLabelById($credential_id){
|
||||||
return $this->credentialMapper->getCredentialLabelById($credential_id);
|
return $this->credentialMapper->getCredentialLabelById($credential_id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,7 @@ class ShareService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createACLEntry(SharingACL $acl) {
|
public function createACLEntry(SharingACL $acl) {
|
||||||
if ($acl->getCreated() === null) {
|
if ($acl->getCreated() === null) $acl->setCreated((new \DateTime())->getTimestamp());
|
||||||
$acl->setCreated((new \DateTime())->getTimestamp());
|
|
||||||
}
|
|
||||||
return $this->sharingACL->createACLEntry($acl);
|
return $this->sharingACL->createACLEntry($acl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,16 +124,12 @@ class ShareService {
|
||||||
$return = [];
|
$return = [];
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
// Check if the user can read the credential, probably unnecesary, but just to be sure
|
// Check if the user can read the credential, probably unnecesary, but just to be sure
|
||||||
if (!$entry->hasPermission(SharingACL::READ)) {
|
if (!$entry->hasPermission(SharingACL::READ)) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp = $entry->jsonSerialize();
|
$tmp = $entry->jsonSerialize();
|
||||||
$tmp['credential_data'] = $this->credential->getCredentialById($entry->getItemId())->jsonSerialize();
|
$tmp['credential_data'] = $this->credential->getCredentialById($entry->getItemId())->jsonSerialize();
|
||||||
|
|
||||||
if (!$entry->hasPermission(SharingACL::FILES)) {
|
if (!$entry->hasPermission(SharingACL::FILES)) unset($tmp['credential_data']['files']);
|
||||||
unset($tmp['credential_data']['files']);
|
|
||||||
}
|
|
||||||
unset($tmp['credential_data']['shared_key']);
|
unset($tmp['credential_data']['shared_key']);
|
||||||
$return[] = $tmp;
|
$return[] = $tmp;
|
||||||
}
|
}
|
||||||
|
|
@ -156,16 +150,12 @@ class ShareService {
|
||||||
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
|
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
|
||||||
|
|
||||||
// Check if the user can read the credential, probably unnecesary, but just to be sure
|
// Check if the user can read the credential, probably unnecesary, but just to be sure
|
||||||
if (!$acl->hasPermission(SharingACL::READ)) {
|
if (!$acl->hasPermission(SharingACL::READ)) throw new DoesNotExistException("Item not found or wrong access level");
|
||||||
throw new DoesNotExistException("Item not found or wrong access level");
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp = $acl->jsonSerialize();
|
$tmp = $acl->jsonSerialize();
|
||||||
$tmp['credential_data'] = $this->credential->getCredentialById($acl->getItemId())->jsonSerialize();
|
$tmp['credential_data'] = $this->credential->getCredentialById($acl->getItemId())->jsonSerialize();
|
||||||
|
|
||||||
if (!$acl->hasPermission(SharingACL::FILES)) {
|
if (!$acl->hasPermission(SharingACL::FILES)) unset($tmp['credential_data']['files']);
|
||||||
unset($tmp['credential_data']['files']);
|
|
||||||
}
|
|
||||||
unset($tmp['credential_data']['shared_key']);
|
unset($tmp['credential_data']['shared_key']);
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
|
@ -180,9 +170,7 @@ class ShareService {
|
||||||
*/
|
*/
|
||||||
public function getItemHistory($user_id, $item_guid) {
|
public function getItemHistory($user_id, $item_guid) {
|
||||||
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
|
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
|
||||||
if (!$acl->hasPermission(SharingACL::READ | SharingACL::HISTORY)) {
|
if (!$acl->hasPermission(SharingACL::READ | SharingACL::HISTORY)) return [];
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->revisions->getRevisions($acl->getItemId());
|
return $this->revisions->getRevisions($acl->getItemId());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue