Module: JunglePath::SQL::UserRole

Defined in:
lib/jungle_path/sql/user_role.rb

Class Method Summary collapse

Class Method Details

.has_root_role_by_user_id(db, user_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jungle_path/sql/user_role.rb', line 6

def self.has_root_role_by_user_id(db, user_id)
  puts "has_root_role_by_user_id: #{user_id}."
  sql = JunglePath::SQL::Helpers.sql("
    select
      count(*)
    from \"user\" a
    join user_role b on b.user_id = a.id
    join role c on c.id = b.role_id
    where c.name = 'root'
    and a.id = ?
  ")
  count = JunglePath::SQL::Helpers.get_count(db, sql, user_id)
  puts "count: #{count}."
  puts "(count > 0): #{(count > 0)}."
  (count > 0)
end

.is_root_role_by_role_id(db, role_id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jungle_path/sql/user_role.rb', line 23

def self.is_root_role_by_role_id(db, role_id)
  puts "has_root_role_by_role_id: #{role_id}."
  sql = JunglePath::SQL::Helpers.sql("
    select
      count(*)
    from role a
    where a.name = 'root'
    and a.id = ?
  ")
  count = JunglePath::SQL::Helpers.get_count(db, sql, role_id)
  puts "count: #{count}."
  puts "(count > 0): #{(count > 0)}."
  (count > 0)
end