MCPcopy Create free account
hub / github.com/error311/FileRise / getUserPermissions

Method getUserPermissions

src/FileRise/Domain/UserModel.php:444–477  ·  view source on GitHub ↗

* Get permissions for current user (or all, if admin). */

()

Source from the content-addressed store, hash-verified

442 * Get permissions for current user (or all, if admin).
443 */
444 public static function getUserPermissions()
445 {
446 self::ensureUserCaseMigration();
447 global $encryptionKey;
448 $permissionsFile = USERS_DIR . "userPermissions.json";
449 $permissionsArray = [];
450
451 if (file_exists($permissionsFile)) {
452 $content = file_get_contents($permissionsFile);
453 $decrypted = decryptData($content, $encryptionKey);
454 if ($decrypted === false) {
455 // tolerate legacy plaintext
456 $permissionsArray = json_decode($content, true);
457 } else {
458 $permissionsArray = json_decode($decrypted, true);
459 }
460 if (!is_array($permissionsArray)) {
461 $permissionsArray = [];
462 }
463 }
464
465 if (!empty($_SESSION['isAdmin'])) {
466 return $permissionsArray;
467 }
468
469 $username = $_SESSION['username'] ?? '';
470 foreach ($permissionsArray as $storedUsername => $data) {
471 if (strcasecmp($storedUsername, $username) === 0) {
472 return $data;
473 }
474 }
475
476 return new \stdClass();
477 }
478
479 /**
480 * Update permissions (encrypted on disk). Skips admins.

Callers 3

loadUserPermissionsMethod · 0.45

Calls 2

decryptDataFunction · 0.85

Tested by

no test coverage detected