Skip to content

Commit

Permalink
[MNOE-932] OrganizationsController: Added checks to properly forward …
Browse files Browse the repository at this point in the history
…filters for demo and frozen orgs
  • Loading branch information
MAhsenArif committed Mar 22, 2018
1 parent 94475d9 commit f9641a0
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ def index
if params[:terms]
# Search mode
@organizations = []
JSON.parse(params[:terms]).map { |t| @organizations = @organizations | MnoEnterprise::Organization.where(Hash[*t]).fetch }
terms = JSON.parse(params[:terms])
terms.map { |t| @organizations = @organizations | MnoEnterprise::Organization.where(Hash[*t]).fetch }
filters = terms['listing_filters']
if filters
@organizations.reject! { |x| x.account_frozen? } if filters && filters.dig('account_frozen') == 'true'
@organizations.reject! { |x| x.demo_account? } if filters && filters.dig('demo_account') == 'true'
end
response.headers['X-Total-Count'] = @organizations.count
else
# Index mode
@organizations = MnoEnterprise::Organization
@organizations = @organizations.limit(params[:limit]) if params[:limit]
@organizations = @organizations.skip(params[:offset]) if params[:offset]
@organizations = @organizations.order_by(params[:order_by]) if params[:order_by]
@organizations = @organizations.where(params[:where]) if params[:where]
if params[:where]
hash_filter = params[:where].is_a?(String) ? JSON.parse(params[:where]) : params[:where]
@organizations = @organizations.where(hash_filter)
end
@organizations = @organizations.all.fetch
response.headers['X-Total-Count'] = @organizations.metadata[:pagination][:count]
end
Expand Down

0 comments on commit f9641a0

Please sign in to comment.