Skip to content

Commit 90dc1e2

Browse files
authored
Merge pull request #16 from LibreCodeCoop/refactor/field-policy-enums
refactor: field policy enums
2 parents dd70944 + c832eb3 commit 90dc1e2

68 files changed

Lines changed: 1396 additions & 975 deletions

File tree

Some content is hidden

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

env.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
/// <reference types="vite/client" />
55

66
declare module '@nextcloud/router' {
7-
export function generateOcsUrl(path: string): string
8-
export function generateUrl(path: string): string
7+
export function generateOcsUrl(path: string, params?: object, options?: object): string
8+
export function generateUrl(path: string, params?: object, options?: object): string
99
}
1010

1111
interface SettingsUserListRow {
-80.7 KB
Loading

img/screenshots/admin-catalog.png

-137 KB
Loading
226 Bytes
Loading
-1.8 KB
Loading
0 Bytes
Loading
0 Bytes
Loading

lib/Controller/FieldDefinitionApiController.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ public function index(): DataResponse {
5555
* @param string $fieldKey Immutable unique key of the field
5656
* @param string $label Human-readable label shown in the UI
5757
* @param string $type Value type accepted by the field
58-
* @param bool $adminOnly Whether only admins can edit values for this field
59-
* @param bool $userEditable Whether the owner can edit the field value
60-
* @param bool $userVisible Whether the owner can see the field in personal settings
61-
* @param string $initialVisibility Initial visibility applied to new values
58+
* @param string $editPolicy Whether values are managed by admins only or by users too
59+
* @param string $exposurePolicy Whether the field is hidden or which default visibility new values receive
6260
* @param int $sortOrder Display order used in admin and profile forms
6361
* @param bool $active Whether the definition is currently active
6462
* @param list<string> $options Allowed values for select fields (ignored for other types)
@@ -72,10 +70,8 @@ public function create(
7270
string $fieldKey,
7371
string $label,
7472
string $type,
75-
bool $adminOnly = false,
76-
bool $userEditable = false,
77-
bool $userVisible = true,
78-
string $initialVisibility = 'private',
73+
string $editPolicy = 'users',
74+
string $exposurePolicy = 'private',
7975
int $sortOrder = 0,
8076
bool $active = true,
8177
array $options = [],
@@ -85,10 +81,8 @@ public function create(
8581
'field_key' => $fieldKey,
8682
'label' => $label,
8783
'type' => $type,
88-
'admin_only' => $adminOnly,
89-
'user_editable' => $userEditable,
90-
'user_visible' => $userVisible,
91-
'initial_visibility' => $initialVisibility,
84+
'edit_policy' => $editPolicy,
85+
'exposure_policy' => $exposurePolicy,
9286
'sort_order' => $sortOrder,
9387
'active' => $active,
9488
];
@@ -111,10 +105,8 @@ public function create(
111105
* @param int $id Identifier of the field definition
112106
* @param string $label Human-readable label shown in the UI
113107
* @param string $type Value type accepted by the field
114-
* @param bool $adminOnly Whether only admins can edit values for this field
115-
* @param bool $userEditable Whether the owner can edit the field value
116-
* @param bool $userVisible Whether the owner can see the field in personal settings
117-
* @param string $initialVisibility Initial visibility applied to new values
108+
* @param string $editPolicy Whether values are managed by admins only or by users too
109+
* @param string $exposurePolicy Whether the field is hidden or which default visibility new values receive
118110
* @param int $sortOrder Display order used in admin and profile forms
119111
* @param bool $active Whether the definition is currently active
120112
* @param list<string> $options Allowed values for select fields (ignored for other types)
@@ -129,10 +121,8 @@ public function update(
129121
int $id,
130122
string $label,
131123
string $type,
132-
bool $adminOnly = false,
133-
bool $userEditable = false,
134-
bool $userVisible = true,
135-
string $initialVisibility = 'private',
124+
string $editPolicy = 'users',
125+
string $exposurePolicy = 'private',
136126
int $sortOrder = 0,
137127
bool $active = true,
138128
array $options = [],
@@ -146,10 +136,8 @@ public function update(
146136
$payload = [
147137
'label' => $label,
148138
'type' => $type,
149-
'admin_only' => $adminOnly,
150-
'user_editable' => $userEditable,
151-
'user_visible' => $userVisible,
152-
'initial_visibility' => $initialVisibility,
139+
'edit_policy' => $editPolicy,
140+
'exposure_policy' => $exposurePolicy,
153141
'sort_order' => $sortOrder,
154142
'active' => $active,
155143
];

lib/Controller/FieldValueApiController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use InvalidArgumentException;
1313
use OCA\ProfileFields\AppInfo\Application;
14+
use OCA\ProfileFields\Enum\FieldExposurePolicy;
1415
use OCA\ProfileFields\Service\FieldAccessService;
1516
use OCA\ProfileFields\Service\FieldDefinitionService;
1617
use OCA\ProfileFields\Service\FieldValueService;
@@ -58,7 +59,7 @@ public function index(): DataResponse {
5859
$editableFields = [];
5960

6061
foreach ($definitions as $definition) {
61-
if (!$definition->getUserVisible()) {
62+
if (!FieldExposurePolicy::from($definition->getExposurePolicy())->isUserVisible()) {
6263
continue;
6364
}
6465

lib/Db/FieldDefinition.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@
2020
* @method void setLabel(string $value)
2121
* @method string getType()
2222
* @method void setType(string $value)
23-
* @method bool getAdminOnly()
24-
* @method void setAdminOnly(bool $value)
25-
* @method bool getUserEditable()
26-
* @method void setUserEditable(bool $value)
27-
* @method bool getUserVisible()
28-
* @method void setUserVisible(bool $value)
29-
* @method string getInitialVisibility()
30-
* @method void setInitialVisibility(string $value)
23+
* @method string getEditPolicy()
24+
* @method void setEditPolicy(string $value)
25+
* @method string getExposurePolicy()
26+
* @method void setExposurePolicy(string $value)
3127
* @method int getSortOrder()
3228
* @method void setSortOrder(int $value)
3329
* @method bool getActive()
@@ -43,10 +39,8 @@ class FieldDefinition extends Entity {
4339
protected $fieldKey;
4440
protected $label;
4541
protected $type;
46-
protected $adminOnly;
47-
protected $userEditable;
48-
protected $userVisible;
49-
protected $initialVisibility;
42+
protected $editPolicy;
43+
protected $exposurePolicy;
5044
protected $sortOrder;
5145
protected $active;
5246
protected $options;
@@ -55,9 +49,6 @@ class FieldDefinition extends Entity {
5549

5650
public function __construct() {
5751
$this->addType('id', 'integer');
58-
$this->addType('adminOnly', 'boolean');
59-
$this->addType('userEditable', 'boolean');
60-
$this->addType('userVisible', 'boolean');
6152
$this->addType('sortOrder', 'integer');
6253
$this->addType('active', 'boolean');
6354
$this->addType('createdAt', 'datetime');
@@ -70,10 +61,8 @@ public function __construct() {
7061
* field_key: string,
7162
* label: string,
7263
* type: string,
73-
* admin_only: bool,
74-
* user_editable: bool,
75-
* user_visible: bool,
76-
* initial_visibility: string,
64+
* edit_policy: string,
65+
* exposure_policy: string,
7766
* sort_order: int,
7867
* active: bool,
7968
* options: list<string>|null,
@@ -89,10 +78,8 @@ public function jsonSerialize(): array {
8978
'field_key' => $this->getFieldKey(),
9079
'label' => $this->getLabel(),
9180
'type' => $this->getType(),
92-
'admin_only' => $this->getAdminOnly(),
93-
'user_editable' => $this->getUserEditable(),
94-
'user_visible' => $this->getUserVisible(),
95-
'initial_visibility' => $this->getInitialVisibility(),
81+
'edit_policy' => $this->getEditPolicy(),
82+
'exposure_policy' => $this->getExposurePolicy(),
9683
'sort_order' => $this->getSortOrder(),
9784
'active' => $this->getActive(),
9885
'options' => $rawOptions !== null ? (json_decode($rawOptions, true) ?? null) : null,

0 commit comments

Comments
 (0)