docs/RoleManagement.md in cm-admin-2.1.4 vs docs/RoleManagement.md in cm-admin-2.1.5

- old
+ new

@@ -60,10 +60,25 @@ 3. Add `belongs_to :cm_role, optional: true` in the `User` model. 4. Include `CmRole` in the `config.included_models` section of `config/initializers/zcm_admin.rb`. 5. Assign `cm_role_id` to `1` for any user in the `User` Model, and use that user to log in. +## Setting up scopes + +By default, `Full Access` scopes is added to each permission item. To add additional scopes, use the following syntax: + +```ruby +... +cm_admin do + actions only: [] + set_icon "fa fa-user" + set_policy_scopes [{scope_name: 'test_supplier_filter', display_name: 'By Test Supplier'}] + cm_index do + page_title 'User' + end +end + ## Overriding Policies By default, roles and policies are enabled for all models in the application. To override a policy, use the following syntax: ```ruby @@ -88,5 +103,26 @@ # Add other actions here end ``` This structure helps ensure that your application's role and permission management is both flexible and secure. + + +## Permission based fields + +We can apply permission logic to display a field on the interface. You can do this with the following syntax. + +```ruby +... +tab :details, '' do + row do + cm_show_section 'Details' do + field :status, field_type: :tag, tag_class: Item::STATUS_TAG_COLOR, display_if: -> (record) { + scoped_model = CmAdmin::ItemPolicy::ArchiveScope.new(Current.user, ::Item).resolve + return scoped_model.find_by(id: record.id).present? + } + end + end +end + +``` +