Skip to content

Commit

Permalink
allow for avatar downloads from social networks
Browse files Browse the repository at this point in the history
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
  • Loading branch information
matthias authored and call-me-matt committed Jul 21, 2020
1 parent b8f4a67 commit a9232db
Show file tree
Hide file tree
Showing 36 changed files with 1,413 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nextcloud Contacts
![Downloads](https://img.shields.io/github/downloads/nextcloud/contacts/total?style=flat-square)
![Downloads](https://img.shields.io/github/downloads/nextcloud/contacts/total.svg?style=flat-square)
[![Codacy Badge](https://img.shields.io/codacy/grade/ea24ea9fccb942419d73ec05105938aa.svg?style=flat-square)](https://app.codacy.com/app/skjnldsv/contacts)
[![Code coverage](https://img.shields.io/codecov/c/github/nextcloud/contacts.svg?style=flat-square)](https://codecov.io/gh/nextcloud/contacts/)
[![Dependabot status](https://img.shields.io/badge/Dependabot-enabled-brightgreen.svg?longCache=true&style=flat-square&logo=dependabot)](https://dependabot.com)
Expand Down
26 changes: 26 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

use OCA\Contacts\AppInfo\Application;

$app = \OC::$server->query(Application::class);
4 changes: 4 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@
<order>4</order>
</navigation>
</navigations>

<settings>
<admin>OCA\Contacts\Settings\AdminSettings</admin>
</settings>
</info>
4 changes: 3 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#index', 'url' => '/{group}', 'verb' => 'GET', 'postfix' => 'group'],
['name' => 'page#index', 'url' => '/{group}/{contact}', 'verb' => 'GET', 'postfix' => 'group.contact']
['name' => 'page#index', 'url' => '/{group}/{contact}', 'verb' => 'GET', 'postfix' => 'group.contact'],
['name' => 'social_api#update_contact', 'url' => '/api/v1/social/avatar/{network}/{addressbookId}/{contactId}', 'verb' => 'PUT'],
['name' => 'social_api#set_app_config', 'url' => '/api/v1/social/config/{key}', 'verb' => 'POST'],
]
];
8 changes: 8 additions & 0 deletions css/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
@include icon-black-white('no-calendar', 'contacts', 1);
@include icon-black-white('language', 'contacts', 2);
@include icon-black-white('clone', 'contacts', 2);
@include icon-black-white('sync', 'contacts', 2);

// social network icons:
@include icon-black-white('facebook', 'contacts', 2); // “facebook (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/facebook?style=brands)
@include icon-black-white('instagram', 'contacts', 2); // “instagram (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/instagram?style=brands)
@include icon-black-white('mastodon', 'contacts', 2); // “mastodon (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/mastodon?style=brands)
@include icon-black-white('tumblr', 'contacts', 2); // “tumblr (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/tumblr?style=brands)
@include icon-black-white('twitter', 'contacts', 2); // “twitter (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/twitter?style=brands)

.icon-up-force-white {
// using #fffffe to trick the accessibility dark theme icon invert
Expand Down
1 change: 1 addition & 0 deletions img/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/instagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions img/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# social network icons:
* “facebook (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/facebook?style=brands)
* “instagram (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/instagram?style=brands)
* “mastodon (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/mastodon?style=brands)
* “tumblr (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/tumblr?style=brands)
* “twitter (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/twitter?style=brands)
1 change: 1 addition & 0 deletions img/mastodon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions img/sync.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions img/tumblr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/twitter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion l10n/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@
"Your web browser is out of date" : "Ваш бразуер застарів",
"This application is not compatible with Internet Explorer" : "Застосунок не сумісний з Internet Explorer"
},"pluralForm" :"nplurals=4; plural=(n % 1 == 0 && n % 10 == 1 && n % 100 != 11 ? 0 : n % 1 == 0 && n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) ? 1 : n % 1 == 0 && (n % 10 ==0 || (n % 10 >=5 && n % 10 <=9) || (n % 100 >=11 && n % 100 <=14 )) ? 2: 3);"
}
}
37 changes: 37 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Contacts\AppInfo;

use OCP\AppFramework\App;

class Application extends App {
public const APP_ID = 'contacts';

public function __construct() {
parent::__construct(self::APP_ID);
}

public const AVAIL_SETTINGS = [
'allowSocialSync' => 'yes',
];
}
14 changes: 11 additions & 3 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

namespace OCA\Contacts\Controller;

use OCA\Contacts\Service\SocialApiService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IInitialStateService;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\L10N\IFactory;
use OCP\Util;
Expand All @@ -43,17 +44,22 @@ class PageController extends Controller {
/** @var IFactory */
private $languageFactory;

/** @var SocialApiService */
private $socialApiService;

public function __construct(string $appName,
IRequest $request,
IConfig $config,
IInitialStateService $initialStateService,
IFactory $languageFactory) {
IFactory $languageFactory,
SocialApiService $socialApiService) {
parent::__construct($appName, $request);

$this->appName = $appName;
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->languageFactory = $languageFactory;
$this->socialApiService = $socialApiService;
}

/**
Expand All @@ -65,10 +71,12 @@ public function __construct(string $appName,
public function index(): TemplateResponse {
$locales = $this->languageFactory->findAvailableLocales();
$defaultProfile = $this->config->getAppValue($this->appName, 'defaultProfile', 'HOME');
$supportedNetworks = $this->socialApiService->getSupportedNetworks();

$this->initialStateService->provideInitialState($this->appName, 'locales', $locales);
$this->initialStateService->provideInitialState($this->appName, 'defaultProfile', $defaultProfile);

$this->initialStateService->provideInitialState($this->appName, 'supportedNetworks', $supportedNetworks);

Util::addScript($this->appName, 'contacts');
Util::addStyle($this->appName, 'contacts');

Expand Down
95 changes: 95 additions & 0 deletions lib/Controller/SocialApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* @copyright Copyright (c) 2020 Matthias Heinisch <nextcloud@matthiasheinisch.de>
*
* @author Matthias Heinisch <nextcloud@matthiasheinisch.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Contacts\Controller;

use OCA\Contacts\AppInfo\Application;
use OCA\Contacts\Service\SocialApiService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IRequest;

class SocialApiController extends ApiController {

/** @var IConfig */
private $config;

/** @var SocialApiService */
private $socialApiService;

public function __construct(IRequest $request,
IConfig $config,
SocialApiService $socialApiService) {
parent::__construct(Application::APP_ID, $request);

$this->config = $config;
$this->socialApiService = $socialApiService;
}


/**
* update appconfig (admin setting)
*
* @param {String} key the identifier to change
* @param {String} allow the value to set
*
* @returns {JSONResponse} an empty JSONResponse with respective http status code
*/
public function setAppConfig($key, $allow) {
$permittedKeys = ['allowSocialSync'];
if (!in_array($key, $permittedKeys)) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
$this->config->setAppValue(Application::APP_ID, $key, $allow);
return new JSONResponse([], Http::STATUS_OK);
}

/**
* @NoAdminRequired
*
* returns an array of supported social networks
*
* @returns {array} array of the supported social networks
*/
public function getSupportedNetworks() : array {
return $this->socialApiService->getSupportedNetworks();
}


/**
* @NoAdminRequired
*
* Retrieves social profile data for a contact and updates the entry
*
* @param {String} addressbookId the addressbook identifier
* @param {String} contactId the contact identifier
* @param {String} network the social network to use (if unkown: take first match)
*
* @returns {JSONResponse} an empty JSONResponse with respective http status code
*/
public function updateContact(string $addressbookId, string $contactId, string $network) : JSONResponse {
return $this->socialApiService->updateContact($addressbookId, $contactId, $network);
}
}
Loading

0 comments on commit a9232db

Please sign in to comment.