Commit 209a5da9 authored by Brian Hatchet's avatar Brian Hatchet :speech_balloon:

Merged and cleanup

No related merge requests found
Pipeline #82219582 passed with stages
in 10 minutes and 5 seconds
<?php
namespace Minds\Controllers\Cli;
use Minds\Cli;
use Minds\Core\Events\Dispatcher;
use Minds\Interfaces;
class Notification extends Cli\Controller implements Interfaces\CliControllerInterface
{
public function help($command = null)
{
switch ($command) {
case 'send':
$this->out('Send a notification');
$this->out('--namespace=<type> Notification namespace');
$this->out('--to=<user guid> User to send notification to');
$this->out('--from=<entity guid> Entity notification is from (defaults to system user)');
$this->out('--view=<view> Notification view');
$this->out('--params=<params> JSON payload data');
// no break
default:
$this->out('Syntax usage: cli notification <cmd>');
$this->displayCommandHelp();
}
}
public function exec()
{
$this->help();
}
public function send()
{
$namespace = $this->getOpt('namespace');
$to = $this->getOpt('to');
$from = $this->getOpt('from') ?? \Minds\Core\Notification\Notification::SYSTEM_ENTITY;
$view = $this->getOpt('view');
$params = $this->getOpt('params') ?? '{}';
if (is_null($namespace)) {
$this->out('namespace must be set');
return;
}
if (is_null($to)) {
$this->out('to must be set');
return;
}
if (is_null($view)) {
$this->out('view must be set');
return;
}
$paramsDecoded = json_decode($params, true);
if (is_null($paramsDecoded)) {
$this->out('Params is not valid JSON');
return;
}
$eventParams = [
'to' => [$to],
'from' => $from,
'notification_view' => $view,
'params' => $paramsDecoded
];
$sent = Dispatcher::trigger('notification', $namespace, $eventParams);
if ($sent) {
$this->out('Notification sent');
} else {
$this->out('Error sending notification - is from guid valid?');
}
}
}
......@@ -31,7 +31,7 @@ class reports implements Interfaces\Api, Interfaces\ApiAdminPam
/** @var Core\Reports\Repository $repository */
$repository = Di::_()->get('Reports\Repository');
$reports = $repository->getAll([
$reports = $repository->getList([
'state' => $state,
'limit' => $limit,
'offset' => $offset
......
......@@ -58,6 +58,9 @@ class container implements Interfaces\Api
case 'blogs':
$type = 'object:blog';
break;
case 'all':
$type = 'all';
break;
}
$hardLimit = 5000;
......
......@@ -20,7 +20,14 @@ class connect implements Interfaces\Api
$connectManager = new Stripe\Connect\Manager();
$account = $connectManager->getByUser($user);
try {
$account = $connectManager->getByUser($user);
} catch (\Exception $e) {
return Factory::response([
'status' => 'error',
'message' => 'There was an error returning the usd account',
]);
}
return Factory::response([
'account' => $account->export(),
......
<?php
/**
*
*/
namespace Minds\Controllers\api\v2\payments\stripe\connect;
use Minds\Api\Factory;
use Minds\Common\Cookie;
use Minds\Core\Di\Di;
use Minds\Core\Config;
use Minds\Core\Session;
use Minds\Interfaces;
use Minds\Core\Payments\Stripe;
class photoid implements Interfaces\Api
{
public function get($pages)
{
return Factory::response([]);
}
public function post($pages)
{
$user = Session::getLoggedInUser();
$connectManager = new Stripe\Connect\Manager();
$account = $connectManager->getByUser($user);
$fp = fopen($_FILES['file']['tmp_name'], 'r');
$connectManager->addPhotoId($account, $fp);
return Factory::response([ 'account_id' => $account->getId() ]);
}
public function put($pages)
{
return Factory::response([]);
}
public function delete($pages)
{
return Factory::response([]);
}
}
<?php
/**
*
*/
namespace Minds\Controllers\api\v2\payments\stripe\connect;
use Minds\Api\Factory;
use Minds\Common\Cookie;
use Minds\Core\Di\Di;
use Minds\Core\Config;
use Minds\Core\Session;
use Minds\Interfaces;
use Minds\Core\Payments\Stripe;
class terms implements Interfaces\Api
{
public function get($pages)
{
return Factory::response([]);
}
public function post($pages)
{
return Factory::response([]);
}
public function put($pages)
{
$user = Session::getLoggedInUser();
$connectManager = new Stripe\Connect\Manager();
$account = $connectManager->getByUser($user);
$account->setIp($_SERVER['HTTP_X_FORWARDED_FOR']);
$connectManager->acceptTos($account);
return Factory::response([]);
}
public function delete($pages)
{
return Factory::response([]);
}
}
<?php
/**
*
*/
namespace Minds\Controllers\api\v2\payments\stripe;
use Minds\Api\Factory;
use Minds\Common\Cookie;
use Minds\Core\Di\Di;
use Minds\Core\Config;
use Minds\Core\Session;
use Minds\Interfaces;
use Minds\Core\Payments\Stripe;
class transactions implements Interfaces\Api
{
public function get($pages)
{
$user = Session::getLoggedInUser();
$connectManager = new Stripe\Connect\Manager();
try {
$account = $connectManager->getByUser($user);
} catch (\Exception $e) {
return Factory::response([
'status' => 'error',
'message' => 'There was an error returning the usd account',
]);
}
$transactionsManger = new Stripe\Transactions\Manager();
$transactions = $transactionsManger->getByAccount($account);
return Factory::response([
'transactions' => Factory::exportable($transactions),
]);
}
public function post($pages)
{
return Factory::response([]);
}
public function put($pages)
{
return Factory::response([]);
}
public function delete($pages)
{
return Factory::response([]);
}
}
......@@ -175,7 +175,7 @@ class Manager
//filter to get todays offchain transactions
$offlineToday = array_filter($offchain->toArray(), function ($result) {
return $result->getCreatedTimestamp() > time() - (60 * 60 * 24);
return $result->getCreatedTimestamp() > (time() - (60 * 60 * 24)) * 1000;
});
//reduce the impressions to count the days boosts.
......
......@@ -16,7 +16,7 @@
</a>
</td>
<td style="width: 70%">
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>@<?php echo $vars['sender']->get('name'); ?> wired you</h4>
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>@<?php echo $vars['sender']->get('username'); ?> wired you</h4>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>Transfer Date and Amount:</p>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>
<?php echo $wireDate; ?>; +<?php echo $amount ?>
......
......@@ -16,7 +16,7 @@
</a>
</td>
<td style="width: 70%">
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>You wired @<?php echo $vars['receiver']->get('name'); ?></h4>
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>You wired @<?php echo $vars['receiver']->get('username'); ?></h4>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>Transfer Date and Amount:</p>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>
<?php echo $wireDate; ?>; +<?php echo $amount ?>
......
......@@ -95,6 +95,7 @@ class Manager
'filter_hashtags' => false,
'pinned_guids' => null,
'as_activities' => false,
'exclude' => null,
], $opts);
if (isset($opts['query']) && $opts['query']) {
......
......@@ -53,6 +53,7 @@ class Repository
'exclude_moderated' => false,
'moderation_reservations' => null,
'pinned_guids' => null,
'exclude' => null,
], $opts);
if (!$opts['type']) {
......@@ -67,6 +68,8 @@ class Repository
throw new \Exception('Unsupported period');
}
$type = $opts['type'];
$body = [
'_source' => array_unique([
'guid',
......@@ -75,7 +78,7 @@ class Repository
'time_created',
'access_id',
'moderator_guid',
$this->getSourceField($opts['type']),
$this->getSourceField($type),
]),
'query' => [
'function_score' => [
......@@ -98,7 +101,7 @@ class Repository
'sort' => [],
];
/*if ($opts['type'] === 'group' && false) {
/*if ($type === 'group' && false) {
if (!isset($body['query']['function_score']['query']['bool']['must_not'])) {
$body['query']['function_score']['query']['bool']['must_not'] = [];
}
......@@ -107,7 +110,7 @@ class Repository
'access_id' => ['0', '1', '2'],
],
];
} elseif ($opts['type'] === 'user') {
} elseif ($type === 'user') {
$body['query']['function_score']['query']['bool']['must'][] = [
'term' => [
'access_id' => '2',
......@@ -236,7 +239,7 @@ class Repository
}
}
if ($opts['type'] !== 'group' && $opts['access_id'] !== null) {
if ($type !== 'group' && $opts['access_id'] !== null) {
$body['query']['function_score']['query']['bool']['must'][] = [
'terms' => [
'access_id' => Text::buildArray($opts['access_id']),
......@@ -294,6 +297,14 @@ class Repository
}
}
if ($opts['exclude']) {
$body['query']['function_score']['query']['bool']['must_not'][] = [
'terms' => [
'guid' => Text::buildArray($opts['exclude']),
],
];
}
// firehose options
......@@ -338,9 +349,15 @@ class Repository
//
$esType = $opts['type'];
if ($esType === 'all') {
$esType = 'object:image,object:video,object:blog';
}
$query = [
'index' => $this->index,
'type' => $opts['type'],
'type' => $esType,
'body' => $body,
'size' => $opts['limit'],
'from' => $opts['offset'],
......
......@@ -95,6 +95,24 @@ class Account
/** @var string $status */
private $status = "processing";
/** @var Balance $totalBalance */
private $totalBalance;
/** @var Balance $pendingBalance */
private $pendingBalance;
/** @var string $payoutInterval */
private $payoutInterval;
/** @var int $payoutDelay */
private $payoutDelay;
/** @var int $payoutAnchor */
private $payoutAnchor;
/** @var string $requirement */
private $requirement;
/** @var array $exportable */
private $exportable = [
'guid',
......@@ -118,6 +136,10 @@ class Account
'status',
'verified',
'bankAccount',
'payoutInterval',
'payoutDelay',
'payoutAnchor',
'requirement',
];
/**
......@@ -146,6 +168,14 @@ class Account
$export[$field] = $this->$field;
}
if ($this->totalBalance) {
$export['totalBalance'] = $this->totalBalance->export();
}
if ($this->pendingBalance) {
$export['pendingBalance'] = $this->pendingBalance->export();
}
return $export;
}
}
<?php
/**
* Stripe Connect Balance
*/
namespace Minds\Core\Payments\Stripe\Connect;
use Minds\Traits\MagicAttributes;
/**
* @method Balance getAmount(): int
* @method Balance getCurrency(): string
*/
class Balance
{
use MagicAttributes;
/** @var int $amount */
private $amount;
/** @var string $currency */
private $currency;
/**
* Expose to public API
* @return array
*/
public function export(array $extend = []) : array
{
return [
'amount' => (int) $this->amount,
'currency' => $this->currency,
];
}
}
......@@ -6,6 +6,8 @@ use Minds\Core\Entities\Actions\Save;
use Minds\Core\Payments\Stripe\Connect\Delegates\NotificationDelegate;
use Minds\Core\Payments\Stripe\Currencies;
use Minds\Core\Payments\Stripe\Instances\AccountInstance;
use Minds\Core\Payments\Stripe\Instances\BalanceInstance;
use Minds\Core\Payments\Stripe\Instances\FileInstance;
use Stripe;
use Minds\Entities\User;
......@@ -20,14 +22,24 @@ class Manager
/** @var AccountInstance $accountInstance */
private $accountInstance;
/** @var BalanceInstance $balanceInstance */
private $balanceInstance;
/** @var FileInstance $fileInstance */
private $fileInstance;
public function __construct(
Save $save = null,
NotificationDelegate $notificationDelegate = null,
AccountInstance $accountInstance = null
AccountInstance $accountInstance = null,
BalanceInstance $balanceInstance = null,
FileInstance $fileInstance = null
) {
$this->save = $save ?: new Save();
$this->notificationDelegate = $notificationDelegate ?: new NotificationDelegate();
$this->accountInstance = $accountInstance ?: new AccountInstance();
$this->balanceInstance = $balanceInstance ?: new BalanceInstance();
$this->fileInstance = $fileInstance ?: new FileInstance();
}
/**
......@@ -167,6 +179,27 @@ class Manager
return $stripeAccount->id;
}
/**
* Updates a stripe connect account
* @param $account
* @return bool
* @throws \Exception
*/
public function acceptTos(Account $account) : bool
{
try {
$this->accountInstance->update($account->getId(), [
'tos_acceptance' => [
'date' => time(),
'ip' => $account->getIp(),
],
]);
return true;
} catch (\Exception $e) {
return false;
}
}
/**
* Add a bank account to stripe account
* @param Account $account
......@@ -195,12 +228,26 @@ class Manager
return true;
}
/**
* Add photo Id
* @param Account $account
* @param resource $file
* @return bool
*/
public function addPhotoId(Account $account, $file) : bool
{
return (bool) $this->fileInstance->create([
'purpose' => 'identity_document',
'file' => $file,
], [ 'stripe_account' => $account->getId() ]);
}
/**
* Return a stripe account
* @param string $id
* @return Account
*/
public function getByAccountId(string $id) : Account
public function getByAccountId(string $id) : ?Account
{
try {
$result = $this->accountInstance->retrieve($id);
......@@ -223,20 +270,30 @@ class Manager
->setBankAccount($result->external_accounts->data[0])
->setAccountNumber($result->external_accounts->data[0]['last4'])
->setRoutingNumber($result->external_accounts->data[0]['routing_number'])
->setDestination('bank');
->setDestination('bank')
->setPayoutInterval($result->settings->payouts->schedule->interval)
->setPayoutDelay($result->settings->payouts->schedule->delay_days)
->setPayoutAnchor($result->settings->payouts->schedule->monthly_anchor);
//verifiction check
if ($result->legal_entity->verification->status === 'verified') {
$account->setVerified(true);
}
if ($result->verification->disabled_reason == 'fields_needed') {
if ($result->verification->fields_needed[0] == 'legal_entity.verification.document') {
$account->setStatus('awaiting-document');
if (!$account->getVerified()) {
switch ($result->requirements->disabled_reason) {
case 'requirements.past_due':
$account->setRequirement($result->requirements->currently_due[0]);
break;
}
}
$account->setTotalBalance($this->getBalanceById($result->id, 'available'));
$account->setPendingBalance($this->getBalanceById($result->id, 'pending'));
return $account;
} catch (Stripe\Error\Permission $e) {
throw new \Exception($e->getMessage());
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
......@@ -256,6 +313,20 @@ class Manager
return $this->getByAccountId($merchant['id']);
}
/**
* Get balance by ID
* @param string $id
* @return Balance
*/
public function getBalanceById(string $id, string $type) : Balance
{
$stripeBalance = $this->balanceInstance->retrieve([ 'stripe_account' => $id ]);
$balance = new Balance();
$balance->setAmount($stripeBalance->$type[0]->amount)
->setCurrency($stripeBalance->$type[0]->currency);
return $balance;
}
/**
* Delete a merchant accont
* @param Account $account
......
<?php
namespace Minds\Core\Payments\Stripe\Instances;
use Minds\Common\StaticToInstance;
use Minds\Core\Config\Config;
use Minds\Core\Di\Di;
/**
* @method BalanceInstance create()
* @method BalanceInstance retrieve()
*/
class BalanceInstance extends StaticToInstance
{
public function __construct(Config $config = null)
{
$config = $config ?? Di::_()->get('Config');
\Stripe\Stripe::setApiKey($config->get('payments')['stripe']['api_key']);
$this->setClass(new \Stripe\Balance);
}
}
<?php
namespace Minds\Core\Payments\Stripe\Instances;
use Minds\Common\StaticToInstance;
use Minds\Core\Config\Config;
use Minds\Core\Di\Di;
/**
* @method ChargeInstance retrieve()
*/
class ChargeInstance extends StaticToInstance
{
public function __construct(Config $config = null)
{
$config = $config ?? Di::_()->get('Config');
\Stripe\Stripe::setApiKey($config->get('payments')['stripe']['api_key']);
$this->setClass(new \Stripe\Charge);
}
}
<?php
namespace Minds\Core\Payments\Stripe\Instances;
use Minds\Common\StaticToInstance;
use Minds\Core\Config\Config;
use Minds\Core\Di\Di;
/**
* @method FileInstance create()
*/
class FileInstance extends StaticToInstance
{
public function __construct(Config $config = null)
{
$config = $config ?? Di::_()->get('Config');
\Stripe\Stripe::setApiKey($config->get('payments')['stripe']['api_key']);
$this->setClass(new \Stripe\File);
}
}
<?php
namespace Minds\Core\Payments\Stripe\Instances;
use Minds\Common\StaticToInstance;
use Minds\Core\Config\Config;
use Minds\Core\Di\Di;
/**
* @method TransferInstance all()
*/
class TransferInstance extends StaticToInstance
{
public function __construct(Config $config = null)
{
$config = $config ?? Di::_()->get('Config');
\Stripe\Stripe::setApiKey($config->get('payments')['stripe']['api_key']);
$this->setClass(new \Stripe\Transfer);
}
}
......@@ -63,6 +63,9 @@ class Manager
'transfer_data' => [
'destination' => $intent->getStripeAccountId(),
],
'metadata' => [
'user_guid' => $intent->getUserGuid(),
],
];
if ($intent->getServiceFee()) {
......
<?php
namespace Minds\Core\Payments\Stripe\Transactions;
use Minds\Core\Payments\Stripe\Connect\Account;
use Minds\Core\Payments\Stripe\Instances\TransferInstance;
use Minds\Core\Payments\Stripe\Instances\ChargeInstance;
use Minds\Core\Di\Di;
use Minds\Common\Repository\Response;
class Manager
{
/** @var EntitiesBuilder $entitiesBuilder */
private $entitiesBuilder;
/** @var TransferInstance $transferInstance */
private $transferInstance;
/** @var ChargeInstance $chargeInstance */
private $chargeInstance;
public function __construct($entitiesBuilder = null, $transferInstance = null, $chargeInstance = null)
{
$this->entitiesBuilder = $entitiesBuilder ?? Di::_()->get('EntitiesBuilder');
$this->transferInstance = $transferInstance ?? new TransferInstance();
$this->chargeInstance = $chargeInstance ?? new ChargeInstance();
}
/**
* Return transactions from an account object
* @param Account $account
* @return Response[Transaction]
*/
public function getByAccount(Account $account): Response
{
$transfers = $this->transferInstance->all([ 'destination' => $account->getId() ]);
$response = new Response();
foreach ($transfers->autoPagingIterator() as $transfer) {
try {
$payment = $this->chargeInstance->retrieve($transfer->source_transaction);
} catch (\Exception $e) {
continue;
}
$transaction = new Transaction();
$transaction->setId($transfer->id)
->setTimestamp($transfer->created)
->setGross($payment->amount)
->setFees(0)
->setNet($transfer->amount)
->setCurrency($transfer->currency)
->setCustomerUserGuid($payment->metadata['user_guid'])
->setCustomerUser($this->entitiesBuilder->single($payment->metadata['user_guid']));
$response[] = $transaction;
}
return $response;
}
}
<?php
namespace Minds\Core\Payments\Stripe\Transactions;
use Minds\Entities\User;
use Minds\Traits\MagicAttributes;
class Transaction
{
use MagicAttributes;
/** @var string $id */
private $id;
/** @var int $timestamp */
private $timestamp;
/** @var int $gross */
private $gross;
/** @var string $currency */
private $currency;
/** @var int $fees */
private $fees;
/** @var int $net */
private $net;
/** @var string $customerGuid */
private $customerUserGuid;
/** @var User $customerUser */
private $customerUser;
/**
* Expose to the public apis
* @param array $extend
* @return array
*/
public function export(array $extend = []) : array
{
return [
'id' => $this->id,
'timestamp' => $this->timestamp,
'gross' => $this->gross,
'currency' => $this->currency,
'fees' => $this->fees,
'net' => $this->net,
'customer_user_guid' => $this->userGuid,
'customer_user' => $this->customerUser ? $this->customerUser->export() : null,
];
}
}
......@@ -4,6 +4,7 @@ namespace Minds\Core\Permissions\Delegates;
use Minds\Traits\MagicAttributes;
use Minds\Core\Permissions\Roles\Roles;
use Minds\Core\Permissions\Roles\Role;
class ChannelRoleCalculator extends BaseRoleCalculator
{
......@@ -20,7 +21,7 @@ class ChannelRoleCalculator extends BaseRoleCalculator
*
* @return Role
*/
public function calculate($entity)
public function calculate($entity): Role
{
if (isset($this->channels[$entity->getOwnerGuid()])) {
return $this->channels[$entity->getOwnerGuid()];
......
......@@ -4,9 +4,10 @@ namespace Minds\Core\Permissions\Delegates;
use Minds\Traits\MagicAttributes;
use Minds\Core\Di\Di;
use Minds\Core\Permissions\Roles\Roles;
use Minds\Core\Permissions\Roles\Role;
use Minds\Core\EntitiesBuilder;
use Minds\Entities\User;
use Minds\Core\Permissions\Roles\Roles;
class GroupRoleCalculator extends BaseRoleCalculator
{
......@@ -32,7 +33,7 @@ class GroupRoleCalculator extends BaseRoleCalculator
*
* @return Role
*/
public function calculate($entity)
public function calculate($entity): Role
{
if (isset($this->groups[$entity->getAccessId()])) {
return $this->groups[$entity->getAccessId()];
......
......@@ -31,11 +31,12 @@ class Manager
}
/**
* Save permissions for an entity and propegate it to linked objects
* @param mixed $entity a minds entity that implements the save function
* @param Permissions $permissions the flag to apply to the entity
*/
public function save($entity, EntityPermissions $permissions)
* Save permissions for an entity and propegate it to linked objects.
*
* @param mixed $entity a minds entity that implements the save function
* @param Permissions $permissions the flag to apply to the entity
*/
public function save($entity, EntityPermissions $permissions): void
{
$entity->setAllowComments($permissions->getAllowComments());
......
......@@ -5,6 +5,7 @@ namespace Minds\Core\Permissions;
use Minds\Core\Di\Di;
use Minds\Core\Permissions\Permissions;
use Minds\Core\EntitiesBuilder;
use Minds\Core\Permissions\Roles\Roles;
/*
* Manager for managing role based permissions
......@@ -23,13 +24,14 @@ class Manager
* Takes a user_guid and list of entity guids
* Builds up a permissions object
* Permissions contains the user's role per entity, channel and group
*
* @param array $opts
* - user_guid: long, the user's guid for calculating permissions
* - guids: array long, the list of entities to permit
* - entities: fetched objects to permit
* - user_guid: long, the user's guid for calculating permissions
* - guids: array long, the list of entities to permit
*
* @return Permissions A map of channels, groups and entities with the user's role for each
*/
public function getList(array $opts = [])
public function getList(array $opts = []): Permissions
{
$opts = array_merge([
'user_guid' => null,
......@@ -49,8 +51,10 @@ class Manager
$entities = $this->entitiesBuilder->get($opts);
$entities = array_merge($entities, $opts['entities']);
$roles = new Roles();
/** @var Permissions */
$permissions = new Permissions($user, null, $entitiesBuilder);
$permissions = new Permissions($user, $roles, $entitiesBuilder);
if (is_array($entities)) {
$permissions->calculate($entities);
}
......
......@@ -6,6 +6,7 @@ use Minds\Traits\MagicAttributes;
use Minds\Entities\User;
use Minds\Core\EntitiesBuilder;
use Minds\Core\Permissions\Roles\Roles;
use Minds\Core\Permissions\Roles\Role;
use Minds\Core\Permissions\Delegates\ChannelRoleCalculator;
use Minds\Core\Permissions\Delegates\GroupRoleCalculator;
use Minds\Common\Access;
......@@ -33,11 +34,6 @@ class Permissions implements \JsonSerializable
/** @var EntitiesBuilder */
private $entitiesBuilder;
public function setUser(User $user = null)
{
throw new ImmutableException('User can only be set in the constructor');
}
public function __construct(User $user = null, Roles $roles = null, EntitiesBuilder $entitiesBuilder = null)
{
$this->groups = [];
......@@ -51,10 +47,22 @@ class Permissions implements \JsonSerializable
$this->channels[$user->getGuid()] = $user;
}
$this->entitiesBuilder = $entitiesBuilder ?: Di::_()->get('EntitiesBuilder');
$this->channels[$user->getGUID()] = $user;
$this->channelRoleCalculator = new ChannelRoleCalculator($this->user, $this->roles);
$this->groupRoleCalculator = new GroupRoleCalculator($this->user, $this->roles, $entitiesBuilder);
}
/**
* Permissions are user aware. This bomb function is to keep the user from being changed after instantiation.
*
* @throws ImmutableException
*/
public function setUser(User $user): void
{
throw new ImmutableException('User can only be set in the constructor');
}
/**
* Takes an array of entities and checks their permissions
* Builds up collections of permissions based on the user's relationships to the entity
......@@ -64,14 +72,14 @@ class Permissions implements \JsonSerializable
*
* @param array entities an array of entities for calculating permissions
*/
public function calculate(array $entities = [])
public function calculate(array $entities = []): void
{
foreach ($entities as $entity) {
$this->entities[$entity->getGuid()] = $this->getRoleForEntity($entity);
}
}
private function getRoleForEntity($entity)
private function getRoleForEntity($entity): Role
{
$role = null;
......@@ -104,7 +112,7 @@ class Permissions implements \JsonSerializable
*
* @return array serialized objects
*/
public function export()
public function export(): array
{
$export = [];
if ($this->user) {
......@@ -120,7 +128,7 @@ class Permissions implements \JsonSerializable
/**
* @return array channel guids with the user's role
*/
public function getChannels()
public function getChannels(): array
{
return $this->channelRoleCalculator->getChannels();
}
......@@ -128,7 +136,7 @@ class Permissions implements \JsonSerializable
/**
* @return array group guids with the user's role
*/
public function getGroups()
public function getGroups(): array
{
return $this->groupRoleCalculator->getGroups();
}
......@@ -136,7 +144,7 @@ class Permissions implements \JsonSerializable
/**
* @return array serialized objects
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->export();
}
......
......@@ -3,10 +3,11 @@
namespace Minds\Core\Permissions\Roles;
use Zend\Permissions\Rbac;
use Minds\Core\Permissions\Roles\Role;
abstract class BaseRole extends Rbac\Role implements \JsonSerializable
abstract class BaseRole extends Rbac\Role implements \JsonSerializable, Role
{
public function export()
public function export(): array
{
$export = [];
$export['name'] = $this->getName();
......@@ -15,7 +16,7 @@ abstract class BaseRole extends Rbac\Role implements \JsonSerializable
return $export;
}
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->export();
}
......
<?php
namespace Minds\Core\Permissions\Roles;
interface Role
{
public function export();
}
......@@ -170,6 +170,7 @@ class Events
'xn--90aizihgi.xn--p1ai',
'tinyurl.com',
'bit.ly',
'bit.do',
'123football.space',
'bitly.com',
'j.mp',
......
......@@ -187,6 +187,7 @@ class Spam
'xn--90aizihgi.xn--p1ai',
'tinyurl.com',
'bit.ly',
'bit.do',
'123football.space',
'bitly.com',
'j.mp',
......
......@@ -266,6 +266,9 @@ class Manager
throw new \Exception("Not implemented ETH yet");
break;
case 'usd':
if (!$this->receiver->getMerchant() || !$this->receiver->getMerchant()['id']) {
throw new \Exception("This channel is not able to receive USD at the moment");
}
$intent = new PaymentIntent();
$intent
->setUserGuid($this->sender->getGuid())
......
......@@ -12,6 +12,7 @@ use Minds\Entities\Entity;
use PhpSpec\Exception\Example\FailureException;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Minds\Common\Access;
class ManagerSpec extends ObjectBehavior
{
......@@ -50,6 +51,10 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5000);
$scoredGuid1->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$scoredGuid1->getScore()
->shouldBeCalled()
->willReturn(500);
......@@ -70,6 +75,10 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5000);
$entity1->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$entity1->getOwnerGUID()
->shouldBeCalled()
->willReturn(1000);
......@@ -82,6 +91,10 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5001);
$scoredGuid2->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$scoredGuid2->getScore()
->shouldBeCalled()
->willReturn(800);
......@@ -102,6 +115,10 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5001);
$entity2->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$entity2->getOwnerGUID()
->shouldBeCalled()
->willReturn(1001);
......@@ -138,6 +155,10 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5000);
$scoredGuid1->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$scoredGuid1->getScore()
->shouldBeCalled()
->willReturn(500);
......@@ -158,6 +179,10 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5000);
$entity1->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$entity1->getOwnerGUID()
->shouldBeCalled()
->willReturn(1000);
......@@ -170,6 +195,11 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5001);
$scoredGuid2->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$scoredGuid2->getScore()
->shouldBeCalled()
->willReturn(800);
......@@ -190,6 +220,11 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(5001);
$entity2->getAccessId()
->shouldBeCalled()
->willReturn(Access::PUBLIC);
$entity2->getOwnerGUID()
->shouldBeCalled()
->willReturn(1001);
......
......@@ -9,6 +9,7 @@ use Minds\Core\Feeds\Top\MetricsSync;
use Minds\Core\Feeds\Top\Repository;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Minds\Common\Access;
class RepositorySpec extends ObjectBehavior
{
......@@ -52,6 +53,7 @@ class RepositorySpec extends ObjectBehavior
[
'_source' => [
'guid' => '1',
'access_id' => Access::PUBLIC,
'owner_guid' => '1000',
'time_created' => 1,
'@timestamp' => 1000,
......@@ -62,6 +64,7 @@ class RepositorySpec extends ObjectBehavior
[
'_source' => [
'guid' => '2',
'access_id' => Access::PUBLIC,
'owner_guid' => '1000',
'time_created' => 1,
'@timestamp' => 1000,
......@@ -102,6 +105,7 @@ class RepositorySpec extends ObjectBehavior
[
'_source' => [
'guid' => '1',
'access_id' => Access::PUBLIC,
'owner_guid' => '1',
'time_created' => 1,
'@timestamp' => 1000,
......@@ -112,6 +116,7 @@ class RepositorySpec extends ObjectBehavior
[
'_source' => [
'guid' => '2',
'access_id' => Access::PUBLIC,
'owner_guid' => '2',
'time_created' => 2,
'@timestamp' => 2000,
......@@ -152,6 +157,7 @@ class RepositorySpec extends ObjectBehavior
[
'_source' => [
'guid' => '1',
'access_id' => Access::PUBLIC,
'owner_guid' => '1000',
'time_created' => 1,
'@timestamp' => 1000,
......@@ -163,6 +169,7 @@ class RepositorySpec extends ObjectBehavior
[
'_source' => [
'guid' => '2',
'access_id' => Access::PUBLIC,
'owner_guid' => '1001',
'time_created' => 2,
'@timestamp' => 2000,
......
......@@ -7,6 +7,8 @@ use Minds\Core\Payments\Stripe\Connect\Account;
use Minds\Core\Entities\Actions\Save;
use Minds\Core\Payments\Stripe\Connect\Delegates\NotificationDelegate;
use Minds\Core\Payments\Stripe\Instances\AccountInstance;
use Minds\Core\Payments\Stripe\Instances\BalanceInstance;
use Minds\Core\Payments\Stripe\Instances\FileInstance;
use Minds\Entities\User;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
......@@ -16,13 +18,17 @@ class ManagerSpec extends ObjectBehavior
private $save;
private $notificationDelegate;
private $accountInstance;
private $balanceInstance;
private $fileInstance;
public function let(Save $save, NotificationDelegate $notificationDelegate, AccountInstance $accountInstance)
public function let(Save $save, NotificationDelegate $notificationDelegate, AccountInstance $accountInstance, BalanceInstance $balanceInstance, FileInstance $fileInstance)
{
$this->beConstructedWith($save, $notificationDelegate, $accountInstance);
$this->beConstructedWith($save, $notificationDelegate, $accountInstance, $balanceInstance, $fileInstance);
$this->save = $save;
$this->notificationDelegate = $notificationDelegate;
$this->accountInstance = $accountInstance;
$this->balanceInstance = $balanceInstance;
$this->fileInstance = $fileInstance;
}
public function it_is_initializable()
......@@ -126,6 +132,31 @@ class ManagerSpec extends ObjectBehavior
'verification' => (object) [
'disabled_reason' => null,
],
'settings' => (object) [
'payouts' => (object) [
'schedule' => (object) [
'interval' => 1,
'delay_days' => 2,
'monthly_anchor' => 31,
],
],
],
]);
$this->balanceInstance->retrieve([ 'stripe_account' => 'acc_123'])
->willReturn((object) [
'pending' => [
(object) [
'amount' => 100,
'currency' => 'GBP',
],
],
'available' => [
(object) [
'amount' => 100,
'currency' => 'GBP',
],
],
]);
$account = $this->getByAccountId('acc_123');
......@@ -181,6 +212,31 @@ class ManagerSpec extends ObjectBehavior
'verification' => (object) [
'disabled_reason' => null,
],
'settings' => (object) [
'payouts' => (object) [
'schedule' => (object) [
'interval' => 1,
'delay_days' => 2,
'monthly_anchor' => 31,
]
]
]
]);
$this->balanceInstance->retrieve([ 'stripe_account' => 'acc_123'])
->willReturn((object) [
'pending' => [
(object) [
'amount' => 100,
'currency' => 'GBP',
],
],
'available' => [
(object) [
'amount' => 100,
'currency' => 'GBP',
],
],
]);
$user = new User();
......
<?php
namespace Spec\Minds\Core\Permissions;
use Minds\Core\Permissions\Permissions;
use Minds\Core\Permissions\Roles\Roles;
use Minds\Entities\User;
use Minds\Entities\Activity;
use Minds\Entities\Group;
use Minds\Core\EntitiesBuilder;
use PhpSpec\ObjectBehavior;
use Prophecy\Prophet;
use Minds\Common\Access;
use Minds\Exceptions\ImmutableException;
class PermissionsSpec extends ObjectBehavior
{
/** @var EntitiesBuilder */
private $entitiesBuilder;
public function let(EntitiesBuilder $entitiesBuilder)
{
$this->entitiesBuilder = $entitiesBuilder;
$this->beConstructedWith($this->user, null, $this->entitiesBuilder);
}
public function it_should_except_with_no_user()
{
$this->shouldThrow(new InvalidArgumentException('Entity is not a user'))
->duringGetList();
}
}
......@@ -299,28 +299,28 @@ class PermissionsSpec extends ObjectBehavior
$activity = $prophet->prophesize(Activity::class);
$activity->getGUID()->willReturn(10);
$activity->getOwnerGUID()->willReturn(1);
$activity->getAccessID()->willReturn(Access::PUBLIC);
$activity->getAccessId()->willReturn(Access::PUBLIC);
$entities[] = $activity;
//Mock subscriber channel activity
$activity = $prophet->prophesize(Activity::class);
$activity->getGUID()->willReturn(11);
$activity->getOwnerGUID()->willReturn(2);
$activity->getAccessID()->willReturn(Access::PUBLIC);
$activity->getAccessId()->willReturn(Access::PUBLIC);
$entities[] = $activity;
//Mock non-subscriber channel activity
$activity = $prophet->prophesize(Activity::class);
$activity->getGUID()->willReturn(12);
$activity->getOwnerGUID()->willReturn(3);
$activity->getAccessID()->willReturn(Access::PUBLIC);
$activity->getAccessId()->willReturn(Access::PUBLIC);
$entities[] = $activity;
//Mock group activity
$activity = $prophet->prophesize(Activity::class);
$activity->getGUID()->willReturn(13);
$activity->getOwnerGUID()->willReturn(1);
$activity->getAccessID()->willReturn(100);
$activity->getAccessId()->willReturn(100);
$entities[] = $activity;
return $entities;
......
This diff is collapsed.
......@@ -5,7 +5,7 @@ rm -rf ../vendor
# Setup composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment