4141
4242use OC \Accounts \AccountManager ;
4343use OC \AppFramework \Http ;
44+ use OC \Encryption \Exceptions \ModuleDoesNotExistsException ;
4445use OC \ForbiddenException ;
4546use OC \Security \IdentityProof \Manager ;
4647use OCA \User_LDAP \User_Proxy ;
@@ -128,9 +129,9 @@ public function __construct(string $appName,
128129 /**
129130 * @NoCSRFRequired
130131 * @NoAdminRequired
131- *
132+ *
132133 * Display users list template
133- *
134+ *
134135 * @return TemplateResponse
135136 */
136137 public function usersListByGroup () {
@@ -140,17 +141,17 @@ public function usersListByGroup() {
140141 /**
141142 * @NoCSRFRequired
142143 * @NoAdminRequired
143- *
144+ *
144145 * Display users list template
145- *
146+ *
146147 * @return TemplateResponse
147148 */
148149 public function usersList () {
149150 $ user = $ this ->userSession ->getUser ();
150151 $ uid = $ user ->getUID ();
151152
152153 \OC ::$ server ->getNavigationManager ()->setActiveEntry ('core_users ' );
153-
154+
154155 /* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */
155156 $ sortGroupsBy = \OC \Group \MetaData::SORT_USERCOUNT ;
156157 $ isLDAPUsed = false ;
@@ -166,22 +167,17 @@ public function usersList() {
166167 }
167168 }
168169 }
169-
170- /* ENCRYPTION CONFIG */
171- $ isEncryptionEnabled = $ this ->encryptionManager ->isEnabled ();
172- $ useMasterKey = $ this ->config ->getAppValue ('encryption ' , 'useMasterKey ' , true );
173- // If masterKey enabled, then you can change password. This is to avoid data loss!
174- $ canChangePassword = ($ isEncryptionEnabled && $ useMasterKey ) || $ useMasterKey ;
175-
176-
177- /* GROUPS */
170+
171+ $ canChangePassword = $ this ->canAdminChangeUserPasswords ();
172+
173+ /* GROUPS */
178174 $ groupsInfo = new \OC \Group \MetaData (
179175 $ uid ,
180176 $ this ->isAdmin ,
181177 $ this ->groupManager ,
182178 $ this ->userSession
183179 );
184-
180+
185181 $ groupsInfo ->setSorting ($ sortGroupsBy );
186182 list ($ adminGroup , $ groups ) = $ groupsInfo ->get ();
187183
@@ -190,7 +186,7 @@ public function usersList() {
190186 return $ ldapFound || $ backend instanceof User_Proxy;
191187 });
192188 }
193-
189+
194190 if ($ this ->isAdmin ) {
195191 $ disabledUsers = $ isLDAPUsed ? -1 : $ this ->userManager ->countDisabledUsers ();
196192 $ userCount = $ isLDAPUsed ? 0 : array_reduce ($ this ->userManager ->countUsers (), function ($ v , $ w ) {
@@ -221,7 +217,7 @@ public function usersList() {
221217 'name ' => 'Disabled users ' ,
222218 'usercount ' => $ disabledUsers
223219 ];
224-
220+
225221 /* QUOTAS PRESETS */
226222 $ quotaPreset = $ this ->config ->getAppValue ('files ' , 'quota_preset ' , '1 GB, 5 GB, 10 GB ' );
227223 $ quotaPreset = explode (', ' , $ quotaPreset );
@@ -230,12 +226,12 @@ public function usersList() {
230226 }
231227 $ quotaPreset = array_diff ($ quotaPreset , array ('default ' , 'none ' ));
232228 $ defaultQuota = $ this ->config ->getAppValue ('files ' , 'default_quota ' , 'none ' );
233-
229+
234230 \OC ::$ server ->getEventDispatcher ()->dispatch ('OC\Settings\Users::loadAdditionalScripts ' );
235-
231+
236232 /* LANGUAGES */
237233 $ languages = $ this ->l10nFactory ->getLanguages ();
238-
234+
239235 /* FINAL DATA */
240236 $ serverData = array ();
241237 // groups
@@ -254,6 +250,38 @@ public function usersList() {
254250 return new TemplateResponse ('settings ' , 'settings-vue ' , ['serverData ' => $ serverData ]);
255251 }
256252
253+ /**
254+ * check if the admin can change the users password
255+ *
256+ * The admin can change the passwords if:
257+ *
258+ * - no encryption module is loaded and encryption is disabled
259+ * - encryption module is loaded but it doesn't require per user keys
260+ *
261+ * The admin can not change the passwords if:
262+ *
263+ * - an encryption module is loaded and it uses per-user keys
264+ * - encryption is enabled but no encryption modules are loaded
265+ *
266+ * @return bool
267+ */
268+ protected function canAdminChangeUserPasswords () {
269+ $ isEncryptionEnabled = $ this ->encryptionManager ->isEnabled ();
270+ try {
271+ $ noUserSpecificEncryptionKeys =!$ this ->encryptionManager ->getEncryptionModule ()->needDetailedAccessList ();
272+ $ isEncryptionModuleLoaded = true ;
273+ } catch (ModuleDoesNotExistsException $ e ) {
274+ $ noUserSpecificEncryptionKeys = true ;
275+ $ isEncryptionModuleLoaded = false ;
276+ }
277+
278+ $ canChangePassword = ($ isEncryptionEnabled && $ isEncryptionModuleLoaded && $ noUserSpecificEncryptionKeys )
279+ || (!$ isEncryptionEnabled && !$ isEncryptionModuleLoaded )
280+ || (!$ isEncryptionEnabled && $ isEncryptionModuleLoaded && $ noUserSpecificEncryptionKeys );
281+
282+ return $ canChangePassword ;
283+ }
284+
257285 /**
258286 * @NoAdminRequired
259287 * @NoSubadminRequired
0 commit comments