mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-29 14:56:12 +08:00
Sharing API progress
This commit is contained in:
parent
38e1533b5e
commit
5fa439ee4d
5 changed files with 43 additions and 4 deletions
|
|
@ -149,6 +149,10 @@ class ShareController extends ApiController {
|
|||
return new JSONResponse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @param $credential
|
||||
*/
|
||||
public function share($credential) {
|
||||
|
||||
$link = '';
|
||||
|
|
@ -180,4 +184,12 @@ class ShareController extends ApiController {
|
|||
return new JSONResponse($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the list of credentials shared with this vault
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getSharedItems($vault_guid){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -132,7 +132,6 @@ angular.module('passmanApp')
|
|||
ShareService.generateSharedKey(20).then(function(key){
|
||||
console.log(key);
|
||||
|
||||
|
||||
var encryptedSharedCredential = ShareService.encryptSharedCredential($scope.storedCredential, key);
|
||||
|
||||
var list = $scope.share_settings.credentialSharedWithUserAndGroup;
|
||||
|
|
|
|||
|
|
@ -44,9 +44,11 @@ class CredentialMapper extends Mapper {
|
|||
return $this->findEntities($sql, [$timestamp]);
|
||||
}
|
||||
|
||||
public function getCredentialById($credential_id, $user_id){
|
||||
public function getCredentialById($credential_id, $user_id = null){
|
||||
$sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' .
|
||||
'WHERE `id` = ? and `user_id` = ? ';
|
||||
'WHERE `id` = ?';
|
||||
// If we want to check the owner, add it to the query
|
||||
if ($user_id !== null) $sql .= ' and `user_id` = ? ';
|
||||
return $this->findEntity($sql,[$credential_id, $user_id]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,4 +37,15 @@ class SharingACLMapper extends Mapper {
|
|||
public function createACLEntry(SharingACL $acl){
|
||||
return $this->insert($acl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently accepted share requests from the given user for the given vault guid
|
||||
* @param $user_id
|
||||
* @param $vault_id
|
||||
* @return SharingACL[]
|
||||
*/
|
||||
public function getVaultEntries($user_id, $vault_id) {
|
||||
$q = "SELECT * FROM {{ self::TABLE_NAME }} WHERE target_user_id = ? AND target_vault_guid = ?";
|
||||
return $this->findEntities($q, [$user_id, $vault_id]);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
namespace OCA\Passman\Service;
|
||||
|
||||
|
||||
use OCA\Passman\Db\CredentialMapper;
|
||||
use OCA\Passman\Db\ShareRequest;
|
||||
use OCA\Passman\Db\ShareRequestMapper;
|
||||
use OCA\Passman\Db\SharingACL;
|
||||
|
|
@ -17,10 +18,12 @@ use OCA\Passman\Db\SharingACLMapper;
|
|||
class ShareService {
|
||||
private $sharingACL;
|
||||
private $shareRequest;
|
||||
private $credential;
|
||||
|
||||
public function __construct(SharingACLMapper $sharingACL, ShareRequestMapper $shareRequest) {
|
||||
public function __construct(SharingACLMapper $sharingACL, ShareRequestMapper $shareRequest, CredentialMapper $credentials) {
|
||||
$this->sharingACL = $sharingACL;
|
||||
$this->shareRequest = $shareRequest;
|
||||
$this->credential = $credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -88,4 +91,16 @@ class ShareService {
|
|||
public function getUserPendingRequests($user_id){
|
||||
return $this->shareRequest->getUserPendingRequests($user_id);
|
||||
}
|
||||
|
||||
public function getSharedItems($user_id, $vault_id){
|
||||
$entries = $this->sharingACL->getVaultEntries($user_id, $vault_id);
|
||||
$return = [];
|
||||
foreach ($entries as $entry){
|
||||
$tmp = $entry->jsonSerialize();
|
||||
$tmp['credential_data'] = $this->credential->getCredentialById($entry->getItemId());
|
||||
$return[] = $tmp;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue