diff options
| author | Robert | 2017-07-03 08:27:45 +0200 | 
|---|---|---|
| committer | Robert | 2017-07-04 21:54:04 +0200 | 
| commit | 747d333ffbcc8ee0c9f1daf93ccca32799434e04 (patch) | |
| tree | d475ba66bd6893bac155ddd781f009c74178c10d /app/policies/application_policy.rb | |
| parent | ebd292c7a6abaab5aeb90b37e34e21253184979f (diff) | |
| download | chouette-core-747d333ffbcc8ee0c9f1daf93ccca32799434e04.tar.bz2 | |
Refs: #3478@2h  Access correct referential in line_footnotes Ctrl
  + ApplicationController provides Pundit's UserContext's referential with `@referential` instead of `current_referential`,
    (`@referential` is computed from the URL,  while `current_referential` was aliased to different methods, **not always**
     pointing to `Referential` instances)
  + ApplicationPolicy uses the record's referential in its `referential method` iff it is an instance of `Referential` else
    it uses the abovely provided referential, locally named `@current_referential` (as it should be named in the Ctrl too)
    This assures, in combination with the Ctrl Change, that `referential` **always** returns an instance of `Referential`!
  - TODO: Review my understanding of _Referential Setup_ inside the Ctrls
Diffstat (limited to 'app/policies/application_policy.rb')
| -rw-r--r-- | app/policies/application_policy.rb | 23 | 
1 files changed, 17 insertions, 6 deletions
diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index a863404ae..f2521fa44 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -1,18 +1,19 @@  class ApplicationPolicy -  attr_reader :user, :record +  attr_reader :current_referential, :record, :user    def initialize(user_context, record) -    @user = user_context.user -    @referential = user_context.context[:referential] -    @record = record +    @user                = user_context.user +    @current_referential = user_context.context[:referential] +    @record              = record    end    def archived? -    !!referential.try(:archived_at) +    return @is_archived if instance_variable_defined?(:@is_archived) +    @is_archived = is_archived    end    def referential -    @referential ||= record_referential +    @referential ||=  current_referential || record_referential    end    def record_referential @@ -77,4 +78,14 @@ class ApplicationPolicy        scope      end    end + +  private +  def is_archived +    !!case referential +    when Referential +      referential.archived_at +    else +      current_referential.try(:archived_at) +    end +  end  end  | 
