where("(#{self.table_name}.id in (?)) or (#{self.table_name}.path like ?) or (#{self.table_name}.path rlike ?)",department.path.to_s.split('/').map(&:to_i),"%/#{department.id}/%","\/#{department.id}$")
acts_as_listscope: '#{parent_id.present? ? %Q{parent_id = #{parent_id}} : %q{parent_id is null}} and #{organization_id.present? ? %Q{organization_id = #{organization_id}} : %q{organization_id is null}} and deleted_at is null',add_new_at: :bottom
joins("join grants on grants.subject_id = announcements.id and grants.subject_type = 'Announcement'").
where("(grants.grantee_type = 'Department' and grants.grantee_id in (:department_id)) or (grants.grantee_type = 'Role' and grants.grantee_id in (:role_id)) or (grants.grantee_type = 'Organization' and grants.grantee_id = :organization_id)",department_id: all_joined_department_ids,role_id: role.try(:id),organization_id: organization_id)