Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module HtwMembershipHandshake
- module ProjectModelPatch
- def self.included(base) # :nodoc:
- base.include InstanceMethods
- base.extend ClassMethods
- # wrapping methods and save attributes:
- base.class_eval do
- # unloadable
- has_many :waiting_members, -> { where "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}" },-> { includes [:user, :roles] }
- #has_many :waiting_member_principals, :class_name => 'WaitingMember', :include => :principal, :conditions => "#{Principal.table_name}.type'Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})"
- #TODO FIX conditions
- has_many :waiting_member_principals,-> { where "#{Principal.table_name}.type'Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})" } ,-> { includes :user }, :class_name => 'WaitingMember'
- before_destroy :delete_all_waiting_members
- end #of class_eval
- end #of self.included
- module ClassMethods
- def plugin_htw_membership_handshake
- puts "Plugin HTW Berlin active\n"
- nil
- end
- end #end of ClassMethods
- module InstanceMethods
- # Deletes all project's waiting members
- def delete_all_waiting_members
- me = WaitingMember.table_name
- mr = WaitingMemberRole.table_name
- connection.delete("DELETE FROM #{mr} WHERE #{mr}.waiting_member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
- WaitingMember.delete_all(['project_id = ?', id])
- end
- end #end of module IM
- end # model patch
- end # module userlevel
- ActionDispatch::Callbacks.to_prepare do
- Project.include(HtwMembershipHandshake::ProjectModelPatch)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement