Skip to content

Commit

Permalink
Merge pull request #4437 from ushahidi/feat/config-deployment-id
Browse files Browse the repository at this point in the history
feat: change config/multisite resource to config/deployment_id
  • Loading branch information
tuxpiper authored Jun 27, 2022
2 parents 7a73a03 + 4630b94 commit 37636e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
35 changes: 26 additions & 9 deletions src/App/Repository/ConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function get($group)
{
$this->verifyGroup($group);

if ($group == 'multisite') {
return $this->getMultisiteGroup();
if ($group == 'deployment_id') {
return $this->getDeploymentIdGroup();
}

$config = [];
Expand Down Expand Up @@ -112,20 +112,37 @@ public function get($group)
return $this->getEntity(['id' => $group] + $config);
}

protected function getMultisiteGroup()
protected function getDeploymentIdGroup()
{
// The multisite group is special in that it's not persisted in the deployment's database.
// The Deployment Id group is special in that it's not persisted in the deployment's database.
$config = [];

// Multisite IDs
if (app('multisite')->enabled()) {
$multi = app('multisite');
$config = [
$config['multisite'] = [
'enabled' => true,
'site_id' => $multi->getSiteId(),
'site_fqdn' => $multi->site->getClientUri(),
];
} else {
$config = [ 'enabled' => false ];
$config['multisite'] = [];
}
return $this->getEntity(['id' => 'multisite'] + $config);

$analytics_prefix = env('USH_ANALYTICS_PREFIX', null);
$analytics_id =
$config['multisite']['site_id'] ??
env('USH_ANALYTICS_ID', null);
if ($analytics_prefix && $analytics_id) {
$config['analytics'] = [
'prefix' => $analytics_prefix,
'id' => $analytics_id,
];
} else {
$config['analytics'] = [];
}

return $this->getEntity(['id' => 'deployment_id'] + $config);
}

// UpdateRepository
Expand All @@ -136,7 +153,7 @@ public function update(Entity $entity)

$this->verifyGroup($group);

if ($group == 'multisite') {
if ($group == 'deployment_id') {
return; /* noop */
}

Expand Down Expand Up @@ -205,7 +222,7 @@ public function groups()
return [
'features',
'site',
'multisite',
'deployment_id',
'test',
'data-provider',
'map',
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Tools/Authorizer/ConfigAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class ConfigAuthorizer implements Authorizer
* Public config groups
* @var [string, ...]
*/
protected $public_groups = ['features', 'map', 'site', 'multisite'];
protected $public_groups = ['features', 'map', 'site', 'deployment_id'];

/**
* Public config groups
* @var [string, ...]
*/
protected $readonly_groups = ['features', 'multisite'];
protected $readonly_groups = ['features', 'deployment_id'];

/* Authorizer */
public function isAllowed(Entity $entity, $privilege)
Expand Down

0 comments on commit 37636e9

Please sign in to comment.