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
Class Method Details
.extended(base) ⇒ Object
46 47 48 49 50 51 52 53 |
# 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 base.class_eval do scope :with_permission, lambda { |user, | select("#{table_name}.*").where((user, )) } end 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/joinable/acts_as_joinable_component.rb', line 65 def (user, , = {}) = .to_s case user when String user_id = user else user_id = user.id end component_type = [:type_column] || name component_id = [:id_column] || table_name + ".id" = .gsub('join_and_', '') = == 'view' ? "permission_links.component_view_permission" : "'#{}'" if .starts_with?('view') "#{(component_type, component_id)} OR #{(user_id, component_type, component_id, )} OR #{(component_type, component_id, )}" elsif .starts_with?('join_and_') (component_type, component_id, ) else "#{(component_type, component_id)} OR #{(user_id, component_type, component_id, )}" end end |