-
Notifications
You must be signed in to change notification settings - Fork 294
LDAP alias provisioning #5198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LDAP alias provisioning #5198
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,19 +60,20 @@ public function createProvisioning(array $data): JSONResponse { | |
| $this->provisioningManager->newProvisioning($data); | ||
| } catch (ValidationException $e) { | ||
| return HttpJsonResponse::fail([$e->getFields()]); | ||
| } catch (\Exception $e) { | ||
| return HttpJsonResponse::fail([$e->getMessage()]); | ||
| } | ||
|
|
||
| return new JSONResponse([]); | ||
| } | ||
|
|
||
| public function updateProvisioning(int $id, array $data): JSONResponse { | ||
| try { | ||
| $this->provisioningManager->updateProvisioning(array_merge( | ||
| $data, | ||
| ['id' => $id] | ||
| )); | ||
| $this->provisioningManager->updateProvisioning(array_merge($data, ['id' => $id])); | ||
| } catch (ValidationException $e) { | ||
| return HttpJsonResponse::fail([$e->getFields()]); | ||
| } catch (\Exception $e) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same. Could this possibly be a ClientException? \Error will throw almost anything. That anything could also be from unexpected service errors, then the HTTP4xx isn't appropriate IMO
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return HttpJsonResponse::fail([$e->getMessage()]); | ||
| } | ||
|
|
||
| return new JSONResponse([]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ public function __construct(IDBConnection $db) { | |
| */ | ||
| public function find(int $aliasId, string $currentUserId): Alias { | ||
| $qb = $this->db->getQueryBuilder(); | ||
| $qb->select('aliases.*') | ||
| $qb->select('aliases.*', 'accounts.provisioning_id') | ||
| ->from($this->getTableName(), 'aliases') | ||
| ->join('aliases', 'mail_accounts', 'accounts', $qb->expr()->eq('aliases.account_id', 'accounts.id')) | ||
| ->where( | ||
|
|
@@ -54,6 +54,24 @@ public function find(int $aliasId, string $currentUserId): Alias { | |
| return $this->findEntity($qb); | ||
| } | ||
|
|
||
| /** | ||
| * @throws DoesNotExistException | ||
| */ | ||
| public function findByAlias(string $alias, string $currentUserId): Alias { | ||
| $qb = $this->db->getQueryBuilder(); | ||
| $qb->select('aliases.*', 'accounts.provisioning_id') | ||
| ->from($this->getTableName(), 'aliases') | ||
| ->join('aliases', 'mail_accounts', 'accounts', $qb->expr()->eq('aliases.account_id', 'accounts.id')) | ||
| ->where( | ||
| $qb->expr()->andX( | ||
| $qb->expr()->eq('accounts.user_id', $qb->createNamedParameter($currentUserId)), | ||
| $qb->expr()->eq('aliases.alias', $qb->createNamedParameter($alias)) | ||
| ) | ||
| ); | ||
|
|
||
| return $this->findEntity($qb); | ||
| } | ||
|
|
||
| /** | ||
| * @param int $accountId | ||
| * @param string $currentUserId | ||
|
|
@@ -62,7 +80,7 @@ public function find(int $aliasId, string $currentUserId): Alias { | |
| */ | ||
| public function findAll(int $accountId, string $currentUserId): array { | ||
| $qb = $this->db->getQueryBuilder(); | ||
| $qb->select('aliases.*') | ||
| $qb->select('aliases.*', 'accounts.provisioning_id') | ||
| ->from($this->getTableName(), 'aliases') | ||
| ->join('aliases', 'mail_accounts', 'accounts', $qb->expr()->eq('aliases.account_id', 'accounts.id')) | ||
| ->where( | ||
|
|
@@ -89,6 +107,29 @@ public function deleteAll($accountId) { | |
| $query->execute(); | ||
| } | ||
|
|
||
| /** | ||
| * Delete all provisioned aliases for the given uid | ||
| * | ||
| * Exception for Nextcloud 20: \Doctrine\DBAL\DBALException | ||
| * Exception for Nextcloud 21 and newer: \OCP\DB\Exception | ||
| * | ||
| * @TODO: Change throws to \OCP\DB\Exception once Mail does not support Nextcloud 20. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI I think we do this soon-ish so we only have to support two major versions |
||
| * | ||
| * @throws \Exception | ||
| */ | ||
| public function deleteProvisionedAliasesByUid(string $uid): void { | ||
| $qb = $this->db->getQueryBuilder(); | ||
|
|
||
| $qb->delete($this->getTableName(), 'aliases') | ||
| ->join('aliases', 'mail_accounts', 'accounts', 'accounts.id = aliases.account_id') | ||
| ->where( | ||
| $qb->expr()->eq('accounts.user_id', $qb->createNamedParameter($uid)), | ||
| $qb->expr()->isNotNull('provisioning_id') | ||
| ); | ||
|
|
||
| $qb->execute(); | ||
| } | ||
|
|
||
| public function deleteOrphans(): void { | ||
| $qb1 = $this->db->getQueryBuilder(); | ||
| $idsQuery = $qb1->select('a.id') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OCA\Mail\Migration; | ||
|
|
||
| use Closure; | ||
| use Doctrine\DBAL\Schema\SchemaException; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
|
|
||
| class Version1101Date20210616141806 extends SimpleMigrationStep { | ||
| /** | ||
| * @throws SchemaException | ||
| */ | ||
| public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
|
|
||
| $provisioningTable = $schema->getTable('mail_provisionings'); | ||
| $provisioningTable->addColumn('ldap_aliases_provisioning', 'boolean', [ | ||
| 'notnull' => false, | ||
| 'default' => false | ||
| ]); | ||
| $provisioningTable->addColumn('ldap_aliases_attribute', 'string', [ | ||
| 'notnull' => false, | ||
| 'length' => 255, | ||
| 'default' => '', | ||
| ]); | ||
|
|
||
| return $schema; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you elaborate why this was widened?