Module: Joinable::ActsAsJoinableComponent::ClassMethods
- Defined in:
- lib/joinable/acts_as_joinable_component.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#with_permission_sql(user, permission, options = {}) ⇒ Object
Returns the SQL necessary to find all components for which there is no associated joinable or the user has a membership with a specific permission.
Methods included from Joinable::ActsAsPermissable::ClassMethods
#find_with_privacy, #permission_sql_condition, #with_permission
Class Method Details
.extended(base) ⇒ Object
46 47 48 49 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 46 def self.extended(base) base.has_one :permission_link, :as => :component, :dependent => :destroy base.after_create :find_joinable_and_create_permission_link end |
Instance Method Details
#with_permission_sql(user, permission, options = {}) ⇒ Object
Returns the SQL necessary to find all components for which there is no associated joinable or the user has a membership with a specific permission.
Permissions which require special handling:
-
view_* - This is a class of permissions that start with the word ‘view’. When determining if a user can view any aspect of a joinable, we also check
if the project is open.
-
join_and_* - This is a class of permissions that start with the words ‘join_and_’. When determining if a user will have a certain permission
after they join a project, we need to check the default_permission_set of the project.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 61 def (user, , = {}) = .to_s case user when String user_id = user else user_id = user.id end component_id_column = [:id_column] || "#{table_name}.id" = .gsub('join_and_', '') = == 'view' ? "permission_links.component_view_permission" : "'#{}'" if .starts_with?('view') "#{(component_id_column)} OR #{(user_id, component_id_column, )} OR #{(component_id_column, )}" elsif .starts_with?('join_and_') (component_id_column, ) else "#{(component_id_column)} OR #{(user_id, component_id_column, )}" end end |