Class: LcpRuby::Presenter::ColumnSet
- Inherits:
-
Object
- Object
- LcpRuby::Presenter::ColumnSet
- Includes:
- MetadataLookup
- Defined in:
- lib/lcp_ruby/presenter/column_set.rb
Instance Attribute Summary collapse
-
#permission_evaluator ⇒ Object
readonly
Returns the value of attribute permission_evaluator.
-
#presenter_definition ⇒ Object
readonly
Returns the value of attribute presenter_definition.
Instance Method Summary collapse
-
#fk_association_map(model_definition) ⇒ Object
Build a mapping from FK field name to the belongs_to AssociationDefinition, filtered to only include FK fields the current user has permission to see.
-
#initialize(presenter_definition, permission_evaluator) ⇒ ColumnSet
constructor
A new instance of ColumnSet.
-
#readable_named_slot?(field_name) ⇒ Boolean
Returns true when the current user can read the named-slot field.
-
#visible_card_fields(card_config) ⇒ Object
Filter card fields by readable permissions.
- #visible_form_fields(section_fields) ⇒ Object
- #visible_show_fields(section_fields) ⇒ Object
- #visible_table_columns ⇒ Object
Constructor Details
#initialize(presenter_definition, permission_evaluator) ⇒ ColumnSet
Returns a new instance of ColumnSet.
8 9 10 11 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 8 def initialize(presenter_definition, ) @presenter_definition = presenter_definition @permission_evaluator = end |
Instance Attribute Details
#permission_evaluator ⇒ Object (readonly)
Returns the value of attribute permission_evaluator.
6 7 8 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 6 def @permission_evaluator end |
#presenter_definition ⇒ Object (readonly)
Returns the value of attribute presenter_definition.
6 7 8 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 6 def presenter_definition @presenter_definition end |
Instance Method Details
#fk_association_map(model_definition) ⇒ Object
Build a mapping from FK field name to the belongs_to AssociationDefinition, filtered to only include FK fields the current user has permission to see. Returns a Hash: { “company_id” => AssociationDefinition, … } Used by the index view to resolve associated objects instead of showing raw FK integers.
69 70 71 72 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 69 def fk_association_map(model_definition) visible_fields = visible_table_columns.map { |c| c["field"] } model_definition.belongs_to_fk_map.select { |k, _| visible_fields.include?(k) } end |
#readable_named_slot?(field_name) ⇒ Boolean
Returns true when the current user can read the named-slot field. Field-level permissions in LCP are model+role+field scoped (class-level), so the check needs no record. Per-record visibility is already handled by policy_scope before any card is rendered. Dot-paths and template strings are skipped here —the resolver enforces field_readable? at every traversal step.
57 58 59 60 61 62 63 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 57 def readable_named_slot?(field_name) return true if field_name.blank? return true if FieldValueResolver.dot_path?(field_name) || FieldValueResolver.template_field?(field_name) .field_readable?(field_name.to_s) end |
#visible_card_fields(card_config) ⇒ Object
Filter card fields by readable permissions. Returns array of field config hashes. Used by all card-based layouts (tiles, kanban, future).
43 44 45 46 47 48 49 50 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 43 def visible_card_fields(card_config) readable = .readable_fields fields = card_config["fields"] || [] fields.select do |field_config| field_visible?(field_config["field"], readable) end end |
#visible_form_fields(section_fields) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 17 def visible_form_fields(section_fields) writable = .writable_fields section_fields.select do |field| if field["custom_field"] .field_writable?(field["field"]) else writable.include?(field["field"]) end end end |
#visible_show_fields(section_fields) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 29 def visible_show_fields(section_fields) readable = .readable_fields section_fields.select do |field| if field["custom_field"] .field_readable?(field["field"]) else field_visible?(field["field"], readable) end end end |
#visible_table_columns ⇒ Object
13 14 15 |
# File 'lib/lcp_ruby/presenter/column_set.rb', line 13 def visible_table_columns @visible_table_columns ||= compute_visible_table_columns end |