Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
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
15 changes: 15 additions & 0 deletions lib/Doctrine/CouchDB/CouchDBClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,21 @@ public function createDesignDocument($designDocName, DesignDocument $designDoc)
);
}

/**
* https://docs.couchdb.org/en/stable/api/database/security.html
*/
public function putSecurityDocument(SecurityDocument $securityDoc)
{
$data = $securityDoc->getData();

$path = '/' . $this->databaseName . '/_security';
$response = $this->httpClient->request('PUT', $path, json_encode($data));

if ($response->status != 200 || !$response->body['ok']) {
throw HTTPException::fromResponse($path, $response);
}
}

/**
* GET /db/_compact.
*
Expand Down
44 changes: 44 additions & 0 deletions lib/Doctrine/CouchDB/SecurityDocument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Doctrine\CouchDB;

class SecurityDocument
{
/**
* @var array
*/
private $data = [];

public function getData()
{
return $this->data;
}

public function addAdminName($name)
{
$this->addEntry('admins', 'names', $name);
}

public function addAdminRole($role)
{
$this->addEntry('admins', 'roles', $name);
}

public function addMemberName($name)
{
$this->addEntry('members', 'names', $name);
}

public function addMemberRole($role)
{
$this->addEntry('members', 'roles', $name);
}

private function addEntry($role, $type, $val)
{
if (!isset($this->data[$role][$type])) {
$this->data[$role][$type] = [];
}
$this->data[$role][$type][] = $val;
}
}