diff --git a/app/Auth/Role.php b/app/Auth/Role.php index 51b2ce301..3ae469b59 100644 --- a/app/Auth/Role.php +++ b/app/Auth/Role.php @@ -120,6 +120,19 @@ class Role extends Model implements Loggable ->get(); } + /** + * Get a role to represent the case of 'Everyone else' in the system. + * Used within the interface since the default-fallback for permissions uses role_id=0. + */ + public static function getEveryoneElseRole(): self + { + return (new static())->forceFill([ + 'id' => 0, + 'display_name' => 'Everyone Else', + 'description' => 'Set permissions for all roles not specifically overridden.' + ]); + } + /** * {@inheritdoc} */ diff --git a/app/Entities/Models/Entity.php b/app/Entities/Models/Entity.php index 26a52073e..3528eaf2b 100644 --- a/app/Entities/Models/Entity.php +++ b/app/Entities/Models/Entity.php @@ -184,8 +184,10 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable */ public function hasRestriction(int $role_id, string $action): bool { - return $this->permissions()->where('role_id', '=', $role_id) - ->where('action', '=', $action)->count() > 0; + return $this->permissions() + ->where('role_id', '=', $role_id) + ->where('action', '=', $action) + ->count() > 0; } /** diff --git a/resources/icons/groups.svg b/resources/icons/groups.svg new file mode 100644 index 000000000..c99a6b503 --- /dev/null +++ b/resources/icons/groups.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/js/components/entity-permissions.js b/resources/js/components/entity-permissions.js new file mode 100644 index 000000000..8b57d3376 --- /dev/null +++ b/resources/js/components/entity-permissions.js @@ -0,0 +1,24 @@ + + +class EntityPermissions { + + setup() { + this.everyoneInheritToggle = this.$refs.everyoneInherit; + + this.setupListeners(); + } + + setupListeners() { + this.everyoneInheritToggle.addEventListener('change', event => { + const inherit = event.target.checked; + const permissions = document.querySelectorAll('input[type="checkbox"][name^="restrictions[0]["]'); + for (const permission of permissions) { + permission.disabled = inherit; + permission.checked = false; + } + }) + } + +} + +export default EntityPermissions; \ No newline at end of file diff --git a/resources/js/components/index.js b/resources/js/components/index.js index 4b17dc403..7d00cb671 100644 --- a/resources/js/components/index.js +++ b/resources/js/components/index.js @@ -18,6 +18,7 @@ import dropdown from "./dropdown.js" import dropdownSearch from "./dropdown-search.js" import dropzone from "./dropzone.js" import editorToolbox from "./editor-toolbox.js" +import entityPermissions from "./entity-permissions"; import entitySearch from "./entity-search.js" import entitySelector from "./entity-selector.js" import entitySelectorPopup from "./entity-selector-popup.js" @@ -74,6 +75,7 @@ const componentMapping = { "dropdown-search": dropdownSearch, "dropzone": dropzone, "editor-toolbox": editorToolbox, + "entity-permissions": entityPermissions, "entity-search": entitySearch, "entity-selector": entitySelector, "entity-selector-popup": entitySelectorPopup, diff --git a/resources/sass/_components.scss b/resources/sass/_components.scss index 9f737f3be..d0aadce6e 100644 --- a/resources/sass/_components.scss +++ b/resources/sass/_components.scss @@ -824,9 +824,6 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { .content-permissions-row:hover .content-permissions-row-toggle-all { visibility: visible; } -.content-permissions-row-label { - font-weight: bold; -} .template-item { cursor: pointer; diff --git a/resources/sass/_forms.scss b/resources/sass/_forms.scss index 7025aa898..5c1c8b2e8 100644 --- a/resources/sass/_forms.scss +++ b/resources/sass/_forms.scss @@ -266,6 +266,15 @@ input[type=color] { background-color: rgba(0, 0, 0, 0.05); opacity: 0.8; } + input[type=checkbox][disabled] ~ * { + opacity: 0.8; + cursor: not-allowed; + } + input[type=checkbox][disabled] ~ .custom-checkbox { + border-color: #999; + color: #999 !important; + background: #f2f2f2; + } } .toggle-switch-list { .toggle-switch { diff --git a/resources/views/form/custom-checkbox.blade.php b/resources/views/form/custom-checkbox.blade.php index 2bf4e2232..de3ffe922 100644 --- a/resources/views/form/custom-checkbox.blade.php +++ b/resources/views/form/custom-checkbox.blade.php @@ -5,7 +5,7 @@ $checked $label --}}