6772312ea7
The primary license of the project is changing to: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later with some specific files to be licensed under the one of two licenses: CC0-1.0 LGPL-3.0-or-later This commit is one of the many steps to relicense the entire codebase. Documentation granting permission for this relicensing (from all past contributors who hold copyrights) is on file with Software Freedom Conservancy, Inc.
27 lines
957 B
Ruby
27 lines
957 B
Ruby
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
|
module QueryRoles
|
|
|
|
def self.user_has_role?(user_id, role_names, host_id=nil)
|
|
expr = Qx.select("COUNT(roles)").from(:roles)
|
|
.where("name IN ($names)", names: Array(role_names))
|
|
.and_where(user_id: user_id)
|
|
expr = expr.and_where(host_id: host_id) if host_id
|
|
return expr.execute.first['count'] > 0
|
|
end
|
|
|
|
# Get host tables -- host can be nonprofit, campaign, event
|
|
def self.host_ids(user_id, role_names)
|
|
Qx.select("host_id").from(:roles)
|
|
.where(user_id: user_id)
|
|
.and_where("roles.name IN ($names)", names: role_names)
|
|
.execute.map{|h| h['host_id']}
|
|
end
|
|
|
|
def self.is_nonprofit_user?(user_id, np_id)
|
|
user_has_role?(user_id, [:nonprofit_admin, :nonprofit_user], np_id)
|
|
end
|
|
|
|
def self.is_authorized_for_nonprofit?(user_id, np_id)
|
|
user_has_role?(user_id, [:super_admin]) || is_nonprofit_user?(user_id, np_id)
|
|
end
|
|
end
|