Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mokaddem committed Sep 25, 2024
2 parents 6f31082 + 55ded17 commit af0d56d
Show file tree
Hide file tree
Showing 275 changed files with 1,033 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and issue `make image`

```
COMPOSER_VERSION?=2.1.5
PHP_VERSION?=7.4
PHP_VERSION?=8.2
DEBIAN_RELEASE?=buster
IMAGE_NAME?=cerebrate:latest
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/Component/ACLComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,14 @@ public function initialize(array $config): void
'delete' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
'edit' => ['*'],
'index' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
'filtering' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
'login' => ['*'],
'logout' => ['*'],
'register' => ['*'],
'settings' => ['*'],
'toggle' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
'view' => ['*']
'view' => ['*'],
'getLimitationForOrganisation' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
],
'UserSettings' => [
'index' => ['*'],
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Component/CRUDComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function getResponsePayload()
return false;
}

private function getMetaTemplates(array $metaTemplateConditions = [])
public function getMetaTemplates(array $metaTemplateConditions = [])
{
$metaTemplates = [];
if (!$this->metaFieldsSupported()) {
Expand Down
20 changes: 19 additions & 1 deletion src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function edit($id = false)
$org_conditions = [];
if (empty($currentUser['role']['perm_community_admin'])) {
$org_conditions = ['id' => $currentUser['organisation_id']];
if (!empty($currentUser['role']['perm_group_admin'])) {
if (!empty($currentUser['role']['perm_group_admin']) && !empty($validOrgIds)) {
$org_conditions = ['id IN' => $validOrgIds];
}
}
Expand Down Expand Up @@ -541,4 +541,22 @@ public function register()
}
$this->viewBuilder()->setLayout('login');
}

public function getLimitationForOrganisation($org_id) {
$currentUser = $this->ACL->getUser();
if (!$currentUser['role']['perm_community_admin']) {
$validOrgs = $this->Users->getValidOrgsForUser($currentUser);
if ($currentUser['role']['perm_group_admin']) {
if (!in_array($org_id, $validOrgs)) {
throw new MethodNotAllowedException(__('You do not have permission to assign that organisation.'));
}
}
}
$fakeUser = $this->Users->newEmptyEntity();
$fakeUser->organisation_id = $org_id; // set fakeUser's to the selected org-id
$metaTemplates = $this->CRUD->getMetaTemplates();
$fakeUser = $this->CRUD->attachMetaTemplatesIfNeeded($fakeUser, $metaTemplates->toArray());
$fakeUser = $this->fetchTable('PermissionLimitations')->attachLimitations($fakeUser);
return $this->RestResponse->viewData($fakeUser, 'json');
}
}
17 changes: 10 additions & 7 deletions src/Model/Table/PermissionLimitationsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,24 @@ public function getListOfLimitations(\App\Model\Entity\User $data)
]
])->all()->toList();
if (isset($data['global'])) {
$conditions = [
'scope' => 'user',
'field' => $field,
];
if (!empty($disabledUserIds)) {
$conditions['parent_id NOT IN'] = $disabledUserIds;
}
$limitations[$field]['global']['current'] = $MetaFields->find('all', [
'conditions' => [
'scope' => 'user',
'field' => $field,
'parent_id NOT IN' => $disabledUserIds
]
'conditions' => $conditions,
])->count();
}
if (isset($data['global'])) {
$conditions = [
'scope' => 'user',
'field' => $field,
];
if (!empty($ownOrgUserIds)) {
$conditions['parent_id IN'] = array_values($ownOrgUserIds);
if ($includeOrganisationPermissions) {
$conditions['parent_id IN'] = !empty($ownOrgUserIds) ? array_values($ownOrgUserIds) : [-1];
}
$limitations[$field]['organisation']['current'] = '?';
if ($includeOrganisationPermissions) {
Expand Down
1 change: 1 addition & 0 deletions src/View/AppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ public function initialize(): void
$this->loadHelper('Paginator', ['templates' => 'cerebrate-pagination-templates']);
$this->loadHelper('Tags.Tag');
$this->loadHelper('ACL');
$this->loadHelper('Flag');
}
}
253 changes: 253 additions & 0 deletions src/View/Helper/FlagHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
<?php
namespace App\View\Helper;

use Cake\Utility\Inflector;
use Cake\View\Helper;

// This helper helps determining the brightness of a colour (initially only used for the tagging) in order to decide
// what text colour to use against the background (black or white)
class FlagHelper extends Helper {

public $helpers = [
'Bootstrap',
];

/**
* @param string $countryCode ISO 3166-1 alpha-2 two-letter country code
* @param string $countryName Full country name for title
* @return string
*/
public function countryFlag($countryCode, $countryName = null, $small = false)
{
if (strlen($countryCode) !== 2) {
return '';
}

$output = [];
foreach (str_split(strtolower($countryCode)) as $letter) {
$letterCode = ord($letter);
if ($letterCode < 97 || $letterCode > 122) {
return ''; // invalid letter
}
$output[] = "1f1" . dechex(0xe6 + ($letterCode - 97));
}

$countryNamePretty = Inflector::humanize($countryName ? h($countryName) : $countryCode);
$baseurl = $this->getView()->get('baseurl');
$title = __('Flag of %s', $countryNamePretty);
$html = '<img src="' . $baseurl . '/img/flags/' . implode('-', $output) . '.svg" title="' . $title .'" alt="' . $title . '" aria-label="' . $title . '" style="height: 18px" />';
if (!$small) {
$html = $this->Bootstrap->node('span', [
'class' => 'd-flex align-items-center'
], $html . '&nbsp;' . $countryNamePretty);
}
return $html;
}

public function flag($countryName, $small = false) {
$countryNameLow = strtolower($countryName);
if (!empty(self::countries[$countryNameLow])) {
$countryCode = self::countries[$countryNameLow];
return $this->countryFlag($countryCode, $countryName, $small);
}
return '';
}

private const countries = [
"afghanistan" => "AF",
"albania" => "AL",
"algeria" => "DZ",
"andorra" => "AD",
"angola" => "AO",
"antigua and barbuda" => "AG",
"argentina" => "AR",
"armenia" => "AM",
"australia" => "AU",
"austria" => "AT",
"azerbaijan" => "AZ",
"bahamas" => "BS",
"bahrain" => "BH",
"bangladesh" => "BD",
"barbados" => "BB",
"belarus" => "BY",
"belgium" => "BE",
"belize" => "BZ",
"benin" => "BJ",
"bhutan" => "BT",
"bolivia" => "BO",
"bosnia and herzegovina" => "BA",
"botswana" => "BW",
"brazil" => "BR",
"brunei" => "BN",
"bulgaria" => "BG",
"burkina faso" => "BF",
"burundi" => "BI",
"cabo verde" => "CV",
"cambodia" => "KH",
"cameroon" => "CM",
"canada" => "CA",
"central african republic" => "CF",
"chad" => "TD",
"chile" => "CL",
"china" => "CN",
"colombia" => "CO",
"comoros" => "KM",
"congo (brazzaville)" => "CG",
"congo (kinshasa)" => "CD",
"costa rica" => "CR",
"croatia" => "HR",
"cuba" => "CU",
"cyprus" => "CY",
"czechia" => "CZ",
"denmark" => "DK",
"djibouti" => "DJ",
"dominica" => "DM",
"dominican republic" => "DO",
"ecuador" => "EC",
"egypt" => "EG",
"el salvador" => "SV",
"equatorial guinea" => "GQ",
"eritrea" => "ER",
"estonia" => "EE",
"eswatini" => "SZ",
"ethiopia" => "ET",
"fiji" => "FJ",
"finland" => "FI",
"france" => "FR",
"gabon" => "GA",
"gambia" => "GM",
"georgia" => "GE",
"germany" => "DE",
"ghana" => "GH",
"greece" => "GR",
"grenada" => "GD",
"guatemala" => "GT",
"guinea" => "GN",
"guinea-bissau" => "GW",
"guyana" => "GY",
"haiti" => "HT",
"honduras" => "HN",
"hungary" => "HU",
"iceland" => "IS",
"india" => "IN",
"indonesia" => "ID",
"iran" => "IR",
"iraq" => "IQ",
"ireland" => "IE",
"israel" => "IL",
"italy" => "IT",
"jamaica" => "JM",
"japan" => "JP",
"jordan" => "JO",
"kazakhstan" => "KZ",
"kenya" => "KE",
"kiribati" => "KI",
"korea (north)" => "KP",
"korea (south)" => "KR",
"kuwait" => "KW",
"kyrgyzstan" => "KG",
"laos" => "LA",
"latvia" => "LV",
"lebanon" => "LB",
"lesotho" => "LS",
"liberia" => "LR",
"libya" => "LY",
"liechtenstein" => "LI",
"lithuania" => "LT",
"luxembourg" => "LU",
"madagascar" => "MG",
"malawi" => "MW",
"malaysia" => "MY",
"maldives" => "MV",
"mali" => "ML",
"malta" => "MT",
"marshall islands" => "MH",
"mauritania" => "MR",
"mauritius" => "MU",
"mexico" => "MX",
"micronesia" => "FM",
"moldova" => "MD",
"monaco" => "MC",
"mongolia" => "MN",
"montenegro" => "ME",
"morocco" => "MA",
"mozambique" => "MZ",
"myanmar" => "MM",
"namibia" => "NA",
"nauru" => "NR",
"nepal" => "NP",
"netherlands" => "NL",
"new zealand" => "NZ",
"nicaragua" => "NI",
"niger" => "NE",
"nigeria" => "NG",
"north macedonia" => "MK",
"norway" => "NO",
"oman" => "OM",
"pakistan" => "PK",
"palau" => "PW",
"panama" => "PA",
"papua new guinea" => "PG",
"paraguay" => "PY",
"peru" => "PE",
"philippines" => "PH",
"poland" => "PL",
"portugal" => "PT",
"qatar" => "QA",
"romania" => "RO",
"russia" => "RU",
"rwanda" => "RW",
"saint kitts and nevis" => "KN",
"saint lucia" => "LC",
"saint vincent and the grenadines" => "VC",
"samoa" => "WS",
"san marino" => "SM",
"sao tome and principe" => "ST",
"saudi arabia" => "SA",
"senegal" => "SN",
"serbia" => "RS",
"seychelles" => "SC",
"sierra leone" => "SL",
"singapore" => "SG",
"slovakia" => "SK",
"slovenia" => "SI",
"solomon islands" => "SB",
"somalia" => "SO",
"south africa" => "ZA",
"south sudan" => "SS",
"spain" => "ES",
"sri lanka" => "LK",
"sudan" => "SD",
"suriname" => "SR",
"sweden" => "SE",
"switzerland" => "CH",
"syria" => "SY",
"taiwan" => "TW",
"tajikistan" => "TJ",
"tanzania" => "TZ",
"thailand" => "TH",
"timor-leste" => "TL",
"togo" => "TG",
"tonga" => "TO",
"trinidad and tobago" => "TT",
"tunisia" => "TN",
"turkey" => "TR",
"turkmenistan" => "TM",
"tuvalu" => "TV",
"uganda" => "UG",
"ukraine" => "UA",
"united arab emirates" => "AE",
"united kingdom" => "GB",
"united states" => "US",
"uruguay" => "UY",
"uzbekistan" => "UZ",
"vanuatu" => "VU",
"vatican city" => "VA",
"venezuela" => "VE",
"vietnam" => "VN",
"yemen" => "YE",
"zambia" => "ZM",
"zimbabwe" => "ZW"
];

}
4 changes: 2 additions & 2 deletions templates/Instance/search_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

foreach ($tableResult['entries'] as $entry) {
if ($entry->getSource() == 'MetaFields') {
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
$section .= sprintf('<a class="dropdown-item" href="%s" style="max-width: 70vw; overflow: hidden; text-overflow: ellipsis;">%s</a>',
Cake\Routing\Router::URL([
'controller' => Cake\Utility\Inflector::pluralize($entry->scope),
'action' => 'view',
Expand All @@ -29,7 +29,7 @@
sprintf('%s (%s::%s)', h($entry->value), h($entry->scope), h($entry->field))
);
} else {
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
$section .= sprintf('<a class="dropdown-item" href="%s" style="max-width: 70vw; overflow: hidden; text-overflow: ellipsis;">%s</a>',
Cake\Routing\Router::URL([
'controller' => Cake\Utility\Inflector::pluralize($entry->getSource()),
'action' => 'view',
Expand Down
1 change: 1 addition & 0 deletions templates/Organisations/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'name' => __('Country'),
'data_path' => 'nationality',
'sort' => 'nationality',
'element' => 'country',
],
[
'name' => __('Sector'),
Expand Down
1 change: 1 addition & 0 deletions templates/Organisations/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
[
'key' => __('Country'),
'type' => 'country',
'path' => 'nationality'
],
[
Expand Down
Loading

0 comments on commit af0d56d

Please sign in to comment.