Skip to content

Conversation

@kesselb
Copy link
Contributor

@kesselb kesselb commented Jun 16, 2021

Fix #5173

Todo

  • Add option to enable/disable alias provisioning
  • Add option to customize the ldap attribute
  • Add option to filter aliases by regex
  • Alias section is currently hidden for provisioned accounts. Show the section but disable add alias / delete alias
  • It should be possible to change the name but not the email/alias
  • Test that editing the signature for alias works
  • Add a database field (or virtual field) to alias if provisioned or not
  • Add unique constraint to mail_aliases account_id and alias.
  • UI to enable/disable, ldap attribute, set filter.

@kesselb kesselb force-pushed the enh/5173/ldap-aliases-provisioning branch 3 times, most recently from 7a87327 to e6c824d Compare June 25, 2021 10:15
return $provisioning;
}

if ($this->ldapProviderFactory->isAvailable() === false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snap! isAvailable is new in 21 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do an additional server version comparison here and don't offer the feature for Nextcloud 20 or older. It's a fair tradeoff IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I added @psalm-suppress UndefinedInterfaceMethod to make Psalm on Nextcloud 20 happy. The check for the right Nextcloud version is already done some lines earlier: https://github.com/nextcloud/mail/pull/5198/files#diff-fe646e6e2f7561cf6a8731328355c7432be7647f7114e1619fe2bf5ff2638c42R205. If getMultiValueUserAttribute exist isAvailable also exist.

@kesselb kesselb force-pushed the enh/5173/ldap-aliases-provisioning branch from 4226ec5 to 0ee5cc6 Compare July 6, 2021 19:40
Signed-off-by: Daniel Kesselberg <[email protected]>
@kesselb kesselb force-pushed the enh/5173/ldap-aliases-provisioning branch from 0ee5cc6 to 8fb14b5 Compare July 6, 2021 20:04
@kesselb kesselb changed the title WIP: Ldap alias provisioning LDAP alias provisioning Jul 6, 2021
@kesselb kesselb marked this pull request as ready for review July 6, 2021 20:06
@ChristophWurst ChristophWurst added this to the v1.11.0 milestone Jul 7, 2021
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good otherwise :)

$this->provisioningManager->newProvisioning($data);
} catch (ValidationException $e) {
return HttpJsonResponse::fail([$e->getFields()]);
} catch (\Exception $e) {
Copy link
Member

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?

$this->provisioningManager->updateProvisioning(array_merge($data, ['id' => $id]));
} catch (ValidationException $e) {
return HttpJsonResponse::fail([$e->getFields()]);
} catch (\Exception $e) {
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->provisioningManager->newProvisioning($data); throws a validation exception if input data is invalid or a exception related to the database. I guess we can migrate this to Throwable and HttpJsonResponse.errorFromThrowable.

* 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.
Copy link
Member

Choose a reason for hiding this comment

The 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


$ldapProvider = $this->ldapProviderFactory->getLDAPProvider();
/** @psalm-suppress UndefinedInterfaceMethod */
$provisioning->setAliases($ldapProvider->getMultiValueUserAttribute($user->getUID(), $provisioning->getLdapAliasesAttribute()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kesselb add validation for data

Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setup a test environment using your guide and tested it locally with multiple aliases. Works fine.

The only issue I noticed it that once an account has been provisioned, changes of the aliases in LDAP won't be forwarded to the mail alias settings.

E.g. If I remove one of multiple aliases from LDAP and then run the provisioning again, all aliases are still configured in mail.

@kesselb
Copy link
Contributor Author

kesselb commented Jul 13, 2021

Setup a test environment using your guide and tested it locally with multiple aliases. Works fine.

The only issue I noticed it that once an account has been provisioned, changes of the aliases in LDAP won't be forwarded to the mail alias settings.

E.g. If I remove one of multiple aliases from LDAP and then run the provisioning again, all aliases are still configured in mail.

That should work.

@kesselb
Copy link
Contributor Author

kesselb commented Jul 13, 2021

Setup a test environment using your guide and tested it locally with multiple aliases. Works fine.
The only issue I noticed it that once an account has been provisioned, changes of the aliases in LDAP won't be forwarded to the mail alias settings.
E.g. If I remove one of multiple aliases from LDAP and then run the provisioning again, all aliases are still configured in mail.

That should work.

The provisioning run with every http request in mail. To reduce the load to the ldap server the response for getMultiValueUserAttribute is cached (in server).

If a distributed cache is configured the value is cached. You may set ldapCacheTTL to 0 for testing.

@ChristophWurst ChristophWurst merged commit a32f165 into master Jul 14, 2021
@ChristophWurst ChristophWurst deleted the enh/5173/ldap-aliases-provisioning branch July 14, 2021 13:48
@st3iny
Copy link
Member

st3iny commented Jul 16, 2021

If a distributed cache is configured the value is cached. You may set ldapCacheTTL to 0 for testing.

That has been the issue. My dev setup has a distributed cache setup. Thanks for clarifying :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provision aliases based on an LDAP attribute

4 participants