Skip to content
Snippets Groups Projects
Commit 54139270 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Extend OCS endpoints, write documentation, fix defaults

parent 3ee98dc9
No related branches found
No related tags found
No related merge requests found
build/
vendor/
composer.lock
# Secondary Mail # Secondary Mail - Provide a secondary e-Mail Address to Nextcloud for third-party systems
Place this app in **nextcloud/apps/** Place this app in **nextcloud/apps/** (or install it from the Nextcloud app store), enable it and go to your profile page.
## Building the app
## About the plugin
The app can be built by using the provided Makefile by running:
This app allows your NextCloud users to provide a secondary e-Mail in their profile pages and also specify, which address(es) should be used for communication by third-party systems (like mailinglists). This setting has no influence whatsoever on the mails sent out by Nextcloud, and Nextcloud also will not use the secondary e-mail address for notifications or password resets.
make
However, external custom scripts can be used in combination with the user provisioning API to get the user's preferred e-mail address and use it to sync e.g. Mailman Mailinglists with the nextcloud users. One use case is when nextcloud is used for professional associations, where all users have a work e-mail and private e-mail addresses. Typically, the work address will be used as the primary, but some users prefer to get a copy of all mails/announcements also to their secondary e-mail.
This requires the following things to be present:
* make The primary e-mail address in the nextcloud profile will always be used for nextcloud's notifications and password resets.
* which
* tar: for building the archive This app on its own is not very useful, its full power can only be enjoyed in combination with custom scripts using the user provisioning API (OCS) endpoints to extract the preferred e-mail addresses to third-party systems.
* curl: used if phpunit and composer are not installed to fetch them from the web
* npm: for building and testing everything JS, only required if a package.json is placed inside the **js/** folder ## Editing the secondary email and the preferences in the profile
The make command will install or update Composer dependencies if a composer.json is present and also **npm run build** if a package.json is present in the **js/** folder. The npm **build** script should use local paths for build systems and package managers, so people that simply want to build the app won't need to install npm libraries globally, e.g.:
**package.json**: ## Using OCS endpoints (user provisioning API) to extract email preferences to third-party systems
```json
"scripts": { The app provides two OCS endpoints that allow scripts to extract the user's preferred e-mail from nextcloud:
"test": "node node_modules/gulp-cli/bin/gulp.js karma",
"prebuild": "npm install && node_modules/bower/bin/bower install && node_modules/bower/bin/bower update", * /ocs/v1.php/apps/secondarymail/getAddress/[USERID] - (GET)
"build": "node node_modules/gulp-cli/bin/gulp.js" * /ocs/v1.php/apps/secondarymail/settings/[USERID] - (PUT with parameters key=(email2|emailUsePrimary|emailUseSecondary) and value=...)
}
``` ### Querying for the list of preferred e-mails for communication
This call needs to provide a username and password that has the permissions to read user's profile data, typically this means members of the admin group:
## Publish to App Store
curl -u [USERNAME]:[PASSWORD] -X GET \
First get an account for the [App Store](http://apps.nextcloud.com/) then run: "https://[SERVERURL]/ocs/v1.php/apps/secondarymail/getAddress/[USERID]" \
-H "OCS-APIRequest: true"
make && make appstore
Response:
The archive is located in build/artifacts/appstore and can then be uploaded to the App Store. ```
<?xml version="1.0"?>
## Running tests <ocs>
You can use the provided Makefile to run all tests by using: <meta>
<status>ok</status>
make test <statuscode>100</statuscode>
<message>OK</message>
This will run the PHP unit and integration tests and if a package.json is present in the **js/** folder will execute **npm run test** <totalitems></totalitems>
<itemsperpage></itemsperpage>
Of course you can also install [PHPUnit](http://phpunit.de/getting-started.html) and use the configurations directly: </meta>
<data>
phpunit -c phpunit.xml <usePrimary>true</usePrimary>
<useSecondary>true</useSecondary>
or: <email>
<element>test@demo.open-tools.net</element>
phpunit -c phpunit.integration.xml <element>secondary@dem.open-tools.net</element>
</email>
for integration tests </data>
</ocs>
```
### Setting the secondary e-mail address or changing preferred flags
The /ocs/v1.php/apps/secondarymail/settings/[USERID] endpoint expects two parameters:
* `key`: either email2, emailUsePrimary or emailUseSecondary)
* `value`: The email-address if key=="email2", or "true"/"false" for the preferences
curl -u [USERNAME]:[PASSWORD] -X POST \
"https://[SERVERURL]/ocs/v1.php/apps/secondarymail/settings/[USERID]?key=email2&value=[SECONDARY-MAIL]"\
-H "OCS-APIRequest: true"
Response:
```
<?xml version="1.0"?>
<ocs>
<meta>
<status>ok</status>
<statuscode>100</statuscode>
<message>OK</message>
<totalitems></totalitems>
<itemsperpage></itemsperpage>
</meta>
<data>
<user>test</user>
<key>email2</key>
<value>secondary@demo.open-tools.net</value>
<action>changed</action>
<success>1</success>
</data>
</ocs>
```
...@@ -15,5 +15,6 @@ return [ ...@@ -15,5 +15,6 @@ return [
'ocs' => [ 'ocs' => [
['name' => 'SecondaryMail#getAddress', 'url' => '/getAddress/{id}', 'verb' => 'GET'], ['name' => 'SecondaryMail#getAddress', 'url' => '/getAddress/{id}', 'verb' => 'GET'],
['name' => 'SecondaryMail#setProperty', 'url' => '/settings', 'verb' => 'POST'], ['name' => 'SecondaryMail#setProperty', 'url' => '/settings', 'verb' => 'POST'],
['name' => 'SecondaryMail#setPropertyForUser', 'url' => '/settings/{id}', 'verb' => 'POST'],
] ]
]; ];
img/Nextcloud_SecondaryMail_Profile.png

55.8 KiB

img/Nextcloud_SecondaryMail_ProfileCloseup.png

21.5 KiB

...@@ -53,14 +53,33 @@ class SecondaryMailController extends OCSController { ...@@ -53,14 +53,33 @@ class SecondaryMailController extends OCSController {
* @PasswordConfirmationRequired * @PasswordConfirmationRequired
*/ */
public function setProperty($key, $value) { public function setProperty($key, $value) {
return $this->setPropertyForUser($this->user, $key, $value);
}
/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*/
public function setPropertyForUser($id, $key, $value) {
$data = array();
$data['user'] = $id;
$data['key'] = $key;
$data['value'] = $value;
if (in_array($key, array('emailUsePrimary', 'emailUseSecondary', 'email2'))) { if (in_array($key, array('emailUsePrimary', 'emailUseSecondary', 'email2'))) {
if ($key === 'email2' && $value === "") { if ($key === 'email2' && $value === "") {
$this->config->deleteUserValue($this->user, 'settings', $key); $this->config->deleteUserValue($id, 'settings', $key);
$data['action'] = "deleted";
} else { } else {
$this->config->setUserValue($this->user, 'settings', $key, $value); $this->config->setUserValue($id, 'settings', $key, $value);
$data['action'] = "changed";
} }
$data['success'] = true;
return new DataResponse($data);
} else {
$data['action'] = "UNKNOWN KEY";
$data['success'] = false;
return new DataResponse($data);
} }
return new DataResponse(true);
} }
/** /**
......
...@@ -50,9 +50,9 @@ class Personal implements ISettings { ...@@ -50,9 +50,9 @@ class Personal implements ISettings {
*/ */
public function getForm() { public function getForm() {
$parameters = [ $parameters = [
'use_primary_mail' => $this->config->getUserValue($this->user, 'settings', 'emailUsePrimary', 1), 'use_primary_mail' => $this->config->getUserValue($this->user, 'settings', 'emailUsePrimary', 'true'),
'use_secondary_mail' => $this->config->getUserValue($this->user, 'settings', 'emailUseSecondary', 0), 'use_secondary_mail' => $this->config->getUserValue($this->user, 'settings', 'emailUseSecondary', 'true'),
'secondaryMail' => $this->config->getUserValue($this->user, 'settings', 'email2', 'office@open-tools.net'), 'secondaryMail' => $this->config->getUserValue($this->user, 'settings', 'email2', ''),
'userid' => $this->user 'userid' => $this->user
]; ];
return new TemplateResponse('secondarymail', 'settings/personal', $parameters); return new TemplateResponse('secondarymail', 'settings/personal', $parameters);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment