Skip to content

Commit b9e75b1

Browse files
PVince81nextcloud-command
authored andcommitted
Allow to disable password policy enforcement for selected groups
Backport to stable22 with fixed conflicts and recompiled. Signed-off-by: Vincent Petry <[email protected]> Signed-off-by: nextcloud-command <[email protected]>
1 parent 3c72ba3 commit b9e75b1

16 files changed

Lines changed: 88 additions & 10 deletions

File tree

apps/files_sharing/tests/CapabilitiesTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function testOnlyLinkSharing() {
137137
$map = [
138138
['core', 'shareapi_enabled', 'yes', 'yes'],
139139
['core', 'shareapi_allow_links', 'yes', 'yes'],
140+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
140141
];
141142
$result = $this->getResults($map);
142143
$this->assertIsArray($result['public']);
@@ -147,6 +148,7 @@ public function testLinkPassword() {
147148
$map = [
148149
['core', 'shareapi_enabled', 'yes', 'yes'],
149150
['core', 'shareapi_allow_links', 'yes', 'yes'],
151+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
150152
['core', 'shareapi_enforce_links_password', 'no', 'yes'],
151153
];
152154
$result = $this->getResults($map);
@@ -159,6 +161,7 @@ public function testLinkNoPassword() {
159161
$map = [
160162
['core', 'shareapi_enabled', 'yes', 'yes'],
161163
['core', 'shareapi_allow_links', 'yes', 'yes'],
164+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
162165
['core', 'shareapi_enforce_links_password', 'no', 'no'],
163166
];
164167
$result = $this->getResults($map);
@@ -172,6 +175,7 @@ public function testLinkNoExpireDate() {
172175
['core', 'shareapi_enabled', 'yes', 'yes'],
173176
['core', 'shareapi_allow_links', 'yes', 'yes'],
174177
['core', 'shareapi_default_expire_date', 'no', 'no'],
178+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
175179
];
176180
$result = $this->getResults($map);
177181
$this->assertArrayHasKey('expire_date', $result['public']);
@@ -186,6 +190,7 @@ public function testLinkExpireDate() {
186190
['core', 'shareapi_default_expire_date', 'no', 'yes'],
187191
['core', 'shareapi_expire_after_n_days', '7', '7'],
188192
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
193+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
189194
];
190195
$result = $this->getResults($map);
191196
$this->assertArrayHasKey('expire_date', $result['public']);
@@ -201,6 +206,7 @@ public function testLinkExpireDateEnforced() {
201206
['core', 'shareapi_allow_links', 'yes', 'yes'],
202207
['core', 'shareapi_default_expire_date', 'no', 'yes'],
203208
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
209+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
204210
];
205211
$result = $this->getResults($map);
206212
$this->assertArrayHasKey('expire_date', $result['public']);
@@ -213,6 +219,7 @@ public function testLinkSendMail() {
213219
['core', 'shareapi_enabled', 'yes', 'yes'],
214220
['core', 'shareapi_allow_links', 'yes', 'yes'],
215221
['core', 'shareapi_allow_public_notification', 'no', 'yes'],
222+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
216223
];
217224
$result = $this->getResults($map);
218225
$this->assertTrue($result['public']['send_mail']);
@@ -223,6 +230,7 @@ public function testLinkNoSendMail() {
223230
['core', 'shareapi_enabled', 'yes', 'yes'],
224231
['core', 'shareapi_allow_links', 'yes', 'yes'],
225232
['core', 'shareapi_allow_public_notification', 'no', 'no'],
233+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
226234
];
227235
$result = $this->getResults($map);
228236
$this->assertFalse($result['public']['send_mail']);
@@ -232,6 +240,7 @@ public function testResharing() {
232240
$map = [
233241
['core', 'shareapi_enabled', 'yes', 'yes'],
234242
['core', 'shareapi_allow_resharing', 'yes', 'yes'],
243+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
235244
];
236245
$result = $this->getResults($map);
237246
$this->assertTrue($result['resharing']);
@@ -241,6 +250,7 @@ public function testNoResharing() {
241250
$map = [
242251
['core', 'shareapi_enabled', 'yes', 'yes'],
243252
['core', 'shareapi_allow_resharing', 'yes', 'no'],
253+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
244254
];
245255
$result = $this->getResults($map);
246256
$this->assertFalse($result['resharing']);
@@ -251,6 +261,7 @@ public function testLinkPublicUpload() {
251261
['core', 'shareapi_enabled', 'yes', 'yes'],
252262
['core', 'shareapi_allow_links', 'yes', 'yes'],
253263
['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
264+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
254265
];
255266
$result = $this->getResults($map);
256267
$this->assertTrue($result['public']['upload']);
@@ -262,6 +273,7 @@ public function testLinkNoPublicUpload() {
262273
['core', 'shareapi_enabled', 'yes', 'yes'],
263274
['core', 'shareapi_allow_links', 'yes', 'yes'],
264275
['core', 'shareapi_allow_public_upload', 'yes', 'no'],
276+
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
265277
];
266278
$result = $this->getResults($map);
267279
$this->assertFalse($result['public']['upload']);

apps/settings/js/admin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
window.addEventListener('DOMContentLoaded', function(){
2-
$('#excludedGroups,#linksExcludedGroups').each(function (index, element) {
2+
$('#excludedGroups,#linksExcludedGroups,#passwordsExcludedGroups').each(function (index, element) {
33
OC.Settings.setupGroupsSelect($(element));
44
$(element).change(function(ev) {
55
var groups = ev.val || [];
@@ -94,6 +94,10 @@ window.addEventListener('DOMContentLoaded', function(){
9494
$("#setDefaultRemoteExpireDate").toggleClass('hidden', !this.checked);
9595
});
9696

97+
$('#enforceLinkPassword').change(function() {
98+
$("#selectPasswordsExcludedGroups").toggleClass('hidden', !this.checked);
99+
});
100+
97101
$('#publicShareDisclaimer').change(function() {
98102
$("#publicShareDisclaimerText").toggleClass('hidden', !this.checked);
99103
if(!this.checked) {

apps/settings/lib/Settings/Admin/Sharing.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public function getForm() {
7070
$linksExcludeGroupsList = !is_null(json_decode($linksExcludedGroups))
7171
? implode('|', json_decode($linksExcludedGroups, true)) : '';
7272

73+
$excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
74+
$excludedPasswordGroupsList = !is_null(json_decode($excludedPasswordGroups))
75+
? implode('|', json_decode($excludedPasswordGroups, true)) : '';
76+
77+
7378
$parameters = [
7479
// Built-In Sharing
7580
'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
@@ -81,7 +86,9 @@ public function getForm() {
8186
'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'),
8287
'restrictUserEnumerationToPhone' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no'),
8388
'restrictUserEnumerationFullMatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes'),
84-
'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(),
89+
'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(false),
90+
'passwordExcludedGroups' => $excludedPasswordGroupsList,
91+
'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('allow_disabled_password_enforcement_groups', false),
8592
'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
8693
'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
8794
'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),

apps/settings/templates/settings/admin/sharing.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@
115115
} ?> />
116116
<label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/>
117117

118+
<?php if ($_['passwordExcludedGroupsFeatureEnabled']) { ?>
119+
<div id="selectPasswordsExcludedGroups" class="indent <?php if (!$_['enforceLinkPassword']) { p('hidden'); } ?>">
120+
<div class="indent">
121+
<label for="shareapi_enforce_links_password_excluded_groups"><?php p($l->t('Exclude groups from password requirements:'));?>
122+
<br />
123+
<input name="shareapi_enforce_links_password_excluded_groups" id="passwordsExcludedGroups" value="<?php p($_['passwordExcludedGroups']) ?>" style="width: 400px" class="noJSAutoUpdate"/>
124+
</div>
125+
</div>
126+
<?php } ?>
127+
128+
<input type="checkbox" name="shareapi_default_expire_date" id="shareapiDefaultExpireDate" class="checkbox" value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') { print_unescaped('checked="checked"'); } ?> />
129+
118130
<input type="checkbox" name="shareapi_default_expire_date" id="shareapiDefaultExpireDate" class="checkbox"
119131
value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') {
120132
print_unescaped('checked="checked"');

lib/composer/bin/php-cs-fixer

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor-bin/cs-fixer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer

lib/composer/bin/php-parse

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor-bin/psalm/vendor/nikic/php-parser/bin/php-parse

lib/composer/bin/psalm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor-bin/psalm/vendor/vimeo/psalm/psalm
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor-bin/psalm/vendor/vimeo/psalm/psalm-language-server

lib/composer/bin/psalm-plugin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor-bin/psalm/vendor/vimeo/psalm/psalm-plugin

lib/composer/bin/psalm-refactor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor-bin/psalm/vendor/vimeo/psalm/psalm-refactor

0 commit comments

Comments
 (0)