Module: Zena::Use::VersionHash::ModelMethods
- Included in:
- Node
- Defined in:
- lib/zena/use/version_hash.rb
Instance Method Summary collapse
- #rebuild_vhash ⇒ Object
-
#v_public? ⇒ Boolean
Return true if the current version can be seen by the public.
- #version(lang = nil) ⇒ Object
- #version_id(lang = nil, ugps = visitor.group_ids) ⇒ Object
- #vhash ⇒ Object
-
#visible_versions ⇒ Object
Return the list of versions that are stored in the vhash and could be loaded depending on the visitor.
Instance Method Details
#rebuild_vhash ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/zena/use/version_hash.rb', line 100 def rebuild_vhash cached = VersionHash.cached_values_from_records(connection.select_all("SELECT id,lang,status,publish_from FROM #{Version.table_name} WHERE node_id = #{self.id} ORDER BY lang ASC, status DESC", "Version Load")) # We also rebuild publish_from here: yes, that's a leak with Workflow. self[:publish_from] = cached[:publish_from] self[:vhash] = cached[:vhash].to_json @vhash = cached[:vhash] end |
#v_public? ⇒ Boolean
Return true if the current version can be seen by the public.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/zena/use/version_hash.rb', line 72 def v_public? visitor.is_anon? || begin anon = visitor.site.anon # visible by anonymous can_read?(anon, anon.group_ids) && # anonymous would see this exact version version.id == version_id(visitor.lang, visitor.site.anon.group_ids) end end |
#version(lang = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zena/use/version_hash.rb', line 53 def version(lang = nil) @version ||= begin if v_id = version_id(lang) version = ::Version.find(v_id) else version = ::Version.new end version.node = self version end end |
#version_id(lang = nil, ugps = visitor.group_ids) ⇒ Object
65 66 67 68 69 |
# File 'lib/zena/use/version_hash.rb', line 65 def version_id(lang = nil, ugps = visitor.group_ids) lang ||= visitor.lang access = can_see_redactions?(ugps) ? vhash['w'] : vhash['r'] access[lang] || access[self[:ref_lang]] || access.values.first end |
#vhash ⇒ Object
96 97 98 |
# File 'lib/zena/use/version_hash.rb', line 96 def vhash @vhash ||= JSON.parse(self[:vhash] || '{"r":{}, "w":{}}') end |
#visible_versions ⇒ Object
Return the list of versions that are stored in the vhash and could be loaded depending on the visitor.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/zena/use/version_hash.rb', line 85 def visible_versions @visible_versions ||= begin ids = (vhash['w'].values + vhash['r'].values).uniq ::Version.find(ids).tap do |list| list.each do |version| version.node = self end end end end |