Module: Joinable::ActsAsJoinableComponent::InstanceMethods
- Defined in:
- lib/joinable/acts_as_joinable_component.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #acts_like_joinable_component? ⇒ Boolean
- #check_permission(user, permission) ⇒ Object
-
#inherited_view_permission ⇒ Object
inherited_view_permission is calculated by ascending up the chain of joinable components while view permission only takes into account the current joinable component.
-
#joinable ⇒ Object
Returns the object that we should inherit permissions from.
-
#who_will_be_able_to_view? ⇒ Boolean
Used by unsaved joinable_components to return a list of users who will be able to view the component once it is saved.
Methods included from Joinable::ActsAsPermissable::InstanceMethods
#acts_like_permissable?, #who_can?
Instance Attribute Details
#view_permission ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 185 def = self.class. = .call(self) if .respond_to?(:call) # Allow view_permission to be set at the instance level return @view_permission || end |
Instance Method Details
#acts_like_joinable_component? ⇒ Boolean
121 122 123 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 121 def acts_like_joinable_component? true end |
#check_permission(user, permission) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 135 def (user, ) # You can't ask to join joinable_components so the find permission is actually the view permission = :view if == :find if new_record? if joinable.acts_like?(:joinable) = if == :view joinable.(user, ) else # The component isn't contained by a joinable so it is public. true end else self.class.(user, ).exists?(id) end end |
#inherited_view_permission ⇒ Object
inherited_view_permission is calculated by ascending up the chain of joinable components while view permission only takes into account the current joinable component. inherited_view_permission is for external use while view_permission should only be used internally.
181 182 183 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 181 def .try(:component_view_permission) end |
#joinable ⇒ Object
Returns the object that we should inherit permissions from
Recurses until the target is reached, if we reach a target that does not act as a joinable, call method again if it is a joinable component, else fall out as the chain has no valid endpoint (eg. feed -> discussion -> item)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 157 def joinable if .present? .joinable else parent = next_link # Our target is now joinable therefore our target is at the end (eg. feed -> discussion -> [project]) if parent && parent.acts_like?(:joinable) return parent # Our target is a joinable_component therefore our target somewhere between the beginning and the end (eg. feed -> [discussion] -> ??? -> project) elsif parent && parent.acts_like?(:joinable_component) return parent.joinable # We've fallen out because there was either no target or the target was not joinable or a joinable_component else return parent end end end |
#who_will_be_able_to_view? ⇒ Boolean
Used by unsaved joinable_components to return a list of users who will be able to view the component once it is saved. Useful for outputting information to the user while they are creating a new component.
129 130 131 132 133 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 129 def who_will_be_able_to_view? User.joins(:memberships) .where(:memberships => {:joinable => joinable}) .where(('memberships.permissions', )) end |