forked from grumpydevelop/federator
minor fixes
- permissions are always lower-case - revert webfinger changes to initial state - re-add setFirst and setLast for outbox - we now save the current host (f.e. https://contentnation.net) to save users with their respective host (a request to fedusers/grumpydevelop will then result in saving the user as grumpydevelop@contentnation.net)
This commit is contained in:
parent
721e37882d
commit
823283183e
8 changed files with 54 additions and 6 deletions
|
@ -70,6 +70,18 @@ class FedUsers implements APIInterface
|
|||
break;
|
||||
case 'outbox':
|
||||
$handler = new FedUsers\Outbox($this->main);
|
||||
$user = $paths[1];
|
||||
if (!preg_match("#^([^@]+)@([^/]+)#", $user, $matches) === 1) {
|
||||
$hostUrl = $this->main->getHost();
|
||||
if ($hostUrl !== false) {
|
||||
$host = parse_url($hostUrl, PHP_URL_HOST);
|
||||
$port = parse_url($hostUrl, PHP_URL_PORT);
|
||||
if ($port !== null) {
|
||||
$host .= `:$port`;
|
||||
}
|
||||
$user = `$user@$host`;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -82,10 +94,10 @@ class FedUsers implements APIInterface
|
|||
$ret = false;
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
$ret = $handler->get($paths[1]);
|
||||
$ret = $handler->get($user);
|
||||
break;
|
||||
case 'POST':
|
||||
$ret = $handler->post($paths[1]);
|
||||
$ret = $handler->post($user);
|
||||
break;
|
||||
}
|
||||
if ($ret !== false) {
|
||||
|
|
|
@ -70,6 +70,10 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
|||
if ($page !== '') {
|
||||
$id .= '?page=' . urlencode($page);
|
||||
}
|
||||
if ($page === '' || $outbox->count() == 0) {
|
||||
$outbox->setFirst($id);
|
||||
$outbox->setLast($id . '&min=0');
|
||||
}
|
||||
if (sizeof($items)>0) {
|
||||
$newestId = $items[0]->getPublished();
|
||||
$oldestId = $items[sizeof($items)-1]->getPublished();
|
||||
|
|
|
@ -46,9 +46,11 @@ class WebFinger
|
|||
{
|
||||
$_resource = $this->main->extractFromURI('resource');
|
||||
$matches = [];
|
||||
if (preg_match("/^acct:([^@]+)@(.*)$/", $_resource, $matches) != 1) {
|
||||
$config = $this->main->getConfig();
|
||||
$domain = $config['generic']['externaldomain'];
|
||||
if (preg_match("/^acct:([^@]+)@(.*)$/", $_resource, $matches) != 1 || $matches[2] !== $domain) {
|
||||
throw new \Federator\Exceptions\InvalidArgument();
|
||||
}
|
||||
}
|
||||
$domain = $matches[2];
|
||||
$user = \Federator\DIO\User::getUserByName(
|
||||
$this->main->getDatabase(),
|
||||
|
|
|
@ -145,7 +145,7 @@ class User
|
|||
*/
|
||||
public function hasPermission(string $p)
|
||||
{
|
||||
return in_array(strtolower($p), array_map('strtolower', $this->permissions), true);
|
||||
return in_array($p, $this->permissions, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,12 @@ class Main
|
|||
* @var Connector\Connector $connector
|
||||
*/
|
||||
protected $connector = null;
|
||||
/**
|
||||
* remote host (f.e. https://contentnation.net)
|
||||
*
|
||||
* @var string $host
|
||||
*/
|
||||
protected $host = null;
|
||||
/**
|
||||
* response content type
|
||||
*
|
||||
|
@ -148,6 +154,15 @@ class Main
|
|||
{
|
||||
return $this->connector;
|
||||
}
|
||||
/**
|
||||
* get host (f.e. https://contentnation.net)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* get config
|
||||
|
@ -252,6 +267,19 @@ class Main
|
|||
$this->connector = $connector;
|
||||
}
|
||||
|
||||
/**
|
||||
* set host
|
||||
*
|
||||
* @param string $host the new host url
|
||||
*/
|
||||
public function setHost(string $host) : void
|
||||
{
|
||||
if ($this->host) {
|
||||
echo "main::setHost Setting new host will override old one.\n"; // TODO CHANGE TO LOG WARNING
|
||||
}
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* set response code
|
||||
*
|
||||
|
|
|
@ -47,6 +47,7 @@ class ContentNation implements Connector
|
|||
}
|
||||
$this->service = $config['contentnation']['service-uri'];
|
||||
$this->main = $main;
|
||||
$this->main->setHost($this->service);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,7 +70,7 @@ class DummyConnector implements Connector
|
|||
// validate $_session and $user
|
||||
$user = new \Federator\Data\User();
|
||||
$user->externalid = $_user;
|
||||
$user->permissions = ['PUBLISH'];
|
||||
$user->permissions = ['publish'];
|
||||
$user->session = $_session;
|
||||
return $user;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ class Mastodon implements Connector
|
|||
}
|
||||
$this->service = $config['mastodon']['service-uri'];
|
||||
$this->main = $main;
|
||||
$this->main->setHost($this->service);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue