kopia lustrzana https://github.com/nextcloud/social
social is now an activitypub server
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/6/head
rodzic
3e399899ed
commit
4dddda0dc6
|
@ -2,5 +2,3 @@
|
|||
\.idea/
|
||||
|
||||
vendor/
|
||||
|
||||
test\.json
|
||||
|
|
|
@ -29,7 +29,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Social\AppInfo;
|
||||
|
||||
require_once __DIR__ . '/autoload.php';
|
||||
require_once(__DIR__ . '/../lib/autoload.php');
|
||||
|
||||
//$app = new Application();
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\AppInfo;
|
||||
|
||||
$composerDir = __DIR__ . '/../vendor/';
|
||||
|
||||
if (is_dir($composerDir) && file_exists($composerDir . 'autoload.php')) {
|
||||
require_once $composerDir . 'autoload.php';
|
||||
}
|
||||
|
|
@ -5,51 +5,6 @@
|
|||
<overwrite>false</overwrite>
|
||||
<charset>utf8</charset>
|
||||
|
||||
<table>
|
||||
<name>*dbprefix*social_services</name>
|
||||
<declaration>
|
||||
<field>
|
||||
<name>id</name>
|
||||
<type>integer</type>
|
||||
<length>7</length>
|
||||
<unsigned>true</unsigned>
|
||||
<notnull>true</notnull>
|
||||
<autoincrement>true</autoincrement>
|
||||
<primary>true</primary>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>type</name>
|
||||
<type>text</type>
|
||||
<length>15</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>address</name>
|
||||
<type>text</type>
|
||||
<length>128</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>config</name>
|
||||
<type>text</type>
|
||||
<length>3000</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>status</name>
|
||||
<type>integer</type>
|
||||
<length>1</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>creation</name>
|
||||
<type>timestamp</type>
|
||||
</field>
|
||||
|
||||
</declaration>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<name>*dbprefix*social_accounts</name>
|
||||
<declaration>
|
||||
|
@ -64,59 +19,16 @@
|
|||
<primary>true</primary>
|
||||
</field>
|
||||
|
||||
// @deprecated
|
||||
<field>
|
||||
<name>service_id</name>
|
||||
<type>integer</type>
|
||||
<length>7</length>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>user_id</name>
|
||||
<type>text</type>
|
||||
<length>63</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>username</name>
|
||||
<type>text</type>
|
||||
<length>63</length>
|
||||
</field>
|
||||
|
||||
// @deprecated
|
||||
<field>
|
||||
<name>account</name>
|
||||
<type>text</type>
|
||||
<length>127</length>
|
||||
</field>
|
||||
|
||||
// @deprecated
|
||||
<field>
|
||||
<name>account_id</name>
|
||||
<type>integer</type>
|
||||
<length>7</length>
|
||||
</field>
|
||||
|
||||
// @deprecated
|
||||
<field>
|
||||
<name>status</name>
|
||||
<type>integer</type>
|
||||
<length>1</length>
|
||||
</field>
|
||||
|
||||
// @deprecated
|
||||
<field>
|
||||
<name>auth</name>
|
||||
<type>text</type>
|
||||
<length>2000</length>
|
||||
</field>
|
||||
|
||||
// @deprecated
|
||||
<field>
|
||||
<name>config</name>
|
||||
<type>text</type>
|
||||
<length>2000</length>
|
||||
<length>63</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
|
@ -340,48 +252,5 @@
|
|||
</declaration>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<name>*dbprefix*social_cache_actors</name>
|
||||
<declaration>
|
||||
|
||||
<field>
|
||||
<name>id</name>
|
||||
<type>integer</type>
|
||||
<length>8</length>
|
||||
<unsigned>true</unsigned>
|
||||
<notnull>true</notnull>
|
||||
<autoincrement>true</autoincrement>
|
||||
<primary>true</primary>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>account</name>
|
||||
<type>text</type>
|
||||
<length>127</length>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>url</name>
|
||||
<type>text</type>
|
||||
<length>127</length>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>actor</name>
|
||||
<type>text</type>
|
||||
<length>8000</length>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>creation</name>
|
||||
<type>timestamp</type>
|
||||
</field>
|
||||
|
||||
</declaration>
|
||||
</table>
|
||||
|
||||
</database>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<name>Social</name>
|
||||
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
|
||||
<description><![CDATA[test]]></description>
|
||||
<version>0.0.17</version>
|
||||
<version>0.0.18</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
|
||||
<author mail="jus@bitgrid.net">Julius Härtl</author>
|
||||
|
|
|
@ -11,37 +11,7 @@ return [
|
|||
'routes' => [
|
||||
['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'],
|
||||
|
||||
[
|
||||
'name' => 'ServiceAccounts#getAvailableAccounts', 'url' => '/user/accounts',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
[
|
||||
'name' => 'ServiceAccounts#create', 'url' => '/user/account',
|
||||
'verb' => 'POST'
|
||||
],
|
||||
[
|
||||
'name' => 'ActivityStreams#test', 'url' => '/user/account/{accountId}/test',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
[
|
||||
'name' => 'ActivityStreams#statuses', 'url' => '/user/account/{accountId}/statuses',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
[
|
||||
'name' => 'ActivityStreams#follows', 'url' => '/user/account/{accountId}/follows',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
|
||||
// [
|
||||
// 'name' => 'OAuth2#getAuthUrl', 'url' => '/client/oauth2/auth/{serviceId}/',
|
||||
// 'verb' => 'GET'
|
||||
// ],
|
||||
[
|
||||
'name' => 'OAuth2#setCode', 'url' => '/client/oauth2/redirect/{serviceId}/',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
|
||||
['name' => 'Account#create', 'url' => '/local/account/{username}', 'verb' => 'POST'],
|
||||
['name' => 'Account#create', 'url' => '/local/account/{username}', 'verb' => 'GET'],
|
||||
|
||||
['name' => 'ActivityPub#sharedInbox', 'url' => '/inbox', 'verb' => 'POST'],
|
||||
['name' => 'ActivityPub#actor', 'url' => '/users/{username}', 'verb' => 'GET'],
|
||||
|
@ -52,9 +22,9 @@ return [
|
|||
['name' => 'ActivityPub#following', 'url' => '/@{username}/following', 'verb' => 'GET'],
|
||||
|
||||
['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{postId}', 'verb' => 'GET']
|
||||
,
|
||||
,
|
||||
['name' => 'ActivityPub#test', 'url' => '/inbox/{username}', 'verb' => 'POST'],
|
||||
|
||||
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"name": "vendor_name/package_name",
|
||||
"description": "description_text",
|
||||
"minimum-stability": "stable",
|
||||
"license": "proprietary",
|
||||
"authors": [
|
||||
{
|
||||
"name": "author's name",
|
||||
"email": "email@example.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"league/oauth2-client": "2.3.0",
|
||||
"lrf141/oauth2-mastodon": "1.0.1"
|
||||
}
|
||||
}
|
|
@ -1,422 +0,0 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "61a7838c51e287d8fb6c226460fd4e2c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "6.3.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba",
|
||||
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/promises": "^1.0",
|
||||
"guzzlehttp/psr7": "^1.4",
|
||||
"php": ">=5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-curl": "*",
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
|
||||
"psr/log": "^1.0"
|
||||
},
|
||||
"suggest": {
|
||||
"psr/log": "Required for using the Log middleware"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "6.3-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle is a PHP HTTP client library",
|
||||
"homepage": "http://guzzlephp.org/",
|
||||
"keywords": [
|
||||
"client",
|
||||
"curl",
|
||||
"framework",
|
||||
"http",
|
||||
"http client",
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"time": "2018-04-22T15:46:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
"version": "v1.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/promises.git",
|
||||
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Promise\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle promises library",
|
||||
"keywords": [
|
||||
"promise"
|
||||
],
|
||||
"time": "2016-12-20T10:07:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "1.4.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
|
||||
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"psr/http-message": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Psr7\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 message implementation that also provides common utility methods",
|
||||
"keywords": [
|
||||
"http",
|
||||
"message",
|
||||
"request",
|
||||
"response",
|
||||
"stream",
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2017-03-20T17:10:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/oauth2-client",
|
||||
"version": "2.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/oauth2-client.git",
|
||||
"reference": "aa2e3df188f0bfd87f7880cc880e906e99923580"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/aa2e3df188f0bfd87f7880cc880e906e99923580",
|
||||
"reference": "aa2e3df188f0bfd87f7880cc880e906e99923580",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^6.0",
|
||||
"paragonie/random_compat": "^1|^2",
|
||||
"php": "^5.6|^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"eloquent/liberator": "^2.0",
|
||||
"eloquent/phony-phpunit": "^1.0|^3.0",
|
||||
"jakub-onderka/php-parallel-lint": "^0.9.2",
|
||||
"phpunit/phpunit": "^5.7|^6.0",
|
||||
"squizlabs/php_codesniffer": "^2.3|^3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-2.x": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\OAuth2\\Client\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alex Bilbie",
|
||||
"email": "hello@alexbilbie.com",
|
||||
"homepage": "http://www.alexbilbie.com",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Woody Gilk",
|
||||
"homepage": "https://github.com/shadowhand",
|
||||
"role": "Contributor"
|
||||
}
|
||||
],
|
||||
"description": "OAuth 2.0 Client Library",
|
||||
"keywords": [
|
||||
"Authentication",
|
||||
"SSO",
|
||||
"authorization",
|
||||
"identity",
|
||||
"idp",
|
||||
"oauth",
|
||||
"oauth2",
|
||||
"single sign on"
|
||||
],
|
||||
"time": "2018-01-13T05:27:58+00:00"
|
||||
},
|
||||
{
|
||||
"name": "lrf141/oauth2-mastodon",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lrf141/oauth2-mastodon.git",
|
||||
"reference": "ba051985643bf46788c151dc70bc8ee85edff6a4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/lrf141/oauth2-mastodon/zipball/ba051985643bf46788c151dc70bc8ee85edff6a4",
|
||||
"reference": "ba051985643bf46788c151dc70bc8ee85edff6a4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"league/oauth2-client": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.1",
|
||||
"phpunit/phpunit": ">=5.4.3",
|
||||
"squizlabs/php_codesniffer": "^2.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Lrf141\\OAuth2\\Client\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "K.Takeuchi",
|
||||
"email": "ghost141.kentyo@gmail.com",
|
||||
"homepage": "https://github.com/lrf141",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Mastodon OAuth 2.0 support for the PHP League's OAuth 2.0 Client",
|
||||
"homepage": "https://github.com/lrf141/oauth2-client",
|
||||
"keywords": [
|
||||
"authorization",
|
||||
"client",
|
||||
"lrf141",
|
||||
"mastodon",
|
||||
"oauth2",
|
||||
"oauth2-mastodon"
|
||||
],
|
||||
"time": "2018-08-31T08:03:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "paragonie/random_compat",
|
||||
"version": "v2.0.17",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/paragonie/random_compat.git",
|
||||
"reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/29af24f25bab834fcbb38ad2a69fa93b867e070d",
|
||||
"reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.*|5.*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"lib/random.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paragon Initiative Enterprises",
|
||||
"email": "security@paragonie.com",
|
||||
"homepage": "https://paragonie.com"
|
||||
}
|
||||
],
|
||||
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
|
||||
"keywords": [
|
||||
"csprng",
|
||||
"polyfill",
|
||||
"pseudorandom",
|
||||
"random"
|
||||
],
|
||||
"time": "2018-07-04T16:31:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-message.git",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP messages",
|
||||
"homepage": "https://github.com/php-fig/http-message",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-message",
|
||||
"psr",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"time": "2016-08-06T14:39:51+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
136
js/test.js
136
js/test.js
|
@ -1,136 +0,0 @@
|
|||
(function () {
|
||||
|
||||
var Social = function () {
|
||||
|
||||
var elem = {
|
||||
socialInstanceNewAccount: null,
|
||||
socialSubmitNewAccount: null,
|
||||
socialListAccounts: null,
|
||||
socialSubmitAccountTest: null
|
||||
}
|
||||
|
||||
var test = {
|
||||
|
||||
newAccount: function () {
|
||||
var data = {
|
||||
instance: elem.socialInstanceNewAccount.val()
|
||||
}
|
||||
|
||||
test.sendRequest('POST', data, '/user/account', test.newAccountResult)
|
||||
},
|
||||
|
||||
newAccountResult: function (data) {
|
||||
if (data.status !== 1) {
|
||||
return
|
||||
}
|
||||
|
||||
window.open(data.result.authorizationUrl, 'gettoken', 'width=500,height=550')
|
||||
|
||||
// test.getAccounts()
|
||||
},
|
||||
|
||||
getAccounts: function () {
|
||||
test.sendRequest('GET', {}, '/user/accounts', test.getAccountsResult)
|
||||
},
|
||||
|
||||
getAccountsResult: function (data) {
|
||||
if (data.status !== 1) {
|
||||
return
|
||||
}
|
||||
|
||||
elem.socialListAccounts.empty()
|
||||
for (var i = 0; i < data.result.accounts.length; i++) {
|
||||
var item = data.result.accounts[i]
|
||||
elem.socialListAccounts.append(
|
||||
$('<option>', {value: item.id}).text(item.account + '@' + item.service.address))
|
||||
}
|
||||
|
||||
test.refreshData()
|
||||
},
|
||||
|
||||
testAccount: function (accountId) {
|
||||
test.sendRequest('GET', {}, '/user/account/' + accountId + '/test', test.testAccountResult)
|
||||
},
|
||||
|
||||
testAccountResult: function (data) {
|
||||
console.log(JSON.stringify(data))
|
||||
},
|
||||
|
||||
getAccountStatuses: function (accountId) {
|
||||
test.sendRequest('GET', {}, '/user/account/' + accountId + '/statuses',
|
||||
test.getAccountStatusesResult)
|
||||
},
|
||||
|
||||
getAccountStatusesResult: function (data) {
|
||||
console.log('Your posts: ' + JSON.stringify(data))
|
||||
},
|
||||
|
||||
getAccountFollows: function (accountId) {
|
||||
test.sendRequest('GET', {}, '/user/account/' + accountId + '/follows',
|
||||
test.getAccountFollowsResult)
|
||||
},
|
||||
|
||||
getAccountFollowsResult: function (data) {
|
||||
console.log('Your Follows: ' + JSON.stringify(data))
|
||||
},
|
||||
|
||||
refreshData: function () {
|
||||
var accountId = elem.socialListAccounts.val()
|
||||
test.getAccountFollows(accountId)
|
||||
test.getAccountStatuses(accountId)
|
||||
},
|
||||
|
||||
sendRequest: function (method, data, url, callback) {
|
||||
$.ajax({
|
||||
method: method,
|
||||
url: OC.generateUrl('/apps/social' + url),
|
||||
data: {data: data}
|
||||
}).done(function (res) {
|
||||
test.requestCallback(callback, res)
|
||||
}).fail(function () {
|
||||
console.log('fail to request')
|
||||
})
|
||||
},
|
||||
|
||||
requestCallback: function (callback, result) {
|
||||
if (callback && (typeof callback === 'function')) {
|
||||
if (typeof result === 'object') {
|
||||
callback(result)
|
||||
} else {
|
||||
callback({status: -1})
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
elem.socialInstanceNewAccount = $('#social-instance-new-account')
|
||||
elem.socialSubmitNewAccount = $('#social-submit-new-account')
|
||||
elem.socialListAccounts = $('#social-list-accounts')
|
||||
elem.socialSubmitAccountTest = $('#social-submit-account-test')
|
||||
|
||||
elem.socialSubmitNewAccount.on('click', function () {
|
||||
test.newAccount()
|
||||
})
|
||||
|
||||
elem.socialSubmitAccountTest.on('click', function () {
|
||||
test.testAccount(elem.socialListAccounts.val())
|
||||
})
|
||||
|
||||
elem.socialListAccounts.on('change', function () {
|
||||
test.refreshData()
|
||||
})
|
||||
|
||||
test.getAccounts()
|
||||
}
|
||||
|
||||
if (OCA.Social === undefined) {
|
||||
OCA.Social = {}
|
||||
}
|
||||
OCA.Social.test = new Social()
|
||||
|
||||
})()
|
|
@ -32,6 +32,7 @@ namespace OCA\Social\Command;
|
|||
|
||||
use Exception;
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
use OCA\Social\Service\ActivityPub\NoteService;
|
||||
use OCA\Social\Service\ActivityPubService;
|
||||
use OCA\Social\Service\ActorService;
|
||||
|
@ -66,7 +67,7 @@ class NoteCreate extends Base {
|
|||
|
||||
|
||||
/**
|
||||
* Index constructor.
|
||||
* NoteCreate constructor.
|
||||
*
|
||||
* @param ActivityPubService $activityPubService
|
||||
* @param ActorService $actorService
|
||||
|
@ -122,21 +123,14 @@ class NoteCreate extends Base {
|
|||
$to = $input->getOption('to');
|
||||
$replyTo = $input->getOption('replyTo');
|
||||
|
||||
$note = $this->noteService->generateNote($userId, $content, ActivityPubService::TO_PUBLIC);
|
||||
$note = $this->noteService->generateNote($userId, $content);
|
||||
|
||||
if ($to !== null) {
|
||||
$note->setTo($to);
|
||||
$note->addTag(
|
||||
[
|
||||
'type' => 'Mention',
|
||||
'href' => $to
|
||||
]
|
||||
);
|
||||
$this->noteService->assignTo($note, $to, InstancePath::INBOX);
|
||||
}
|
||||
|
||||
|
||||
if ($replyTo !== null) {
|
||||
$note->setInReplyTo($replyTo);
|
||||
$this->noteService->replyTo($note, $replyTo);
|
||||
}
|
||||
|
||||
$result = $this->activityPubService->createActivity($userId, $note, $activity);
|
||||
|
|
|
@ -29,17 +29,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Social\Controller;
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use daita\Traits\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\ActivityPubService;
|
||||
use OCA\Social\Service\ActivityStreamsService;
|
||||
use OCA\Social\Service\ActorService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\ServiceAccountsService;
|
||||
use OCA\Social\Service\ServicesService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
@ -85,9 +80,12 @@ class AccountController extends Controller {
|
|||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* Called by the frontend to create a new Social account
|
||||
*
|
||||
* @param array $data
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
|
|
|
@ -84,6 +84,13 @@ class ActivityPubController extends Controller {
|
|||
|
||||
|
||||
/**
|
||||
* returns information about an Actor, based on the username.
|
||||
*
|
||||
* This method should be called when a remote ActivityPub server require information
|
||||
* about a local Social account
|
||||
*
|
||||
* The format is pure Json
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
@ -91,7 +98,7 @@ class ActivityPubController extends Controller {
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function actor(string $username) {
|
||||
public function actor(string $username): Response {
|
||||
if (!$this->checkSourceActivityStreams()) {
|
||||
return $this->socialPubController->actor($username);
|
||||
}
|
||||
|
@ -108,6 +115,11 @@ class ActivityPubController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Alias to the actor() method.
|
||||
*
|
||||
* Normal path is /apps/social/users/username
|
||||
* This alias is /apps/social/@username
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
@ -115,35 +127,46 @@ class ActivityPubController extends Controller {
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function aliasactor(string $username) {
|
||||
public function aliasactor(string $username): Response {
|
||||
return $this->actor($username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shared inbox. does nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function sharedInbox() {
|
||||
public function sharedInbox(): Response {
|
||||
return $this->success([]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method is called when a remote ActivityPub server wants to POST in the INBOX of a USER
|
||||
*
|
||||
* Checking that the user exists, and that the header is properly signed.
|
||||
*
|
||||
* Does nothing. Should save data ($body) in database.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param $username
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function inbox($username) {
|
||||
public function inbox(string $username): Response {
|
||||
|
||||
try {
|
||||
$this->actorService->getActor($username);
|
||||
$this->activityPubService->checkRequest($this->request);
|
||||
// $this->noteService->receiving(file_get_contents('php://input'));
|
||||
$body = file_get_contents('php://input');
|
||||
$this->miscService->log('### ' . $body);
|
||||
|
||||
return $this->success([]);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
|
@ -152,26 +175,21 @@ $this->miscService->log('### ' . $body);
|
|||
|
||||
|
||||
/**
|
||||
* Testing method. does nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function test($username, $body) {
|
||||
|
||||
return $this->success([$username]);
|
||||
// $this->miscService->log('#### ' . $toto . ' ' . json_encode($_SERVER) . ' ' . json_encode($_POST));
|
||||
// try {
|
||||
// return $this->success(['author' => $author]);
|
||||
// } catch (Exception $e) {
|
||||
// return $this->fail('ddsaads');
|
||||
// }
|
||||
public function test(): Response {
|
||||
return $this->success(['toto']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Outbox. does nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
@ -179,12 +197,14 @@ $this->miscService->log('### ' . $body);
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function outbox($username) {
|
||||
public function outbox(string $username): Response {
|
||||
return $this->success([$username]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* followers. does nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
@ -192,7 +212,7 @@ $this->miscService->log('### ' . $body);
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function followers($username) {
|
||||
public function followers(string $username): Response {
|
||||
if (!$this->checkSourceActivityStreams()) {
|
||||
return $this->socialPubController->followers($username);
|
||||
}
|
||||
|
@ -202,6 +222,8 @@ $this->miscService->log('### ' . $body);
|
|||
|
||||
|
||||
/**
|
||||
* following. does nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
@ -209,7 +231,7 @@ $this->miscService->log('### ' . $body);
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function following($username) {
|
||||
public function following(string $username): Response {
|
||||
if (!$this->checkSourceActivityStreams()) {
|
||||
return $this->socialPubController->following($username);
|
||||
}
|
||||
|
@ -219,6 +241,8 @@ $this->miscService->log('### ' . $body);
|
|||
|
||||
|
||||
/**
|
||||
* should return data about a post. do nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
@ -228,16 +252,26 @@ $this->miscService->log('### ' . $body);
|
|||
* @return Response
|
||||
*/
|
||||
public function displayPost($username, $postId) {
|
||||
if (!$this->checkSourceActivityStreams()) {
|
||||
return $this->socialPubController->displayPost($username, $postId);
|
||||
}
|
||||
|
||||
return $this->success([$username, $postId]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that the request comes from an ActivityPub server, based on the header.
|
||||
*
|
||||
* If not, should forward to a readable webpage that displays content for navigation.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function checkSourceActivityStreams() {
|
||||
private function checkSourceActivityStreams(): bool {
|
||||
|
||||
// comment this line to display the result that would be return to an ActivityPub service (TEST)
|
||||
return true;
|
||||
|
||||
if ($this->request->getHeader('Accept')
|
||||
=== 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"') {
|
||||
return true;
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Controller;
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use daita\Traits\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\ActivityStreamsService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\ServiceAccountsService;
|
||||
use OCA\Social\Service\ServicesService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
|
||||
class ActivityStreamsController extends Controller {
|
||||
|
||||
use TArrayTools;
|
||||
use TNCDataResponse;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var ServiceAccountsService */
|
||||
private $serviceAccountsService;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccountsController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param string $userId
|
||||
* @param ConfigService $configService
|
||||
* @param ServiceAccountsService $serviceAccountsService
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, string $userId, ConfigService $configService,
|
||||
ServiceAccountsService $serviceAccountsService,
|
||||
ActivityStreamsService $activityStreamsService, MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->configService = $configService;
|
||||
$this->serviceAccountsService = $serviceAccountsService;
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function test(int $accountId): DataResponse {
|
||||
try {
|
||||
$account = $this->serviceAccountsService->getAccount($this->userId, $accountId);
|
||||
|
||||
$result = $this->activityStreamsService->test($account);
|
||||
|
||||
return $this->success($result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function statuses(int $accountId): DataResponse {
|
||||
try {
|
||||
$account = $this->serviceAccountsService->getAccount($this->userId, $accountId);
|
||||
|
||||
$result = $this->activityStreamsService->accountStatus($account);
|
||||
|
||||
return $this->success($result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function follows(int $accountId): DataResponse {
|
||||
try {
|
||||
$account = $this->serviceAccountsService->getAccount($this->userId, $accountId);
|
||||
$result = $this->activityStreamsService->accountFollows($account);
|
||||
|
||||
return $this->success($result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -71,13 +71,15 @@ class NavigationController extends Controller {
|
|||
|
||||
|
||||
/**
|
||||
* Display the navigation page of the Social app.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function navigate() {
|
||||
public function navigate(): TemplateResponse {
|
||||
$data = [];
|
||||
|
||||
return new TemplateResponse(Application::APP_NAME, 'main', $data);
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Controller;
|
||||
|
||||
|
||||
use daita\Traits\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\ServiceAccountsService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
class OAuth2Controller extends Controller {
|
||||
|
||||
|
||||
use TNCDataResponse;
|
||||
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var ServiceAccountsService */
|
||||
private $serviceAccountsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* NavigationController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param IConfig $config
|
||||
* @param string $userId
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param ServiceAccountsService $serviceAccountsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, IConfig $config, string $userId, IURLGenerator $urlGenerator,
|
||||
ServiceAccountsService $serviceAccountsService, MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->config = $config;
|
||||
$this->userId = $userId;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
|
||||
$this->serviceAccountsService = $serviceAccountsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setCode(int $serviceId) {
|
||||
|
||||
$code = $_GET['code'];
|
||||
// TODO: verify $state
|
||||
$state = $_GET['state'];
|
||||
|
||||
$this->serviceAccountsService->generateAccount($this->userId, $serviceId, $code);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Controller;
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use daita\Traits\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\ActivityStreamsService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\ServiceAccountsService;
|
||||
use OCA\Social\Service\ServicesService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
|
||||
class ServiceAccountsController extends Controller {
|
||||
|
||||
use TArrayTools;
|
||||
use TNCDataResponse;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var ServicesService */
|
||||
private $servicesService;
|
||||
|
||||
/** @var ServiceAccountsService */
|
||||
private $serviceAccountsService;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccountsController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param string $userId
|
||||
* @param ConfigService $configService
|
||||
* @param ServicesService $servicesService
|
||||
* @param ServiceAccountsService $serviceAccountsService
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, string $userId, ConfigService $configService,
|
||||
ServicesService $servicesService, ServiceAccountsService $serviceAccountsService,
|
||||
ActivityStreamsService $activityStreamsService, MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->configService = $configService;
|
||||
$this->servicesService = $servicesService;
|
||||
$this->serviceAccountsService = $serviceAccountsService;
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getAvailableAccounts(): DataResponse {
|
||||
try {
|
||||
$ret =
|
||||
['accounts' => $this->serviceAccountsService->getAvailableAccounts($this->userId)];
|
||||
|
||||
return $this->success($ret);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function create(array $data): DataResponse {
|
||||
try {
|
||||
$instance = strtolower($this->get('instance', $data, ''));
|
||||
if ($instance === '') {
|
||||
throw new Exception('Empty address');
|
||||
}
|
||||
|
||||
$service = $this->servicesService->createFromInstance($instance);
|
||||
|
||||
$authUrl = $this->serviceAccountsService->getAuthorizationUrl($service);
|
||||
$data = [
|
||||
'protocol' => 'OAuth2',
|
||||
'authorizationUrl' => $authUrl
|
||||
];
|
||||
|
||||
return $this->success($data);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ class SocialPubController extends Controller {
|
|||
|
||||
|
||||
/**
|
||||
* ActivityPubController constructor.
|
||||
* SocialPubController constructor.
|
||||
*
|
||||
* @param ActivityPubService $activityPubService
|
||||
* @param ActorService $actorService
|
||||
|
@ -76,45 +76,57 @@ class SocialPubController extends Controller {
|
|||
|
||||
|
||||
/**
|
||||
* return webpage content for human navigation.
|
||||
* Should return information about a Social account, based on username.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
e*
|
||||
* e*
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return Response
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function actor(string $username) {
|
||||
public function actor(string $username): TemplateResponse {
|
||||
return new TemplateResponse(Application::APP_NAME, 'actor', [], 'blank');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return webpage content for human navigation.
|
||||
* Should return followers of a Social account, based on username.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return Response
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function followers($username) {
|
||||
public function followers(string $username): TemplateResponse {
|
||||
return new TemplateResponse(Application::APP_NAME, 'followers', [], 'blank');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return webpage content for human navigation.
|
||||
* Should return following of a Social account, based on username.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return Response
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function following($username) {
|
||||
public function following(string $username): TemplateResponse {
|
||||
return new TemplateResponse(Application::APP_NAME, 'following', [], 'blank');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should return post, do nothing.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
@ -123,7 +135,7 @@ class SocialPubController extends Controller {
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function displayPost($username, $postId) {
|
||||
public function displayPost(string $username, int $postId) {
|
||||
return $this->success([$username, $postId]);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class ActorsRequest extends ActorsRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* ServicesRequest constructor.
|
||||
* ActorsRequest constructor.
|
||||
*
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
|
@ -54,6 +54,8 @@ class ActorsRequest extends ActorsRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* create a new Actor in the database.
|
||||
*
|
||||
* @param Actor $actor
|
||||
*
|
||||
* @return int
|
||||
|
@ -81,7 +83,7 @@ class ActorsRequest extends ActorsRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
* return Actor from database based on the username
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
|
@ -104,9 +106,8 @@ class ActorsRequest extends ActorsRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
* return Actor from database, based on the userId of the owner.
|
||||
*
|
||||
* @param string $userId
|
||||
*
|
||||
|
@ -129,45 +130,5 @@ class ActorsRequest extends ActorsRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// /**
|
||||
// * @param Service $service
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function update(Service $service): bool {
|
||||
//
|
||||
// try {
|
||||
// $this->getService($service->getId());
|
||||
// } catch (ServiceDoesNotExistException $e) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// $qb = $this->getServicesUpdateSql();
|
||||
// $qb->set('address', $qb->createNamedParameter($service->getAddress()));
|
||||
// $qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
// $qb->set('status', $qb->createNamedParameter($service->getStatus()));
|
||||
// $qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
//
|
||||
// $this->limitToId($qb, $service->getId());
|
||||
//
|
||||
// $qb->execute();
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
|
||||
// /**
|
||||
// * @param int $serviceId
|
||||
// */
|
||||
// public function delete(int $serviceId) {
|
||||
// $qb = $this->getServicesDeleteSql();
|
||||
// $this->limitToId($qb, $serviceId);
|
||||
//
|
||||
// $qb->execute();
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getActorsInsertSql() {
|
||||
protected function getActorsInsertSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_SERVER_ACTORS);
|
||||
|
||||
|
@ -58,7 +58,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getActorsUpdateSql() {
|
||||
protected function getActorsUpdateSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_SERVER_ACTORS);
|
||||
|
||||
|
@ -71,7 +71,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getActorsSelectSql() {
|
||||
protected function getActorsSelectSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
|
@ -92,7 +92,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getActorsDeleteSql() {
|
||||
protected function getActorsDeleteSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_SERVER_ACTORS);
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\Actor;
|
||||
use OCA\Social\Model\ActivityPub\Cache\CacheActor;
|
||||
|
@ -42,7 +41,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* ServicesRequest constructor.
|
||||
* CacheActorsRequest constructor.
|
||||
*
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
|
@ -56,7 +55,10 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* insert cache about an Actor in database.
|
||||
*
|
||||
* @param Actor $actor
|
||||
* @param array $object
|
||||
*
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
|
@ -79,14 +81,14 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
* get Cached value about an Actor, based on the account.
|
||||
*
|
||||
* @param string $account
|
||||
*
|
||||
* @return CacheActor
|
||||
* @throws CacheActorDoesNotExistException
|
||||
*/
|
||||
public function getFromAccount(string $account): Actor {
|
||||
public function getFromAccount(string $account): CacheActor {
|
||||
$qb = $this->getCacheActorsSelectSql();
|
||||
$this->limitToAccount($qb, $account);
|
||||
|
||||
|
@ -103,7 +105,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
* get Cached version of an Actor, based on the UriId
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
|
|
|
@ -31,10 +31,7 @@ namespace OCA\Social\Db;
|
|||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use OCA\Social\Model\ActivityPub\Actor;
|
||||
use OCA\Social\Model\ActivityPub\Cache\CacheActor;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
||||
|
@ -48,7 +45,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getCacheActorsInsertSql() {
|
||||
protected function getCacheActorsInsertSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_CACHE_ACTORS);
|
||||
|
||||
|
@ -61,7 +58,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getCacheActorsUpdateSql() {
|
||||
protected function getCacheActorsUpdateSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_CACHE_ACTORS);
|
||||
|
||||
|
@ -74,7 +71,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getCacheActorsSelectSql() {
|
||||
protected function getCacheActorsSelectSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
|
@ -94,7 +91,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getCacheActorsDeleteSql() {
|
||||
protected function getCacheActorsDeleteSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_CACHE_ACTORS);
|
||||
|
||||
|
|
|
@ -38,9 +38,6 @@ use OCP\IDBConnection;
|
|||
|
||||
class CoreRequestBuilder {
|
||||
|
||||
const TABLE_SERVICES = 'social_services';
|
||||
const TABLE_ACCOUNTS = 'social_accounts';
|
||||
|
||||
const TABLE_SERVER_ACTORS = 'social_server_actors';
|
||||
const TABLE_SERVER_NOTES = 'social_server_notes';
|
||||
|
||||
|
@ -199,30 +196,30 @@ class CoreRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Left Join service to get info about the serviceId
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
*/
|
||||
public function leftJoinService(IQueryBuilder &$qb) {
|
||||
|
||||
if ($qb->getType() !== QueryBuilder::SELECT) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expr = $qb->expr();
|
||||
$pf = $this->defaultSelectAlias;
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->selectAlias('s.address', 'service_address')
|
||||
->selectAlias('s.status', 'service_status')
|
||||
->selectAlias('s.config', 'service_config')
|
||||
->selectAlias('s.type', 'service_type')
|
||||
->leftJoin(
|
||||
$this->defaultSelectAlias, CoreRequestBuilder::TABLE_SERVICES, 's',
|
||||
$expr->eq($pf . '.service_id', 's.id')
|
||||
);
|
||||
}
|
||||
// /**
|
||||
// * Left Join service to get info about the serviceId
|
||||
// *
|
||||
// * @param IQueryBuilder $qb
|
||||
// */
|
||||
// public function leftJoinService(IQueryBuilder &$qb) {
|
||||
//
|
||||
// if ($qb->getType() !== QueryBuilder::SELECT) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// $expr = $qb->expr();
|
||||
// $pf = $this->defaultSelectAlias;
|
||||
//
|
||||
// /** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
// $qb->selectAlias('s.address', 'service_address')
|
||||
// ->selectAlias('s.status', 'service_status')
|
||||
// ->selectAlias('s.config', 'service_config')
|
||||
// ->selectAlias('s.type', 'service_type')
|
||||
// ->leftJoin(
|
||||
// $this->defaultSelectAlias, CoreRequestBuilder::TABLE_SERVICES, 's',
|
||||
// $expr->eq($pf . '.service_id', 's.id')
|
||||
// );
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,7 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\Note;
|
||||
use OCA\Social\Model\ActivityPub\Actor;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\IDBConnection;
|
||||
|
@ -41,7 +39,7 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* ServicesRequest constructor.
|
||||
* NotesRequest constructor.
|
||||
*
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
|
@ -55,6 +53,8 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* Insert a new Note in the database.
|
||||
*
|
||||
* @param Note $note
|
||||
*
|
||||
* @return int
|
||||
|
|
|
@ -45,7 +45,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesInsertSql() {
|
||||
protected function getNotesInsertSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_SERVER_NOTES);
|
||||
|
||||
|
@ -58,7 +58,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesUpdateSql() {
|
||||
protected function getNotesUpdateSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_SERVER_NOTES);
|
||||
|
||||
|
@ -71,7 +71,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesSelectSql() {
|
||||
protected function getNotesSelectSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
|
@ -92,7 +92,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getNotesDeleteSql() {
|
||||
protected function getNotesDeleteSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_SERVER_NOTES);
|
||||
|
||||
|
|
|
@ -1,231 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Db;
|
||||
|
||||
|
||||
use Exception;
|
||||
use OCA\Social\Exceptions\ServiceAccountDoesNotExistException;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
|
||||
class ServiceAccountsRequest extends ServiceAccountsRequestBuilder {
|
||||
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
|
||||
/**
|
||||
* ServicesRequest constructor.
|
||||
*
|
||||
* @param IL10N $l10n
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IL10n $l10n, IDBConnection $connection, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct($connection, $configService, $miscService);
|
||||
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(ServiceAccount $account): int {
|
||||
try {
|
||||
$service = $account->getService();
|
||||
$qb = $this->getAccountsInsertSql();
|
||||
$qb->setValue('service_id', $qb->createNamedParameter($service->getId()))
|
||||
->setValue('user_id', $qb->createNamedParameter($account->getUserId()))
|
||||
->setValue('account', $qb->createNamedParameter($account->getAccount()))
|
||||
->setValue('account_id', $qb->createNamedParameter($account->getAccountId()))
|
||||
->setValue('status', $qb->createNamedParameter($account->getStatus()))
|
||||
->setValue('auth', $qb->createNamedParameter(json_encode($account->getAuthAll())));
|
||||
|
||||
$qb->execute();
|
||||
|
||||
return $qb->getLastInsertId();
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
*
|
||||
* @return ServiceAccount[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAvailableAccounts(string $userId): array {
|
||||
try {
|
||||
$qb = $this->getAccountsSelectSql();
|
||||
$this->limitToUserId($qb, $userId);
|
||||
$this->limitToStatus($qb, 1);
|
||||
$this->leftJoinService($qb);
|
||||
|
||||
$accounts = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$accounts[] = $this->parseAccountsSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $accounts;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
* @param string $userId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return ServiceAccount
|
||||
* @throws ServiceAccountDoesNotExistException
|
||||
*/
|
||||
public function getFromAccountName(int $serviceId, string $userId, string $accountName) {
|
||||
$qb = $this->getAccountsSelectSql();
|
||||
$this->limitToUserId($qb, $userId);
|
||||
$this->limitToAccount($qb, $accountName);
|
||||
$this->limitToServiceId($qb, $serviceId);
|
||||
$this->leftJoinService($qb);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceAccountDoesNotExistException($this->l10n->t('Account not found'));
|
||||
}
|
||||
|
||||
return $this->parseAccountsSelectSql($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return account.
|
||||
*
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return ServiceAccount
|
||||
* @throws ServiceAccountDoesNotExistException
|
||||
*/
|
||||
public function getAccount(int $accountId): ServiceAccount {
|
||||
$qb = $this->getAccountsSelectSql();
|
||||
$this->limitToId($qb, $accountId);
|
||||
$this->leftJoinService($qb);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceAccountDoesNotExistException($this->l10n->t('Account not found'));
|
||||
}
|
||||
|
||||
return $this->parseAccountsSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * @param Service $service
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function update(Service $service): bool {
|
||||
//
|
||||
// try {
|
||||
// $this->getService($service->getId());
|
||||
// } catch (ServiceDoesNotExistException $e) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// $qb = $this->getServicesUpdateSql();
|
||||
// $qb->set('address', $qb->createNamedParameter($service->getAddress()));
|
||||
// $qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
// $qb->set('status', $qb->createNamedParameter($service->getStatus()));
|
||||
// $qb->set('auth', $qb->createNamedParameter(''));
|
||||
// $qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
//
|
||||
// $this->limitToId($qb, $service->getId());
|
||||
//
|
||||
// $qb->execute();
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @param int $serviceId
|
||||
// */
|
||||
// public function delete(int $serviceId) {
|
||||
// $qb = $this->getServicesDeleteSql();
|
||||
// $this->limitToId($qb, $serviceId);
|
||||
//
|
||||
// $qb->execute();
|
||||
// }
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
// /**
|
||||
// * return services.
|
||||
// *
|
||||
// * @return Service[]
|
||||
// */
|
||||
// public function getServices(): array {
|
||||
// $qb = $this->getServicesSelectSql();
|
||||
//
|
||||
// $services = [];
|
||||
// $cursor = $qb->execute();
|
||||
// while ($data = $cursor->fetch()) {
|
||||
// $services[] = $this->parseServicesSelectSql($data);
|
||||
// }
|
||||
// $cursor->closeCursor();
|
||||
//
|
||||
// return $services;
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Db;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
class ServiceAccountsRequestBuilder extends CoreRequestBuilder {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Insert request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsInsertSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_ACCOUNTS);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Update request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsUpdateSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_ACCOUNTS);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Select request for Shares
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsSelectSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->select(
|
||||
'a.id', 'a.service_id', 'a.user_id', 'a.account', 'a.account_id', 'a.status', 'a.auth',
|
||||
'a.config', 'a.creation'
|
||||
)
|
||||
->from(self::TABLE_ACCOUNTS, 'a');
|
||||
|
||||
$this->defaultSelectAlias = 'a';
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Delete request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsDeleteSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_ACCOUNTS);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
protected function parseAccountsSelectSql($data) {
|
||||
|
||||
$service = new Service($this->getInt('service_id', $data));
|
||||
$service->setAddress($this->get('service_address', $data, ''))
|
||||
->setStatus($this->getInt('service_status', $data, 0))
|
||||
->setConfigAll(json_decode($this->get('service_config', $data, '[]'), true))
|
||||
->setType($this->get('service_type', $data, ''));
|
||||
|
||||
$account = new ServiceAccount(intval($data['id']));
|
||||
$account->setService($service)
|
||||
->setUserId($data['user_id'])
|
||||
->setAccount($this->get('account', $data, ''))
|
||||
->setAccountId($this->getInt('account_id', $data, 0))
|
||||
->setStatus($this->getInt('status', $data, 0))
|
||||
->setAuthAll(json_decode($this->get('auth', $data, '[]'), true))
|
||||
->setConfigAll(json_decode($this->get('config', $data, '[]'), true))
|
||||
->setCreation($this->getInt('creation', $data, 0));
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Db;
|
||||
|
||||
|
||||
use OCA\Social\Exceptions\ServiceDoesNotExistException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
|
||||
class ServicesRequest extends ServicesRequestBuilder {
|
||||
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
|
||||
/**
|
||||
* ServicesRequest constructor.
|
||||
*
|
||||
* @param IL10N $l10n
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IL10n $l10n, IDBConnection $connection, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct($connection, $configService, $miscService);
|
||||
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $instance
|
||||
*
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create(string $type, string $instance): int {
|
||||
|
||||
try {
|
||||
$qb = $this->getServicesInsertSql();
|
||||
$qb->setValue('type', $qb->createNamedParameter($type))
|
||||
->setValue('address', $qb->createNamedParameter($instance))
|
||||
->setValue('status', $qb->createNamedParameter(Service::STATUS_SETUP));
|
||||
|
||||
$qb->execute();
|
||||
|
||||
return $qb->getLastInsertId();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update(Service $service): bool {
|
||||
|
||||
try {
|
||||
$this->getService($service->getId());
|
||||
} catch (ServiceDoesNotExistException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$qb = $this->getServicesUpdateSql();
|
||||
$qb->set('address', $qb->createNamedParameter($service->getAddress()));
|
||||
$qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
$qb->set('status', $qb->createNamedParameter($service->getStatus()));
|
||||
$qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
|
||||
$this->limitToId($qb, $service->getId());
|
||||
|
||||
$qb->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*/
|
||||
public function delete(int $serviceId) {
|
||||
$qb = $this->getServicesDeleteSql();
|
||||
$this->limitToId($qb, $serviceId);
|
||||
|
||||
$qb->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
*
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function getService(int $serviceId): Service {
|
||||
$qb = $this->getServicesSelectSql();
|
||||
$this->limitToId($qb, $serviceId);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceDoesNotExistException($this->l10n->t('Service not found'));
|
||||
}
|
||||
|
||||
return $this->parseServicesSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
*
|
||||
* @param string $instance
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function getServiceFromInstance(string $instance): Service {
|
||||
$qb = $this->getServicesSelectSql();
|
||||
$this->limitToAddress($qb, $instance);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceDoesNotExistException($this->l10n->t('Service not found'));
|
||||
}
|
||||
|
||||
return $this->parseServicesSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return services.
|
||||
*
|
||||
* @param bool $validOnly
|
||||
*
|
||||
* @return Service[]
|
||||
*/
|
||||
public function getServices($validOnly = false): array {
|
||||
$qb = $this->getServicesSelectSql();
|
||||
|
||||
if ($validOnly === true) {
|
||||
$this->limitToStatus($qb, 1);
|
||||
}
|
||||
|
||||
$services = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$services[] = $this->parseServicesSelectSql($data, $validOnly);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Db;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
class ServicesRequestBuilder extends CoreRequestBuilder {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Insert request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesInsertSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_SERVICES);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Update request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesUpdateSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_SERVICES);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Select request for Shares
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesSelectSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->select('s.id', 's.type', 's.address', 's.status', 's.config', 's.creation')
|
||||
->from(self::TABLE_SERVICES, 's');
|
||||
|
||||
$this->defaultSelectAlias = 's';
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Delete request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesDeleteSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_SERVICES);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param bool $sensitive
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
protected function parseServicesSelectSql($data, $sensitive = false) {
|
||||
$service = new Service(intval($data['id']));
|
||||
$service->setType($data['type'])
|
||||
->setAddress($data['address'])
|
||||
->setStatus($this->getInt('status', $data, -1))
|
||||
->setCreation($this->getInt('creation', $data, 0));
|
||||
|
||||
if ($sensitive === false) {
|
||||
$service->setConfigAll(json_decode($this->get('config', $data, '[]'), true));
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class APIRequestException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class AccountAlreadyExistsException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class AccountDoesNotExistException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ActivityStreamsRequestException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ActorAlreadyExistsException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class InvalidAccessTokenException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class MissingStuffException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class MovedPermanentlyException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class RequestException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ServiceAccountDoesNotExistException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ServiceAccountException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ServiceDoesNotExistException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class TokenGenerationException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ namespace OCA\Social\Model\ActivityPub;
|
|||
|
||||
|
||||
use JsonSerializable;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
use OCA\Social\Service\ICoreService;
|
||||
|
||||
class Core implements JsonSerializable {
|
||||
|
@ -51,6 +52,9 @@ class Core implements JsonSerializable {
|
|||
/** @var string */
|
||||
private $type;
|
||||
|
||||
/** @var InstancePath[] */
|
||||
private $instancePaths = [];
|
||||
|
||||
/** @var string */
|
||||
private $to = '';
|
||||
|
||||
|
@ -126,6 +130,50 @@ class Core implements JsonSerializable {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InstancePath $instancePath
|
||||
*
|
||||
* @return Core
|
||||
*/
|
||||
public function addInstancePath(InstancePath $instancePath): Core {
|
||||
$this->instancePaths[] = $instancePath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InstancePath[] $path
|
||||
*
|
||||
* @return Core
|
||||
*/
|
||||
public function addInstancePaths(array $path): Core {
|
||||
$this->instancePaths = array_merge($this->instancePaths, $path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return InstancePath[]
|
||||
*/
|
||||
public function getInstancePaths(): array {
|
||||
return $this->instancePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InstancePath[] $instancePaths
|
||||
*
|
||||
* @return Core
|
||||
*/
|
||||
public function setInstancePaths(array $instancePaths): Core {
|
||||
$this->instancePaths = $instancePaths;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Actor
|
||||
*/
|
||||
|
@ -220,6 +268,18 @@ class Core implements JsonSerializable {
|
|||
return $this->toArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*
|
||||
* @return Core
|
||||
*/
|
||||
public function addToArray(string $to): Core {
|
||||
$this->toArray[] = $to;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $toArray
|
||||
*
|
||||
|
|
|
@ -33,15 +33,16 @@ namespace OCA\Social\Model;
|
|||
use daita\Traits\TArrayTools;
|
||||
use JsonSerializable;
|
||||
|
||||
class APHosts implements JsonSerializable {
|
||||
class Instance implements JsonSerializable {
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var string */
|
||||
private $address;
|
||||
|
||||
/** @var array */
|
||||
private $uriIds = [];
|
||||
/** @var InstancePath[] */
|
||||
private $instancePaths = [];
|
||||
|
||||
public function __construct(string $address = '') {
|
||||
$this->address = $address;
|
||||
|
@ -57,28 +58,28 @@ class APHosts implements JsonSerializable {
|
|||
|
||||
|
||||
/**
|
||||
* @param string $uriId
|
||||
* @param InstancePath $path
|
||||
*
|
||||
* @return APHosts
|
||||
* @return Instance
|
||||
*/
|
||||
public function addUriId(string $uriId): APHosts {
|
||||
$this->uriIds[] = $uriId;
|
||||
public function addPath(InstancePath $path): Instance {
|
||||
$this->instancePaths[] = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return InstancePath[]
|
||||
*/
|
||||
public function getUriIds(): array {
|
||||
return $this->uriIds;
|
||||
public function getInstancePaths(): array {
|
||||
return $this->instancePaths;
|
||||
}
|
||||
|
||||
|
||||
public function jsonSerialize() {
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'address' => $this->address,
|
||||
'urlIds' => $this->getUriIds()
|
||||
'address' => $this->address,
|
||||
'instancePaths' => $this->getInstancePaths()
|
||||
];
|
||||
}
|
||||
|
|
@ -27,24 +27,82 @@ declare(strict_types=1);
|
|||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Traits;
|
||||
namespace OCA\Social\Model;
|
||||
|
||||
|
||||
trait TOAuth2 {
|
||||
use daita\Traits\TArrayTools;
|
||||
use JsonSerializable;
|
||||
|
||||
class InstancePath implements JsonSerializable {
|
||||
|
||||
|
||||
const INBOX = 1;
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var string */
|
||||
private $uri = '';
|
||||
|
||||
/** @var int */
|
||||
private $type;
|
||||
|
||||
|
||||
public function __construct(string $uri, $type = 0) {
|
||||
$this->uri = $uri;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateRedirectUrl(int $serviceId): string {
|
||||
return \OC::$server->getURlGenerator()
|
||||
->linkToRouteAbsolute(
|
||||
'social.OAuth2.setCode',
|
||||
['serviceId' => $serviceId]
|
||||
);
|
||||
public function getUri(): string {
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
*
|
||||
* @return InstancePath
|
||||
*/
|
||||
public function setUri(string $uri): InstancePath {
|
||||
$this->uri = $uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(): int {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
*
|
||||
* @return InstancePath
|
||||
*/
|
||||
public function setType(int $type): InstancePath {
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'uri' => $this->getUri(),
|
||||
'type' => $this->getType()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Model;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
|
||||
class Service implements \JsonSerializable {
|
||||
|
||||
|
||||
const STATUS_SETUP = 0;
|
||||
const STATUS_VALID = 1;
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $type = '';
|
||||
|
||||
/** @var string */
|
||||
private $address = '';
|
||||
|
||||
/** @var int */
|
||||
private $status = -1;
|
||||
|
||||
/** @var array */
|
||||
private $config = [];
|
||||
|
||||
/** @var int */
|
||||
private $creation = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Service constructor.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct(int $id = 0) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setId(int $id): Service {
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setType(string $type): Service {
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress(): string {
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setAddress(string $address): Service {
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): int {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setStatus(int $status): Service {
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigAll(): array {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setConfigAll(array $config): Service {
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param string $default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConfig(string $key, string $default = ''): string {
|
||||
return $this->get($key, $this->config, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setConfig(string $key, string $value): Service {
|
||||
$this->config[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function unsetConfig(string $key): Service {
|
||||
unset($this->config[$key]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCreation(): int {
|
||||
return $this->creation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $creation
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setCreation(int $creation): Service {
|
||||
$this->creation = $creation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'type' => $this->getType(),
|
||||
'address' => $this->getAddress(),
|
||||
'status' => $this->getStatus(),
|
||||
'config' => $this->getConfigAll(),
|
||||
'creation' => $this->getCreation()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,348 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Model;
|
||||
|
||||
|
||||
class ServiceAccount implements \JsonSerializable {
|
||||
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var Service */
|
||||
private $service;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var string */
|
||||
private $account = '';
|
||||
|
||||
/** @var int */
|
||||
private $accountId = 0;
|
||||
|
||||
/** @var int */
|
||||
private $status = 0;
|
||||
|
||||
/** @var array */
|
||||
private $auth = [];
|
||||
|
||||
/** @var array */
|
||||
private $config = [];
|
||||
|
||||
/** @var int */
|
||||
private $creation = 0;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccount constructor.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct(int $id = 0) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setId(int $id): ServiceAccount {
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Service
|
||||
*/
|
||||
public function getService(): Service {
|
||||
return $this->service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setService(Service $service): ServiceAccount {
|
||||
$this->service = $service;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUserId(): string {
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setUserId(string $userId): ServiceAccount {
|
||||
$this->userId = $userId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getAccountId(): int {
|
||||
return $this->accountId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAccountId(int $accountId): ServiceAccount {
|
||||
$this->accountId = $accountId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccount(): string {
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $account
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAccount(string $account): ServiceAccount {
|
||||
$this->account = $account;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): int {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setStatus(int $status): ServiceAccount {
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuth(string $k): string {
|
||||
return $this->auth[$k];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAuthInt(string $k): int {
|
||||
return $this->auth[$k];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthAll(): array {
|
||||
return $this->auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $auth
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAuthAll(array $auth): ServiceAccount {
|
||||
$this->auth = $auth;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param string $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAuth(string $k, string $v): ServiceAccount {
|
||||
$this->auth[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param int $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAuthInt(string $k, int $v): ServiceAccount {
|
||||
$this->auth[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConfig(string $k): string {
|
||||
return $this->config[$k];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getConfigInt(string $k): int {
|
||||
return $this->config[$k];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigAll(): array {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param string $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setConfig(string $k, string $v): ServiceAccount {
|
||||
$this->config[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param int $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setConfigInt(string $k, int $v): ServiceAccount {
|
||||
$this->config[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setConfigAll(array $config): ServiceAccount {
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCreation(): int {
|
||||
return $this->creation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $creation
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setCreation(int $creation): ServiceAccount {
|
||||
$this->creation = $creation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'service' => $this->getService(),
|
||||
'userId' => $this->getUserId(),
|
||||
'account' => $this->getAccount(),
|
||||
'account_id' => $this->getAccountId(),
|
||||
'auth' => $this->getAuthAll(),
|
||||
'creation' => $this->getCreation()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Service\ActivityPub;
|
||||
|
||||
|
||||
use Exception;
|
||||
use OC\User\NoUserException;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\Core;
|
||||
use OCA\Social\Model\ActivityPub\Note;
|
||||
use OCA\Social\Service\ActivityStreamsService;
|
||||
use OCA\Social\Service\ActorService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\CurlService;
|
||||
use OCA\Social\Service\ICoreService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
|
||||
class InboxService implements ICoreService {
|
||||
|
||||
/** @var InboxRequest */
|
||||
private $inboxRequest;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* InboxService constructor.
|
||||
*
|
||||
* @param InboxRequest $inboxRequest
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
InboxRequest $inboxRequest,
|
||||
ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->inboxRequest = $inboxRequest;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,7 +36,8 @@ use OCA\Social\Db\NotesRequest;
|
|||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\Core;
|
||||
use OCA\Social\Model\ActivityPub\Note;
|
||||
use OCA\Social\Service\ActivityStreamsService;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
use OCA\Social\Service\ActivityPubService;
|
||||
use OCA\Social\Service\ActorService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\CurlService;
|
||||
|
@ -45,12 +46,10 @@ use OCA\Social\Service\MiscService;
|
|||
|
||||
class NoteService implements ICoreService {
|
||||
|
||||
|
||||
/** @var NotesRequest */
|
||||
private $notesRequest;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var ActorService */
|
||||
private $actorService;
|
||||
|
||||
|
@ -68,21 +67,17 @@ class NoteService implements ICoreService {
|
|||
* NoteService constructor.
|
||||
*
|
||||
* @param NotesRequest $notesRequest
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param ActorService $actorService
|
||||
* @param CurlService $curlService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, ActivityStreamsService $activityStreamsService,
|
||||
ActorService $actorService,
|
||||
CurlService $curlService,
|
||||
ConfigService $configService,
|
||||
NotesRequest $notesRequest, ActorService $actorService,
|
||||
CurlService $curlService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->actorService = $actorService;
|
||||
$this->curlService = $curlService;
|
||||
$this->configService = $configService;
|
||||
|
@ -93,13 +88,12 @@ class NoteService implements ICoreService {
|
|||
/**
|
||||
* @param string $userId
|
||||
* @param string $content
|
||||
* @param string $to
|
||||
*
|
||||
* @return Note
|
||||
* @throws ActorDoesNotExistException
|
||||
* @throws NoUserException
|
||||
*/
|
||||
public function generateNote(string $userId, string $content, string $to) {
|
||||
public function generateNote(string $userId, string $content) {
|
||||
$note = new Note();
|
||||
$actor = $this->actorService->getActorFromUserId($userId);
|
||||
|
||||
|
@ -108,7 +102,7 @@ class NoteService implements ICoreService {
|
|||
$note->setAttributedTo(
|
||||
$this->configService->getRoot() . '@' . $actor->getPreferredUsername()
|
||||
);
|
||||
$note->setTo($to);
|
||||
$note->setTo(ActivityPubService::TO_PUBLIC);
|
||||
$note->setContent($content);
|
||||
|
||||
$note->saveAs($this);
|
||||
|
@ -118,6 +112,36 @@ class NoteService implements ICoreService {
|
|||
|
||||
|
||||
/**
|
||||
* @param Note $note
|
||||
* @param string $to
|
||||
* @param int $type
|
||||
*/
|
||||
public function assignTo(Note $note, string $to, int $type) {
|
||||
$note->addToArray($to);
|
||||
$note->addTag(
|
||||
[
|
||||
'type' => 'Mention',
|
||||
'href' => $to
|
||||
]
|
||||
);
|
||||
|
||||
$note->addInstancePath(new InstancePath($to, $type));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Note $note
|
||||
* @param string $replyTo
|
||||
*/
|
||||
public function replyTo(Note $note, string $replyTo) {
|
||||
$note->setInReplyTo($replyTo);
|
||||
$note->addInstancePath(new InstancePath($replyTo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when saving the Note object
|
||||
*
|
||||
* @param Core $note
|
||||
*
|
||||
* @throws Exception
|
||||
|
|
|
@ -36,13 +36,11 @@ use Exception;
|
|||
use OC\User\NoUserException;
|
||||
use OCA\Social\Db\ActorsRequest;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\APIRequestException;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Exceptions\MovedPermanentlyException;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
use OCA\Social\Model\ActivityPub\ActivityCreate;
|
||||
use OCA\Social\Model\ActivityPub\Actor;
|
||||
use OCA\Social\Model\ActivityPub\Core;
|
||||
use OCA\Social\Model\ActivityPub\Note;
|
||||
use OCA\Social\Model\APHosts;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
use OCP\IRequest;
|
||||
|
||||
class ActivityPubService {
|
||||
|
@ -56,15 +54,15 @@ class ActivityPubService {
|
|||
const DATE_FORMAT = 'D, d M Y H:i:s T';
|
||||
const DATE_DELAY = 30;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var ActorsRequest */
|
||||
private $actorsRequest;
|
||||
|
||||
/** @var ActorService */
|
||||
private $actorService;
|
||||
|
||||
/** @var InstanceService */
|
||||
private $instanceService;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
|
@ -76,26 +74,23 @@ class ActivityPubService {
|
|||
|
||||
|
||||
/**
|
||||
* ActivityStreamsService constructor.
|
||||
* ActivityPubService constructor.
|
||||
*
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param CurlService $curlService
|
||||
* @param ActorsRequest $actorsRequest
|
||||
* @param CurlService $curlService
|
||||
* @param ActorService $actorService
|
||||
* @param InstanceService $instanceService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ActivityStreamsService $activityStreamsService,
|
||||
CurlService $curlService,
|
||||
ActorsRequest $actorsRequest,
|
||||
ActorService $actorService,
|
||||
ConfigService $configService, MiscService $miscService
|
||||
ActorsRequest $actorsRequest, CurlService $curlService, ActorService $actorService,
|
||||
InstanceService $instanceService, ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->curlService = $curlService;
|
||||
$this->actorsRequest = $actorsRequest;
|
||||
$this->actorService = $actorService;
|
||||
$this->instanceService = $instanceService;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
@ -116,9 +111,7 @@ class ActivityPubService {
|
|||
* @return array
|
||||
* @throws ActorDoesNotExistException
|
||||
* @throws NoUserException
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function createActivity($userId, Core $item, Core &$activity = null): array {
|
||||
|
||||
|
@ -128,11 +121,13 @@ class ActivityPubService {
|
|||
$actor = $this->actorService->getActorFromUserId($userId);
|
||||
$activity->setId($item->getId() . '/activity');
|
||||
|
||||
if ($item->getToArray() !== []) {
|
||||
$activity->setToArray($item->getToArray());
|
||||
} else {
|
||||
$activity->setTo($item->getTo());
|
||||
}
|
||||
$activity->addInstancePaths($item->getInstancePaths());
|
||||
|
||||
// if ($item->getToArray() !== []) {
|
||||
// $activity->setToArray($item->getToArray());
|
||||
// } else {
|
||||
// $activity->setTo($item->getTo());
|
||||
// }
|
||||
|
||||
$activity->setActor($actor);
|
||||
$activity->setObject($item);
|
||||
|
@ -148,17 +143,17 @@ class ActivityPubService {
|
|||
* @param Core $activity
|
||||
*
|
||||
* @return array
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function request(Core $activity) {
|
||||
$hosts = $this->getAPHostsFromActivity($activity);
|
||||
|
||||
$hosts = $this->instanceService->getInstancesFromActivity($activity);
|
||||
|
||||
$result = [];
|
||||
foreach ($hosts as $host) {
|
||||
$request = $this->generateRequest($host, $activity);
|
||||
$result[] = $this->curlService->request($request);
|
||||
foreach ($host->getInstancePaths() as $path) {
|
||||
$result[] = $this->generateRequest($host->getAddress(), $path, $activity);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -166,23 +161,25 @@ class ActivityPubService {
|
|||
|
||||
|
||||
/**
|
||||
* @param APHosts $host
|
||||
* @param string $address
|
||||
* @param InstancePath $path
|
||||
* @param Core $activity
|
||||
*
|
||||
* @return Request
|
||||
* @return Request[]
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function generateRequest(APHosts $host, Core $activity): Request {
|
||||
|
||||
public function generateRequest(string $address, InstancePath $path, Core $activity): array {
|
||||
$document = json_encode($activity);
|
||||
$date = date(self::DATE_FORMAT);
|
||||
|
||||
$localActor = $activity->getActor();
|
||||
$uriIds = $host->getUriIds();
|
||||
$remoteActor = $this->getRemoteActor($uriIds[0]);
|
||||
$remoteActor = $this->getRemoteActor($path->getUri());
|
||||
|
||||
$remotePath = $this->actorService->getPathFromActor($remoteActor, $path->getType());
|
||||
|
||||
$localActorLink =
|
||||
$this->configService->getRoot() . '@' . $localActor->getPreferredUsername();
|
||||
$signature = "(request-target): post /users/testSocial/inbox\nhost: " . $host->getAddress()
|
||||
$signature = "(request-target): post " . $remotePath . "\nhost: " . $address
|
||||
. "\ndate: " . $date;
|
||||
|
||||
openssl_sign($signature, $signed, $localActor->getPrivateKey(), OPENSSL_ALGO_SHA256);
|
||||
|
@ -192,24 +189,21 @@ class ActivityPubService {
|
|||
'keyId="' . $localActorLink . '",headers="(request-target) host date",signature="'
|
||||
. $signed . '"';
|
||||
|
||||
$request = new Request('/users/testSocial/inbox', Request::TYPE_POST);
|
||||
$request->addHeader('Host: ' . $host->getAddress());
|
||||
$request = new Request($remotePath, Request::TYPE_POST);
|
||||
$request->addHeader('Host: ' . $address);
|
||||
$request->addHeader('Date: ' . $date);
|
||||
$request->addHeader('Signature: ' . $header);
|
||||
|
||||
$request->setDataJson($document);
|
||||
$request->setAddress($host->getAddress());
|
||||
$request->setAddress($address);
|
||||
|
||||
return $request;
|
||||
return $this->curlService->request($request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param IRequest $request
|
||||
*
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkRequest(IRequest $request) {
|
||||
|
@ -248,64 +242,11 @@ class ActivityPubService {
|
|||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @param Core $activity
|
||||
*
|
||||
* @return APHosts[]
|
||||
*/
|
||||
private function getAPHostsFromActivity(Core $activity) {
|
||||
|
||||
$hosts = [];
|
||||
// $uriIds = [];
|
||||
$this->addAPHosts($activity->getTo(), $hosts);
|
||||
foreach ($activity->getToArray() as $to) {
|
||||
$this->addAPHosts($to, $hosts);
|
||||
// $uriIds[] = $to;
|
||||
}
|
||||
|
||||
if ($activity instanceof Note) {
|
||||
/** @var Note $activity */
|
||||
$this->addAPHosts($activity->getInReplyTo(), $hosts);
|
||||
// $uriIds[] = $activity->getInReplyTo();
|
||||
}
|
||||
|
||||
// $uriId = $this->cleaningHosts($uriId);
|
||||
|
||||
return $hosts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $uriId
|
||||
* @param APHosts[] $hosts
|
||||
*/
|
||||
private function addAPHosts(string $uriId, array &$hosts) {
|
||||
$address = $this->getHostFromUriId($uriId);
|
||||
if ($address === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
if ($host->getAddress() === $address) {
|
||||
$host->addUriId($uriId);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$apHost = new APHosts($address);
|
||||
$apHost->addUriId($uriId);
|
||||
$hosts[] = $apHost;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $uriId
|
||||
*
|
||||
* @return mixed
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @return Actor
|
||||
* @throws RequestException
|
||||
*/
|
||||
private function getRemoteActor(string $uriId) {
|
||||
$actor = $this->actorService->getFromUri($uriId);
|
||||
|
@ -314,29 +255,6 @@ class ActivityPubService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $uriId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getHostFromUriId(string $uriId) {
|
||||
$ignoreThose = [
|
||||
'',
|
||||
'https://www.w3.org/ns/activitystreams#Public'
|
||||
];
|
||||
|
||||
if (in_array($uriId, $ignoreThose)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = parse_url($uriId);
|
||||
if (!is_array($url) || !array_key_exists('host', $url)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $url['host'];
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * @param array $hosts
|
||||
|
@ -360,9 +278,6 @@ class ActivityPubService {
|
|||
/**
|
||||
* @param IRequest $request
|
||||
*
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function checkSignature(IRequest $request) {
|
||||
|
@ -377,6 +292,7 @@ class ActivityPubService {
|
|||
$estimated = $this->generateEstimatedSignature($headers, $request);
|
||||
|
||||
$publicKey = $this->retrieveKey($keyId);
|
||||
|
||||
if (openssl_verify($estimated, $signed, $publicKey, 'sha256') !== 1) {
|
||||
throw new Exception('signature cannot be checked');
|
||||
}
|
||||
|
@ -389,11 +305,14 @@ class ActivityPubService {
|
|||
* @param IRequest $request
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
private function generateEstimatedSignature(string $headers, IRequest $request): string {
|
||||
$keys = explode(' ', $headers);
|
||||
|
||||
$estimated = "(request-target): post /apps/social/@maxence/inbox";
|
||||
$remoteTarget = strtolower($request->getMethod()) . " " . $request->getPathInfo();
|
||||
$estimated = "(request-target): " . $remoteTarget;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if ($key === '(request-target)') {
|
||||
continue;
|
||||
|
@ -431,36 +350,14 @@ class ActivityPubService {
|
|||
* @param $keyId
|
||||
*
|
||||
* @return array
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws RequestException
|
||||
*/
|
||||
private function retrieveKey($keyId) {
|
||||
$actor = $this->retrieveObject($keyId);
|
||||
$actor = $this->instanceService->retrieveObject($keyId);
|
||||
|
||||
return $actor['publicKey']['publicKeyPem'];
|
||||
}
|
||||
|
||||
//
|
||||
// /**
|
||||
// * @param $id
|
||||
// *
|
||||
// * @return mixed
|
||||
// * @throws MovedPermanentlyException
|
||||
// * @throws APIRequestException
|
||||
// * @throws InvalidAccessTokenException
|
||||
// */
|
||||
// private function retrieveObject($id) {
|
||||
// $url = parse_url($id);
|
||||
//
|
||||
// $request = new Request($url['path'], Request::TYPE_GET);
|
||||
// $request->setAddress($url['host']);
|
||||
//
|
||||
//// $key = $url['fragment'];
|
||||
//
|
||||
// return $this->curlService->request($request);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @param Core $activity
|
||||
|
@ -482,10 +379,4 @@ class ActivityPubService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// public function setRoot(IActivityPub $actor) {
|
||||
// $actor->setRoot('https://test.artificial-owl.com/apps/social');
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Service;
|
||||
|
||||
|
||||
use daita\Model\Request;
|
||||
use Exception;
|
||||
use OCA\Social\Db\ServiceAccountsRequest;
|
||||
use OCA\Social\Exceptions\ActivityStreamsRequestException;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Model\ActivityPub\Core;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Traits\TOAuth2;
|
||||
|
||||
class ActivityStreamsService {
|
||||
|
||||
|
||||
const URL_CREATE_APP = '/api/v1/apps';
|
||||
const URL_VERIFY_ACCOUNT = '/api/v1/accounts/verify_credentials';
|
||||
const URL_TEST = '/api/v1/accounts/verify_credentials';
|
||||
const URL_ACCOUNT_STATUSES = '/api/v1/accounts/:id/statuses';
|
||||
const URL_ACCOUNT_FOLLOWS = '/api/v1/accounts/:id/following';
|
||||
const URL_ACCOUNT_FOLLOWERS = '/api/v1/accounts/:id/followers';
|
||||
|
||||
|
||||
use TOAuth2;
|
||||
|
||||
/** @var ServiceAccountsRequest */
|
||||
private $serviceAccountsRequest;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var ClientCurlService */
|
||||
private $clientCurlService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityStreamsService constructor.
|
||||
*
|
||||
* @param ServiceAccountsRequest $serviceAccountsRequest
|
||||
* @param ConfigService $configService
|
||||
* @param ClientCurlService $clientCurlService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceAccountsRequest $serviceAccountsRequest, ConfigService $configService,
|
||||
ClientCurlService $clientCurlService, MiscService $miscService
|
||||
) {
|
||||
$this->serviceAccountsRequest = $serviceAccountsRequest;
|
||||
$this->configService = $configService;
|
||||
$this->clientCurlService = $clientCurlService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Core $core
|
||||
*/
|
||||
public function initCore(Core &$core) {
|
||||
$core->setRoot('https://test.artificial-owl.com/apps/social');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO : clean below !
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function test(ServiceAccount $account) {
|
||||
$request = new Request(self::URL_TEST, Request::TYPE_GET);
|
||||
|
||||
return $this->request($account, $request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function accountStatus(ServiceAccount $account) {
|
||||
$request = new Request(self::URL_ACCOUNT_STATUSES, Request::TYPE_GET);
|
||||
$request->addDataInt('id', $account->getAccountId());
|
||||
|
||||
return $this->request($account, $request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function accountFollows(ServiceAccount $account) {
|
||||
$request = new Request(self::URL_ACCOUNT_FOLLOWS, Request::TYPE_GET);
|
||||
$request->addDataInt('id', $account->getAccountId());
|
||||
|
||||
return $this->request($account, $request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAccountInformation(ServiceAccount $account) {
|
||||
$request = new Request(self::URL_VERIFY_ACCOUNT, Request::TYPE_GET);
|
||||
|
||||
return $this->request($account, $request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @throws ActivityStreamsRequestException
|
||||
*/
|
||||
private function request(ServiceAccount $account, Request $request) {
|
||||
try {
|
||||
return $this->clientCurlService->request($account, $request, true);
|
||||
} catch (InvalidAccessTokenException $e) {
|
||||
// $this->oAuth2TokensRequest->resetToken($auth);
|
||||
throw new ActivityStreamsRequestException($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$message = 'Issue with ' . json_encode($request) . ' - ' . get_class($e) . ' - '
|
||||
. $e->getMessage();
|
||||
|
||||
$this->miscService->log($message);
|
||||
throw new ActivityStreamsRequestException($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -35,13 +35,12 @@ use Exception;
|
|||
use OC\User\NoUserException;
|
||||
use OCA\Social\Db\ActorsRequest;
|
||||
use OCA\Social\Db\CacheActorsRequest;
|
||||
use OCA\Social\Exceptions\ActorAlreadyExistsException;
|
||||
use OCA\Social\Exceptions\AccountAlreadyExistsException;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\APIRequestException;
|
||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Exceptions\MovedPermanentlyException;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
use OCA\Social\Model\ActivityPub\Actor;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
|
||||
class ActorService {
|
||||
|
||||
|
@ -49,8 +48,8 @@ class ActorService {
|
|||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var UriIdService */
|
||||
private $uriIdService;
|
||||
/** @var InstanceService */
|
||||
private $instanceService;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
@ -66,21 +65,21 @@ class ActorService {
|
|||
|
||||
|
||||
/**
|
||||
* ActivityStreamsService constructor.
|
||||
* ActorService constructor.
|
||||
*
|
||||
* @param ActorsRequest $actorsRequest
|
||||
* @param CacheActorsRequest $cacheActorsRequest
|
||||
* @param UriIdService $uriIdService
|
||||
* @param InstanceService $instanceService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ActorsRequest $actorsRequest,
|
||||
CacheActorsRequest $cacheActorsRequest, UriIdService $uriIdService,
|
||||
CacheActorsRequest $cacheActorsRequest, InstanceService $instanceService,
|
||||
ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->configService = $configService;
|
||||
$this->uriIdService = $uriIdService;
|
||||
$this->instanceService = $instanceService;
|
||||
$this->actorsRequest = $actorsRequest;
|
||||
$this->cacheActorsRequest = $cacheActorsRequest;
|
||||
$this->miscService = $miscService;
|
||||
|
@ -92,8 +91,8 @@ class ActorService {
|
|||
*
|
||||
* @return Actor
|
||||
* @throws ActorDoesNotExistException
|
||||
* @throws NoUserException
|
||||
*/
|
||||
|
||||
public function getActor(string $username): Actor {
|
||||
$actor = $this->actorsRequest->getFromUsername($username);
|
||||
|
||||
|
@ -120,9 +119,7 @@ class ActorService {
|
|||
* @param string $uriId
|
||||
*
|
||||
* @return Actor
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws RequestException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getFromUri(string $uriId) {
|
||||
|
@ -132,7 +129,7 @@ class ActorService {
|
|||
|
||||
return $this->generateActor($cache->getActor());
|
||||
} catch (CacheActorDoesNotExistException $e) {
|
||||
$object = $this->uriIdService->retrieveObject($uriId);
|
||||
$object = $this->instanceService->retrieveObject($uriId);
|
||||
$actor = $this->generateActor($object);
|
||||
$this->cacheActorsRequest->create($actor, $object);
|
||||
|
||||
|
@ -141,6 +138,22 @@ class ActorService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Actor $actor
|
||||
* @param int $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPathFromActor(Actor $actor, int $type) {
|
||||
switch ($type) {
|
||||
case InstancePath::INBOX:
|
||||
return parse_url($actor->getInbox(), PHP_URL_PATH);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $object
|
||||
*
|
||||
|
@ -149,6 +162,7 @@ class ActorService {
|
|||
public function generateActor(array $object) {
|
||||
$actor = new Actor();
|
||||
|
||||
|
||||
$actor->setId($this->get('id', $object));
|
||||
$actor->setFollowers($this->get('followers', $object));
|
||||
$actor->setFollowing($this->get('following', $object));
|
||||
|
@ -165,9 +179,18 @@ class ActorService {
|
|||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* Method should be called by the frontend and will generate a fresh Social account for
|
||||
* the user, using the userId and the username.
|
||||
*
|
||||
* @throws ActorAlreadyExistsException
|
||||
* Pair of keys are created at this point.
|
||||
*
|
||||
* Return exceptions if an account already exist for this user or if the username is already
|
||||
* taken
|
||||
*
|
||||
* @param string $userId
|
||||
* @param string $username
|
||||
*
|
||||
* @throws AccountAlreadyExistsException
|
||||
* @throws NoUserException
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -179,14 +202,14 @@ class ActorService {
|
|||
|
||||
try {
|
||||
$this->actorsRequest->getFromUsername($username);
|
||||
throw new ActorAlreadyExistsException('actor with that name already exist');
|
||||
throw new AccountAlreadyExistsException('actor with that name already exist');
|
||||
} catch (ActorDoesNotExistException $e) {
|
||||
/* we do nohtin */
|
||||
}
|
||||
|
||||
try {
|
||||
$this->actorsRequest->getFromUserId($userId);
|
||||
throw new ActorAlreadyExistsException('account for this user already exist');
|
||||
throw new AccountAlreadyExistsException('account for this user already exist');
|
||||
} catch (ActorDoesNotExistException $e) {
|
||||
/* we do nohtin */
|
||||
}
|
||||
|
@ -202,10 +225,10 @@ class ActorService {
|
|||
|
||||
/**
|
||||
* @param $username
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function checkActorUsername($username) {
|
||||
$accepted = 'qwertyuiopasdfghjklzxcvbnm';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,214 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Service;
|
||||
|
||||
|
||||
use daita\Model\Request;
|
||||
use OCA\Social\Exceptions\APIRequestException;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Exceptions\MovedPermanentlyException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
|
||||
class ClientCurlService {
|
||||
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ClientCurlService constructor.
|
||||
*
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(MiscService $miscService) {
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
* @param bool $authed
|
||||
*
|
||||
* @return array
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws APIRequestException
|
||||
*/
|
||||
public function request(ServiceAccount $account, Request $request, bool $authed = true) {
|
||||
|
||||
$curl = $this->initRequest($account, $request, $authed);
|
||||
$this->initRequestPost($curl, $request);
|
||||
$this->initRequestPut($curl, $request);
|
||||
$this->initRequestDelete($curl, $request);
|
||||
|
||||
$result = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
echo 'code: ' . $code . "\n";
|
||||
echo 'result: ' . json_encode($result) . "\n";
|
||||
|
||||
$this->parseRequestResultCode301($code);
|
||||
$this->parseRequestResultCode401($code);
|
||||
$this->parseRequestResultCode404($code);
|
||||
// $this->parseRequestResultCode503($code);
|
||||
// $this->parseRequestResultCode500($code);
|
||||
// $this->parseRequestResult($result);
|
||||
|
||||
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
* @param bool $authed
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
private function initRequest(ServiceAccount $account, Request $request, bool $authed) {
|
||||
|
||||
$curl = $this->generateCurlRequest($account, $request);
|
||||
$headers = $request->getHeaders();
|
||||
|
||||
if ($authed) {
|
||||
$headers[] = 'Authorization: Bearer ' . $account->getAuth('token');
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
|
||||
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
return $curl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
private function generateCurlRequest(ServiceAccount $account, Request $request) {
|
||||
$service = $account->getService();
|
||||
$url = 'https://' . $service->getAddress() . $request->getParsedUrl();
|
||||
|
||||
if ($request->getType() !== Request::TYPE_GET) {
|
||||
$curl = curl_init($url);
|
||||
} else {
|
||||
$curl = curl_init($url . '?' . $request->getDataBody());
|
||||
}
|
||||
|
||||
return $curl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param resource $curl
|
||||
* @param Request $request
|
||||
*/
|
||||
private function initRequestPost($curl, Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_POST) {
|
||||
return;
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param resource $curl
|
||||
* @param Request $request
|
||||
*/
|
||||
private function initRequestPut($curl, Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_PUT) {
|
||||
return;
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param resource $curl
|
||||
* @param Request $request
|
||||
*/
|
||||
private function initRequestDelete($curl, Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @throws MovedPermanentlyException
|
||||
*/
|
||||
private function parseRequestResultCode301($code) {
|
||||
if ($code === 301) {
|
||||
throw new MovedPermanentlyException('301 Moved Permanently');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @throws InvalidAccessTokenException
|
||||
*/
|
||||
private function parseRequestResultCode401($code) {
|
||||
if ($code === 401) {
|
||||
throw new InvalidAccessTokenException('401 Access Token Invalid');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @throws APIRequestException
|
||||
*/
|
||||
private function parseRequestResultCode404($code) {
|
||||
if ($code === 404) {
|
||||
throw new APIRequestException('404 Not Found');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -31,11 +31,7 @@ namespace OCA\Social\Service;
|
|||
|
||||
|
||||
use daita\Model\Request;
|
||||
use OCA\Social\Exceptions\APIRequestException;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Exceptions\MovedPermanentlyException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
|
||||
class CurlService {
|
||||
|
||||
|
@ -45,7 +41,7 @@ class CurlService {
|
|||
|
||||
|
||||
/**
|
||||
* ClientCurlService constructor.
|
||||
* CurlService constructor.
|
||||
*
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
|
@ -58,12 +54,9 @@ class CurlService {
|
|||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function request(Request $request): array {
|
||||
|
||||
$curl = $this->initRequest($request);
|
||||
|
||||
$this->initRequestPost($curl, $request);
|
||||
|
@ -75,10 +68,11 @@ class CurlService {
|
|||
|
||||
$this->parseRequestResultCode301($code);
|
||||
// $this->parseRequestResultCode401($code);
|
||||
$this->parseRequestResultCode404($code);
|
||||
$this->parseRequestResultCode404($code, $request);
|
||||
// $this->parseRequestResultCode503($code);
|
||||
// $this->parseRequestResultCode500($code);
|
||||
// $this->parseRequestResult($result);
|
||||
|
||||
$ret = json_decode($result, true);
|
||||
if (!is_array($ret)) {
|
||||
$ret = ['_result' => $result];
|
||||
|
@ -120,7 +114,7 @@ class CurlService {
|
|||
*/
|
||||
private function generateCurlRequest(Request $request) {
|
||||
$url = 'https://' . $request->getAddress() . $request->getParsedUrl();
|
||||
|
||||
// echo 'curl: ' . $request->getUrl() . "\n";
|
||||
if ($request->getType() !== Request::TYPE_GET) {
|
||||
$curl = curl_init($url);
|
||||
} else {
|
||||
|
@ -176,11 +170,11 @@ class CurlService {
|
|||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws RequestException
|
||||
*/
|
||||
private function parseRequestResultCode301($code) {
|
||||
if ($code === 301) {
|
||||
throw new MovedPermanentlyException('301 Moved Permanently');
|
||||
throw new RequestException('301 Moved Permanently');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,11 +182,13 @@ class CurlService {
|
|||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @throws APIRequestException
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws RequestException
|
||||
*/
|
||||
private function parseRequestResultCode404($code) {
|
||||
private function parseRequestResultCode404(int $code, Request $request) {
|
||||
if ($code === 404) {
|
||||
throw new APIRequestException('404 Not Found');
|
||||
throw new RequestException('404 Not Found - ' . json_encode($request));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,11 +31,12 @@ namespace OCA\Social\Service;
|
|||
|
||||
|
||||
use daita\Model\Request;
|
||||
use OCA\Social\Exceptions\APIRequestException;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Exceptions\MovedPermanentlyException;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
use OCA\Social\Model\ActivityPub\Core;
|
||||
use OCA\Social\Model\Instance;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
|
||||
class UriIdService {
|
||||
class InstanceService {
|
||||
|
||||
|
||||
/** @var ConfigService */
|
||||
|
@ -68,9 +69,7 @@ class UriIdService {
|
|||
* @param $id
|
||||
*
|
||||
* @return mixed
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws APIRequestException
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function retrieveObject($id) {
|
||||
$url = parse_url($id);
|
||||
|
@ -83,4 +82,70 @@ class UriIdService {
|
|||
return $this->curlService->request($request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Core $activity
|
||||
*
|
||||
* @return Instance[]
|
||||
*/
|
||||
public function getInstancesFromActivity(Core $activity): array {
|
||||
$instances = [];
|
||||
foreach ($activity->getInstancePaths() as $instancePath) {
|
||||
$this->addInstances($instancePath, $instances);
|
||||
// $uriIds[] = $to;
|
||||
}
|
||||
|
||||
return $instances;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InstancePath $instancePath
|
||||
* @param Instance[] $instances
|
||||
*/
|
||||
private function addInstances(InstancePath $instancePath, array &$instances) {
|
||||
$address = $this->getHostFromUriId($instancePath->getUri());
|
||||
if ($address === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
if ($instance->getAddress() === $address) {
|
||||
$instance->addPath($instancePath);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$instance = new Instance($address);
|
||||
$instance->addPath($instancePath);
|
||||
$instances[] = $instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $uriId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getHostFromUriId(string $uriId) {
|
||||
$ignoreThose = [
|
||||
'',
|
||||
'https://www.w3.org/ns/activitystreams#Public'
|
||||
];
|
||||
|
||||
if (in_array($uriId, $ignoreThose)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = parse_url($uriId);
|
||||
if (!is_array($url) || !array_key_exists('host', $url)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $url['host'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -120,7 +120,6 @@ class MiscService {
|
|||
public function confirmUserId(string &$userId) {
|
||||
$user = $this->userManager->get($userId);
|
||||
|
||||
return;
|
||||
if ($user === null) {
|
||||
throw new NoUserException('user does not exist');
|
||||
}
|
||||
|
|
|
@ -1,201 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Service;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use Lrf141\OAuth2\Client\Provider\Mastodon;
|
||||
use OCA\Social\Db\ServiceAccountsRequest;
|
||||
use OCA\Social\Db\ServicesRequest;
|
||||
use OCA\Social\Exceptions\ServiceAccountAlreadyExistException;
|
||||
use OCA\Social\Exceptions\ServiceAccountDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ServiceAccountException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Traits\TOAuth2;
|
||||
|
||||
class ServiceAccountsService {
|
||||
|
||||
|
||||
use TOAuth2;
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var ServicesRequest */
|
||||
private $servicesRequest;
|
||||
|
||||
/** @var ServiceAccountsRequest */
|
||||
private $serviceAccountsRequest;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccountsService constructor.
|
||||
*
|
||||
* @param ServicesRequest $servicesRequest
|
||||
* @param ServiceAccountsRequest $serviceAccountsRequest
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ServicesRequest $servicesRequest, ServiceAccountsRequest $serviceAccountsRequest,
|
||||
ActivityStreamsService $activityStreamsService, MiscService $miscService
|
||||
) {
|
||||
$this->servicesRequest = $servicesRequest;
|
||||
$this->serviceAccountsRequest = $serviceAccountsRequest;
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
*
|
||||
* @return ServiceAccount[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAvailableAccounts(string $userId): array {
|
||||
$service = $this->serviceAccountsRequest->getAvailableAccounts($userId);
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return ServiceAccount
|
||||
* @throws ServiceAccountDoesNotExistException
|
||||
*/
|
||||
public function getAccount(string $userId, int $accountId): ServiceAccount {
|
||||
$account = $this->serviceAccountsRequest->getAccount($accountId);
|
||||
|
||||
if ($account->getUserId() !== $userId) {
|
||||
throw new ServiceAccountDoesNotExistException('Wrong owner');
|
||||
}
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorizationUrl(Service $service): string {
|
||||
$mastodon = $this->generateMastodonAuth($service);
|
||||
|
||||
return $mastodon->getAuthorizationUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param int $serviceId
|
||||
* @param string $code
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generateAccount(string $userId, int $serviceId, string $code) {
|
||||
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
$mastodon = $this->generateMastodonAuth($service);
|
||||
|
||||
$token =
|
||||
$mastodon->getAccessToken('authorization_code', ['code' => $code]);
|
||||
|
||||
$account = new ServiceAccount();
|
||||
$account->setAuth('token', $token->getToken());
|
||||
// $account->setAuth('refresh_token', $token->getRefreshToken());
|
||||
$account->setService($service);
|
||||
$account->setUserId($userId);
|
||||
$account->setStatus(1);
|
||||
|
||||
$info = $this->activityStreamsService->getAccountInformation($account);
|
||||
$accountName = '@' . $this->get('username', $info, '');
|
||||
$this->checkAccountUniqueness($serviceId, $userId, $accountName);
|
||||
|
||||
$account->setAccount($accountName);
|
||||
$account->setAccountId($this->getInt('id', $info, 0));
|
||||
$this->serviceAccountsRequest->create($account);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
* @param string $userId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @throws ServiceAccountAlreadyExistException
|
||||
* @throws ServiceAccountException
|
||||
*/
|
||||
private function checkAccountUniqueness(int $serviceId, string $userId, string $accountName) {
|
||||
|
||||
if ($accountName === '@') {
|
||||
throw new ServiceAccountException('Account name is not valid');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->serviceAccountsRequest->getFromAccountName($serviceId, $userId, $accountName);
|
||||
throw new ServiceAccountAlreadyExistException('This account already exist');
|
||||
} catch (ServiceAccountDoesNotExistException $e) {
|
||||
/** we do nohtin' */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return Mastodon
|
||||
*/
|
||||
private function generateMastodonAuth(Service $service): Mastodon {
|
||||
return new Mastodon(
|
||||
[
|
||||
'clientId' => $service->getConfig('clientKey'),
|
||||
'clientSecret' => $service->getConfig('clientSecret'),
|
||||
'redirectUri' => $this->generateRedirectUrl($service->getId()),
|
||||
'instance' => 'https://' . $service->getAddress(),
|
||||
'scope' => 'read write follow'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,242 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.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\Social\Service;
|
||||
|
||||
|
||||
use daita\Model\Request;
|
||||
use daita\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use OCA\Social\Db\ServicesRequest;
|
||||
use OCA\Social\Exceptions\MissingStuffException;
|
||||
use OCA\Social\Exceptions\ServiceDoesNotExistException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Traits\TOAuth2;
|
||||
|
||||
class ServicesService {
|
||||
|
||||
|
||||
use TOAuth2;
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var ServicesRequest */
|
||||
private $servicesRequest;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var ClientCurlService */
|
||||
private $clientCurlService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServicesService constructor.
|
||||
*
|
||||
* @param ServicesRequest $servicesRequest
|
||||
* @param ConfigService $configService
|
||||
* @param ClientCurlService $clientCurlService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ServicesRequest $servicesRequest, ConfigService $configService, ClientCurlService $clientCurlService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->servicesRequest = $servicesRequest;
|
||||
$this->configService = $configService;
|
||||
$this->clientCurlService = $clientCurlService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $instance
|
||||
*
|
||||
* @return Service
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createFromInstance(string $instance) {
|
||||
try {
|
||||
$service = $this->servicesRequest->getServiceFromInstance($instance);
|
||||
|
||||
if ($service->getStatus() !== Service::STATUS_VALID) {
|
||||
$this->servicesRequest->delete($service->getId());
|
||||
throw new ServiceDoesNotExistException();
|
||||
}
|
||||
} catch (ServiceDoesNotExistException $e) {
|
||||
|
||||
$service = $this->createService('mastodon', $instance);
|
||||
$app = $this->createAppOnService($service);
|
||||
|
||||
$service->setConfig('clientKey', $this->get('client_id', $app, ''))
|
||||
->setConfig('clientSecret', $this->get('client_secret', $app, ''))
|
||||
->unsetConfig('redirectUrl')
|
||||
->setStatus(Service::STATUS_VALID);
|
||||
$this->servicesRequest->update($service);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $address
|
||||
*
|
||||
* @return Service
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createService(string $type, string $address): Service {
|
||||
if ($type === '' || $address === '') {
|
||||
throw new MissingStuffException('missing some data');
|
||||
}
|
||||
|
||||
$serviceId = $this->servicesRequest->create($type, $address);
|
||||
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
$service->setConfig('redirectUrl', $this->generateRedirectUrl($serviceId));
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function createAppOnService(Service $service) {
|
||||
|
||||
$account = new ServiceAccount();
|
||||
$account->setService($service);
|
||||
|
||||
$data = [
|
||||
'client_name' => 'Social@' . $this->configService->getCloudAddress(),
|
||||
'redirect_uris' => $this->generateRedirectUrl($service->getId()),
|
||||
'scopes' => 'read write follow',
|
||||
'website' => 'https://' . $this->configService->getCloudAddress() . '/'
|
||||
];
|
||||
|
||||
$request = new Request(ActivityStreamsService::URL_CREATE_APP, Request::TYPE_POST);
|
||||
$request->setData($data);
|
||||
|
||||
return $this->clientCurlService->request($account, $request, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function getService(int $serviceId): Service {
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
$service->setConfig('redirectUrl', $this->generateRedirectUrl($serviceId));
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
* @param array $data
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function editService(int $serviceId, array $data): Service {
|
||||
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
|
||||
$service->setAddress($this->get('address', $data, ''));
|
||||
$service->setConfig('clientKey', trim($this->get('clientKey', $data, '')));
|
||||
$service->setConfig('clientSecret', trim($this->get('clientSecret', $data, '')));
|
||||
|
||||
$this->validateService($service);
|
||||
$this->servicesRequest->update($service);
|
||||
|
||||
$service->setConfig('redirectUrl', $this->generateRedirectUrl($serviceId));
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*/
|
||||
private function validateService(Service &$service) {
|
||||
if ($service->getStatus() === 1
|
||||
|| $service->getConfig('clientKey', '') === ''
|
||||
|| $service->getConfig('clientSecret', '') === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$service->setStatus(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return Service[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function removeService(int $serviceId): array {
|
||||
$this->servicesRequest->delete($serviceId);
|
||||
|
||||
return $this->servicesRequest->getServices();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getServices(): array {
|
||||
return $this->servicesRequest->getServices();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAvailableServices(): array {
|
||||
return $this->servicesRequest->getServices(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -232,7 +232,7 @@ class Request implements \JsonSerializable {
|
|||
/**
|
||||
* @return array
|
||||
*/
|
||||
function jsonSerialize() {
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'url' => $this->getUrl(),
|
||||
'type' => $this->getType(),
|
||||
|
|
|
@ -40,7 +40,7 @@ trait TArrayTools {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get(string $k, array $arr, string $default = '') {
|
||||
private function get(string $k, array $arr, string $default = ''): string {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ trait TArrayTools {
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getInt(string $k, array $arr, int $default = 0) {
|
||||
private function getInt(string $k, array $arr, int $default = 0): int {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ trait TArrayTools {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function getBool(string $k, array $arr, bool $default = false) {
|
||||
private function getBool(string $k, array $arr, bool $default = false): bool {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ trait TArrayTools {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getArray(string $k, array $arr, array $default = []) {
|
||||
private function getArray(string $k, array $arr, array $default = []): array {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Social;
|
||||
|
||||
require_once __DIR__ . '/../appinfo/autoload.php';
|
||||
require_once(__DIR__ . '/../lib/autoload.php');
|
||||
|
||||
if (!array_key_exists('resource', $_GET)) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
script('social', 'social');
|
||||
script('social', 'test');
|
||||
style('social', 'style');
|
||||
?>
|
||||
<div id="vue-content"></div>
|
||||
|
|
Ładowanie…
Reference in New Issue