docbrown/app/queries/admin/users_query.rb
dependabot[bot] 816855ce3b
Bump rubocop from 1.17.0 to 1.18.0 (#14107)
* Bump rubocop from 1.17.0 to 1.18.0

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.17.0 to 1.18.0.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.17.0...v1.18.0)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* yarn install

* Fix violations

* Restore the default aligned setting

* Trigger Travis CI

* Escape HTML

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: rhymes <github@rhymes.dev>
2021-07-01 13:51:49 +02:00

22 lines
750 B
Ruby

module Admin
class UsersQuery
QUERY_CLAUSE = "users.name ILIKE :search OR " \
"users.username ILIKE :search OR " \
"users.github_username ILIKE :search OR " \
"users.email ILIKE :search OR " \
"users.twitter_username ILIKE :search".freeze
def self.call(relation: User.registered, options: {})
role, search = options.values_at(:role, :search)
relation = relation.with_role(role, :any) if role.presence
relation = search_relation(relation, search) if search.presence
relation.order(created_at: :desc)
end
def self.search_relation(relation, search)
relation.where(QUERY_CLAUSE, search: "%#{search.strip}%")
end
end
end