Skip to content

Commit af0d56d

Browse files
committed
Merge branch 'develop'
2 parents 6f31082 + 55ded17 commit af0d56d

File tree

275 files changed

+1033
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

275 files changed

+1033
-47
lines changed

docker/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and issue `make image`
1616

1717
```
1818
COMPOSER_VERSION?=2.1.5
19-
PHP_VERSION?=7.4
19+
PHP_VERSION?=8.2
2020
DEBIAN_RELEASE?=buster
2121
IMAGE_NAME?=cerebrate:latest
2222

src/Controller/Component/ACLComponent.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@ public function initialize(array $config): void
239239
'delete' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
240240
'edit' => ['*'],
241241
'index' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
242+
'filtering' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
242243
'login' => ['*'],
243244
'logout' => ['*'],
244245
'register' => ['*'],
245246
'settings' => ['*'],
246247
'toggle' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
247-
'view' => ['*']
248+
'view' => ['*'],
249+
'getLimitationForOrganisation' => ['OR' => ['perm_org_admin', 'perm_community_admin']],
248250
],
249251
'UserSettings' => [
250252
'index' => ['*'],

src/Controller/Component/CRUDComponent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public function getResponsePayload()
393393
return false;
394394
}
395395

396-
private function getMetaTemplates(array $metaTemplateConditions = [])
396+
public function getMetaTemplates(array $metaTemplateConditions = [])
397397
{
398398
$metaTemplates = [];
399399
if (!$this->metaFieldsSupported()) {

src/Controller/UsersController.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public function edit($id = false)
336336
$org_conditions = [];
337337
if (empty($currentUser['role']['perm_community_admin'])) {
338338
$org_conditions = ['id' => $currentUser['organisation_id']];
339-
if (!empty($currentUser['role']['perm_group_admin'])) {
339+
if (!empty($currentUser['role']['perm_group_admin']) && !empty($validOrgIds)) {
340340
$org_conditions = ['id IN' => $validOrgIds];
341341
}
342342
}
@@ -541,4 +541,22 @@ public function register()
541541
}
542542
$this->viewBuilder()->setLayout('login');
543543
}
544+
545+
public function getLimitationForOrganisation($org_id) {
546+
$currentUser = $this->ACL->getUser();
547+
if (!$currentUser['role']['perm_community_admin']) {
548+
$validOrgs = $this->Users->getValidOrgsForUser($currentUser);
549+
if ($currentUser['role']['perm_group_admin']) {
550+
if (!in_array($org_id, $validOrgs)) {
551+
throw new MethodNotAllowedException(__('You do not have permission to assign that organisation.'));
552+
}
553+
}
554+
}
555+
$fakeUser = $this->Users->newEmptyEntity();
556+
$fakeUser->organisation_id = $org_id; // set fakeUser's to the selected org-id
557+
$metaTemplates = $this->CRUD->getMetaTemplates();
558+
$fakeUser = $this->CRUD->attachMetaTemplatesIfNeeded($fakeUser, $metaTemplates->toArray());
559+
$fakeUser = $this->fetchTable('PermissionLimitations')->attachLimitations($fakeUser);
560+
return $this->RestResponse->viewData($fakeUser, 'json');
561+
}
544562
}

src/Model/Table/PermissionLimitationsTable.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,24 @@ public function getListOfLimitations(\App\Model\Entity\User $data)
6767
]
6868
])->all()->toList();
6969
if (isset($data['global'])) {
70+
$conditions = [
71+
'scope' => 'user',
72+
'field' => $field,
73+
];
74+
if (!empty($disabledUserIds)) {
75+
$conditions['parent_id NOT IN'] = $disabledUserIds;
76+
}
7077
$limitations[$field]['global']['current'] = $MetaFields->find('all', [
71-
'conditions' => [
72-
'scope' => 'user',
73-
'field' => $field,
74-
'parent_id NOT IN' => $disabledUserIds
75-
]
78+
'conditions' => $conditions,
7679
])->count();
7780
}
7881
if (isset($data['global'])) {
7982
$conditions = [
8083
'scope' => 'user',
8184
'field' => $field,
8285
];
83-
if (!empty($ownOrgUserIds)) {
84-
$conditions['parent_id IN'] = array_values($ownOrgUserIds);
86+
if ($includeOrganisationPermissions) {
87+
$conditions['parent_id IN'] = !empty($ownOrgUserIds) ? array_values($ownOrgUserIds) : [-1];
8588
}
8689
$limitations[$field]['organisation']['current'] = '?';
8790
if ($includeOrganisationPermissions) {

src/View/AppView.php

+1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ public function initialize(): void
4545
$this->loadHelper('Paginator', ['templates' => 'cerebrate-pagination-templates']);
4646
$this->loadHelper('Tags.Tag');
4747
$this->loadHelper('ACL');
48+
$this->loadHelper('Flag');
4849
}
4950
}

src/View/Helper/FlagHelper.php

+253
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
<?php
2+
namespace App\View\Helper;
3+
4+
use Cake\Utility\Inflector;
5+
use Cake\View\Helper;
6+
7+
// This helper helps determining the brightness of a colour (initially only used for the tagging) in order to decide
8+
// what text colour to use against the background (black or white)
9+
class FlagHelper extends Helper {
10+
11+
public $helpers = [
12+
'Bootstrap',
13+
];
14+
15+
/**
16+
* @param string $countryCode ISO 3166-1 alpha-2 two-letter country code
17+
* @param string $countryName Full country name for title
18+
* @return string
19+
*/
20+
public function countryFlag($countryCode, $countryName = null, $small = false)
21+
{
22+
if (strlen($countryCode) !== 2) {
23+
return '';
24+
}
25+
26+
$output = [];
27+
foreach (str_split(strtolower($countryCode)) as $letter) {
28+
$letterCode = ord($letter);
29+
if ($letterCode < 97 || $letterCode > 122) {
30+
return ''; // invalid letter
31+
}
32+
$output[] = "1f1" . dechex(0xe6 + ($letterCode - 97));
33+
}
34+
35+
$countryNamePretty = Inflector::humanize($countryName ? h($countryName) : $countryCode);
36+
$baseurl = $this->getView()->get('baseurl');
37+
$title = __('Flag of %s', $countryNamePretty);
38+
$html = '<img src="' . $baseurl . '/img/flags/' . implode('-', $output) . '.svg" title="' . $title .'" alt="' . $title . '" aria-label="' . $title . '" style="height: 18px" />';
39+
if (!$small) {
40+
$html = $this->Bootstrap->node('span', [
41+
'class' => 'd-flex align-items-center'
42+
], $html . '&nbsp;' . $countryNamePretty);
43+
}
44+
return $html;
45+
}
46+
47+
public function flag($countryName, $small = false) {
48+
$countryNameLow = strtolower($countryName);
49+
if (!empty(self::countries[$countryNameLow])) {
50+
$countryCode = self::countries[$countryNameLow];
51+
return $this->countryFlag($countryCode, $countryName, $small);
52+
}
53+
return '';
54+
}
55+
56+
private const countries = [
57+
"afghanistan" => "AF",
58+
"albania" => "AL",
59+
"algeria" => "DZ",
60+
"andorra" => "AD",
61+
"angola" => "AO",
62+
"antigua and barbuda" => "AG",
63+
"argentina" => "AR",
64+
"armenia" => "AM",
65+
"australia" => "AU",
66+
"austria" => "AT",
67+
"azerbaijan" => "AZ",
68+
"bahamas" => "BS",
69+
"bahrain" => "BH",
70+
"bangladesh" => "BD",
71+
"barbados" => "BB",
72+
"belarus" => "BY",
73+
"belgium" => "BE",
74+
"belize" => "BZ",
75+
"benin" => "BJ",
76+
"bhutan" => "BT",
77+
"bolivia" => "BO",
78+
"bosnia and herzegovina" => "BA",
79+
"botswana" => "BW",
80+
"brazil" => "BR",
81+
"brunei" => "BN",
82+
"bulgaria" => "BG",
83+
"burkina faso" => "BF",
84+
"burundi" => "BI",
85+
"cabo verde" => "CV",
86+
"cambodia" => "KH",
87+
"cameroon" => "CM",
88+
"canada" => "CA",
89+
"central african republic" => "CF",
90+
"chad" => "TD",
91+
"chile" => "CL",
92+
"china" => "CN",
93+
"colombia" => "CO",
94+
"comoros" => "KM",
95+
"congo (brazzaville)" => "CG",
96+
"congo (kinshasa)" => "CD",
97+
"costa rica" => "CR",
98+
"croatia" => "HR",
99+
"cuba" => "CU",
100+
"cyprus" => "CY",
101+
"czechia" => "CZ",
102+
"denmark" => "DK",
103+
"djibouti" => "DJ",
104+
"dominica" => "DM",
105+
"dominican republic" => "DO",
106+
"ecuador" => "EC",
107+
"egypt" => "EG",
108+
"el salvador" => "SV",
109+
"equatorial guinea" => "GQ",
110+
"eritrea" => "ER",
111+
"estonia" => "EE",
112+
"eswatini" => "SZ",
113+
"ethiopia" => "ET",
114+
"fiji" => "FJ",
115+
"finland" => "FI",
116+
"france" => "FR",
117+
"gabon" => "GA",
118+
"gambia" => "GM",
119+
"georgia" => "GE",
120+
"germany" => "DE",
121+
"ghana" => "GH",
122+
"greece" => "GR",
123+
"grenada" => "GD",
124+
"guatemala" => "GT",
125+
"guinea" => "GN",
126+
"guinea-bissau" => "GW",
127+
"guyana" => "GY",
128+
"haiti" => "HT",
129+
"honduras" => "HN",
130+
"hungary" => "HU",
131+
"iceland" => "IS",
132+
"india" => "IN",
133+
"indonesia" => "ID",
134+
"iran" => "IR",
135+
"iraq" => "IQ",
136+
"ireland" => "IE",
137+
"israel" => "IL",
138+
"italy" => "IT",
139+
"jamaica" => "JM",
140+
"japan" => "JP",
141+
"jordan" => "JO",
142+
"kazakhstan" => "KZ",
143+
"kenya" => "KE",
144+
"kiribati" => "KI",
145+
"korea (north)" => "KP",
146+
"korea (south)" => "KR",
147+
"kuwait" => "KW",
148+
"kyrgyzstan" => "KG",
149+
"laos" => "LA",
150+
"latvia" => "LV",
151+
"lebanon" => "LB",
152+
"lesotho" => "LS",
153+
"liberia" => "LR",
154+
"libya" => "LY",
155+
"liechtenstein" => "LI",
156+
"lithuania" => "LT",
157+
"luxembourg" => "LU",
158+
"madagascar" => "MG",
159+
"malawi" => "MW",
160+
"malaysia" => "MY",
161+
"maldives" => "MV",
162+
"mali" => "ML",
163+
"malta" => "MT",
164+
"marshall islands" => "MH",
165+
"mauritania" => "MR",
166+
"mauritius" => "MU",
167+
"mexico" => "MX",
168+
"micronesia" => "FM",
169+
"moldova" => "MD",
170+
"monaco" => "MC",
171+
"mongolia" => "MN",
172+
"montenegro" => "ME",
173+
"morocco" => "MA",
174+
"mozambique" => "MZ",
175+
"myanmar" => "MM",
176+
"namibia" => "NA",
177+
"nauru" => "NR",
178+
"nepal" => "NP",
179+
"netherlands" => "NL",
180+
"new zealand" => "NZ",
181+
"nicaragua" => "NI",
182+
"niger" => "NE",
183+
"nigeria" => "NG",
184+
"north macedonia" => "MK",
185+
"norway" => "NO",
186+
"oman" => "OM",
187+
"pakistan" => "PK",
188+
"palau" => "PW",
189+
"panama" => "PA",
190+
"papua new guinea" => "PG",
191+
"paraguay" => "PY",
192+
"peru" => "PE",
193+
"philippines" => "PH",
194+
"poland" => "PL",
195+
"portugal" => "PT",
196+
"qatar" => "QA",
197+
"romania" => "RO",
198+
"russia" => "RU",
199+
"rwanda" => "RW",
200+
"saint kitts and nevis" => "KN",
201+
"saint lucia" => "LC",
202+
"saint vincent and the grenadines" => "VC",
203+
"samoa" => "WS",
204+
"san marino" => "SM",
205+
"sao tome and principe" => "ST",
206+
"saudi arabia" => "SA",
207+
"senegal" => "SN",
208+
"serbia" => "RS",
209+
"seychelles" => "SC",
210+
"sierra leone" => "SL",
211+
"singapore" => "SG",
212+
"slovakia" => "SK",
213+
"slovenia" => "SI",
214+
"solomon islands" => "SB",
215+
"somalia" => "SO",
216+
"south africa" => "ZA",
217+
"south sudan" => "SS",
218+
"spain" => "ES",
219+
"sri lanka" => "LK",
220+
"sudan" => "SD",
221+
"suriname" => "SR",
222+
"sweden" => "SE",
223+
"switzerland" => "CH",
224+
"syria" => "SY",
225+
"taiwan" => "TW",
226+
"tajikistan" => "TJ",
227+
"tanzania" => "TZ",
228+
"thailand" => "TH",
229+
"timor-leste" => "TL",
230+
"togo" => "TG",
231+
"tonga" => "TO",
232+
"trinidad and tobago" => "TT",
233+
"tunisia" => "TN",
234+
"turkey" => "TR",
235+
"turkmenistan" => "TM",
236+
"tuvalu" => "TV",
237+
"uganda" => "UG",
238+
"ukraine" => "UA",
239+
"united arab emirates" => "AE",
240+
"united kingdom" => "GB",
241+
"united states" => "US",
242+
"uruguay" => "UY",
243+
"uzbekistan" => "UZ",
244+
"vanuatu" => "VU",
245+
"vatican city" => "VA",
246+
"venezuela" => "VE",
247+
"vietnam" => "VN",
248+
"yemen" => "YE",
249+
"zambia" => "ZM",
250+
"zimbabwe" => "ZW"
251+
];
252+
253+
}

templates/Instance/search_all.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
foreach ($tableResult['entries'] as $entry) {
2222
if ($entry->getSource() == 'MetaFields') {
23-
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
23+
$section .= sprintf('<a class="dropdown-item" href="%s" style="max-width: 70vw; overflow: hidden; text-overflow: ellipsis;">%s</a>',
2424
Cake\Routing\Router::URL([
2525
'controller' => Cake\Utility\Inflector::pluralize($entry->scope),
2626
'action' => 'view',
@@ -29,7 +29,7 @@
2929
sprintf('%s (%s::%s)', h($entry->value), h($entry->scope), h($entry->field))
3030
);
3131
} else {
32-
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
32+
$section .= sprintf('<a class="dropdown-item" href="%s" style="max-width: 70vw; overflow: hidden; text-overflow: ellipsis;">%s</a>',
3333
Cake\Routing\Router::URL([
3434
'controller' => Cake\Utility\Inflector::pluralize($entry->getSource()),
3535
'action' => 'view',

templates/Organisations/index.php

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
'name' => __('Country'),
7979
'data_path' => 'nationality',
8080
'sort' => 'nationality',
81+
'element' => 'country',
8182
],
8283
[
8384
'name' => __('Sector'),

templates/Organisations/view.php

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
],
2020
[
2121
'key' => __('Country'),
22+
'type' => 'country',
2223
'path' => 'nationality'
2324
],
2425
[

0 commit comments

Comments
 (0)