Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/multisite-…
Browse files Browse the repository at this point in the history
…job-queues

Conflicts:
	composer.lock
  • Loading branch information
rjmackay committed Nov 12, 2018
2 parents 2d0b9b1 + 77a3907 commit 42c68e9
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 322 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ language: php
php:
- '7.0'
- '7.1'
- '7.2'
- 'nightly'
env:
- coverage="--coverage"
Expand All @@ -15,6 +16,8 @@ matrix:
exclude:
- php: '7.1'
env: coverage="--coverage"
- php: '7.2'
env: coverage="--coverage"
- php: 'nightly'
env: coverage="--coverage"
allow_failures:
Expand Down Expand Up @@ -65,4 +68,4 @@ after_success:
# repo: ushahidi/platform
# php: 5.5
# tags: true
# all_branches: true
# all_branches: true
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Ushahidi 3

[![Build Status](https://travis-ci.org/ushahidi/platform.png)](https://travis-ci.org/ushahidi/platform)
[![Coverage Status](https://coveralls.io/repos/github/ushahidi/platform/badge.svg)](https://coveralls.io/github/ushahidi/platform)
[![Backers on Open Collective](https://opencollective.com/platform/backers/badge.svg)](#backers)

[![Sponsors on Open Collective](https://opencollective.com/platform/sponsors/badge.svg)](#sponsors)


[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
Expand All @@ -24,7 +26,7 @@ Ushahidi 3
Ushahidi is an open source web application for information collection, visualization and interactive mapping. It helps you to collect info from: SMS, Twitter, RSS feeds, Email. It helps you to process that information, categorize it, geo-locate it and publish it on a map.

## A note for grassroots organizations
If you are starting a deployment for a grassroots organization, you can apply for a free social-impact responder account [here](https://www.ushahidi.com/plans/apply-for-free) after verifying that you meet the criteria.
If you are starting a deployment for a grassroots organization, you can apply for a free social-impact responder account [here](https://www.ushahidi.com/pricing/apply-for-free) after verifying that you meet the criteria.


## Getting Involved
Expand Down Expand Up @@ -126,6 +128,28 @@ Follow the instructions [here](docs/setup_alternatives/XAMPP.md)

- The latest install instructions for the client are always [in the platform-client README, at this url](https://github.com/ushahidi/platform-client/blob/develop/README.md).

## Credits

### Contributors

This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].

<a href="graphs/contributors"><img src="https://opencollective.com/platform/contributors.svg?width=890&button=false" /></a>

### Backers

Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/platform#backer)]

<a href="https://opencollective.com/platform#backers" target="_blank"><img src="https://opencollective.com/platform/backers.svg?width=890"></a>

### Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/platform#sponsor)]

<a href="https://opencollective.com/platform/sponsor/0/website" target="_blank"><img src="https://opencollective.com/platform/sponsor/0/avatar.svg"></a>



## Useful Links

- [Download][download]
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function setupMultisiteIlluminateDB()
public function registerFeatures()
{
$this->app->singleton('features', function ($app) {
return new \Ushahidi\App\Tools\Features(service('features'));
return new \Ushahidi\App\Tools\Features(service('repository.config'));
});
}
}
43 changes: 34 additions & 9 deletions app/Tools/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace Ushahidi\App\Tools;

use Ushahidi\Core\Entity\ConfigRepository;

class Features
{

/**
* @param array $config
* @param array $configRepo
*/
public function __construct(array $config)
public function __construct(ConfigRepository $configRepo)
{
$this->config = $config;
$this->configRepo = $configRepo;
}

/**
Expand All @@ -20,16 +21,40 @@ public function __construct(array $config)
*/
public function isEnabled($feature)
{
if (isset($this->config[$feature])) {
if (!is_array($this->config[$feature])) {
return !!$this->config[$feature];
$config = $this->configRepo->get('features');

if (isset($config->$feature)) {
if (!is_array($config->$feature)) {
return !!$config->$feature;
}

if (isset($this->config[$feature]['enabled'])) {
return !!$this->config[$feature]['enabled'];
if (isset($config->$feature['enabled'])) {
return !!$config->$feature['enabled'];
}
}

return false;
}

/**
* Get limit for feature
* @param string $feature
* @return int|INF
*/
public function getLimit($feature)
{
$config = $this->configRepo->get('features');

if (isset($config->limits[$feature])) {
if ($config->limits[$feature] === true) {
// Return infinity ie. unlimited
return INF;
}

return (int) $config->limits[$feature];
}

// Return infinity ie. unlimited
return INF;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": ">=7.0 <7.2",
"php": ">=7.0 <=7.3",
"aura/di": "~3.4",
"league/flysystem-aws-s3-v3": "~1.0",
"league/flysystem-rackspace": "~1.0",
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 2 additions & 16 deletions src/App/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Ushahidi\Core\Entity\User;
use Ushahidi\Core\Entity\Permission;
use Ushahidi\Core\Entity\RoleRepository;
use Ushahidi\App\Facades\Features;

class Acl implements AclInterface
{
protected $role_repo;
protected $roles_enabled = false;
const DEFAULT_ROLES = [
'user' => [Permission::EDIT_OWN_POSTS]
];
Expand All @@ -29,20 +29,6 @@ public function setRoleRepo(RoleRepository $role_repo)
$this->role_repo = $role_repo;
}

public function setRolesEnabled($roles_enabled)
{
$this->roles_enabled = $roles_enabled;
}

/**
* Check if custom roles are enabled for this deployment
* @return boolean
*/
protected function hasRolesEnabled()
{
return (bool) $this->roles_enabled;
}

// Acl interface
public function hasPermission(User $user, $permission)
{
Expand All @@ -59,7 +45,7 @@ public function hasPermission(User $user, $permission)

// Don't check for permissions if we don't have the
// roles feature enabled
if ($this->hasRolesEnabled()) {
if (Features::isEnabled('roles')) {
return $this->customRoleHasPermission($user, $permission);
} else {
return $this->defaultHasPermission($user, $permission);
Expand Down
74 changes: 2 additions & 72 deletions src/App/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function define(Container $di)
// Helpers, tools, etc
$di->set('tool.acl', $di->lazyNew(\Ushahidi\App\Acl::class));
$di->setters[\Ushahidi\App\Acl::class]['setRoleRepo'] = $di->lazyGet('repository.role');
$di->setters[\Ushahidi\App\Acl::class]['setRolesEnabled'] = $di->lazyGet('roles.enabled');

$di->set('tool.hasher.password', $di->lazyNew(\Ushahidi\App\Hasher\Password::class));
$di->set('tool.authenticator.password', $di->lazyNew(\Ushahidi\App\Authenticator\Password::class));
Expand Down Expand Up @@ -608,7 +607,6 @@ public function define(Container $di)
'role_repo' => $di->lazyGet('repository.role'),
'post_value_factory' => $di->lazyGet('repository.post_value_factory'),
'post_value_validator_factory' => $di->lazyGet('validator.post.value_factory'),
'limits' => $di->lazyGet('features.limits'),
];

$di->params[\Ushahidi\App\Validator\Post\Lock\Update::class] = [
Expand All @@ -618,7 +616,6 @@ public function define(Container $di)

$di->params[\Ushahidi\App\Validator\Form\Update::class] = [
'repo' => $di->lazyGet('repository.form'),
'limits' => $di->lazyGet('features.limits'),
];

$di->params[\Ushahidi\App\Validator\Form\Attribute\Update::class] = [
Expand Down Expand Up @@ -674,7 +671,6 @@ public function define(Container $di)
$di->params[\Ushahidi\App\Validator\User\Update::class] = [
'repo' => $di->lazyGet('repository.user'),
'role_repo' => $di->lazyGet('repository.role'),
'limits' => $di->lazyGet('features.limits'),
];
$di->params[\Ushahidi\App\Validator\User\Register::class] = [
'repo' => $di->lazyGet('repository.user')
Expand All @@ -696,8 +692,7 @@ public function define(Container $di)
'form_repo' => $di->lazyGet('repository.form'),
];
$di->params[\Ushahidi\App\Validator\Role\Update::class] = [
'permission_repo' => $di->lazyGet('repository.permission'),
'feature_enabled' => $di->lazyGet('roles.enabled'),
'permission_repo' => $di->lazyGet('repository.permission')
];

// Validator Setters
Expand Down Expand Up @@ -991,76 +986,11 @@ public function define(Container $di)
return $di->get('repository.config')->get('map')->asArray();
});

// Feature config
$di->set('features', function () use ($di) {
return $di->get('repository.config')->get('features')->asArray();
});

// @todo add some kind of FeatureManager that owns all these checkes
// $features->isEnabled('roles')
// $features->getQuota('admins');
// Roles config settings
$di->set('roles.enabled', function () use ($di) {
$config = $di->get('features');

return $config['roles']['enabled'];
});

// csv speedup config settings
$di->set('csv-speedup.enabled', function () use ($di) {
$config = $di->get('features');
return $config['csv-speedup']['enabled'];
});

// Feature config
$di->set('features.limits', function () use ($di) {
$config = $di->get('features');

return $config['limits'];
});

// Webhooks config settings
$di->set('webhooks.enabled', function () use ($di) {
$config = $di->get('features');

return $config['webhooks']['enabled'];
});

// Post Locking config settings
$di->set('post-locking.enabled', function () use ($di) {
$config = $di->get('features');

return $config['post-locking']['enabled'];
});

// Redis config settings
$di->set('redis.enabled', function () use ($di) {
$config = $di->get('features');

return $config['redis']['enabled'];
});

// Data import config settings
$di->set('data-import.enabled', function () use ($di) {
$config = $di->get('features');

return $config['data-import']['enabled'];
});

// Dataprovider feature config
$di->set('features.data-providers', function () use ($di) {
$config = $di->get('features');
$config = $di->get('repository.config')->get('features')->asArray();

return array_filter($config['data-providers']);
});

// Private deployment config settings
// @todo move to repo
$di->set('site.private', function () use ($di) {
$site = $di->get('site.config');
$features = $di->get('features');
return $site['private']
and $features['private']['enabled'];
});
}
}
5 changes: 3 additions & 2 deletions src/App/Listener/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use League\Event\AbstractListener;
use League\Event\EventInterface;
use Ushahidi\Core\Entity\Set;
use Ushahidi\App\Facades\Features;

class Import extends AbstractListener
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public function handle(
$entity->setState(['status' => 'draft']);
}

if (!service('csv-speedup.enabled')) {
if (!Features::isEnabled('csv-speedup')) {
$importUsecase->verify($entity);
}
// ... persist the new entity
Expand All @@ -83,7 +84,7 @@ public function handle(
'processed' => $processed,
'errors' => $errors
]);

service('repository.csv')->update($csv);
}
}
5 changes: 2 additions & 3 deletions src/App/Listener/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
use League\Event\EventInterface;
use Ushahidi\Core\Traits\RedisFeature;
use Ushahidi\Core\Traits\UserContext;
use Ushahidi\App\Facades\Features;

class Lock extends AbstractListener
{
// Provides getUser()
use UserContext;

use RedisFeature;

public function handle(EventInterface $event, $user_id = null, $event_type = null)
{
$user = $this->getUser();
// Check if the webhooks feature enabled
if (!$this->isRedisEnabled()) {
if (!Features::isEnabled('redis')) {
return false;
}

Expand Down
5 changes: 0 additions & 5 deletions src/App/Repository/Config/features.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
'enabled' => true,
],

// Post locking
'post-locking' => [
'enabled' => true,
],

// Targeted Surveys
'targeted-surveys' => [
'enabled' => false,
Expand Down
Loading

0 comments on commit 42c68e9

Please sign in to comment.