Class: SuperAuth::Edge

Inherits:
Object
  • Object
show all
Defined in:
lib/super_auth/edge.rb

Class Method Summary collapse

Class Method Details

.authorizationsObject



10
11
12
13
14
15
# File 'lib/super_auth/edge.rb', line 10

def authorizations
  users_groups_roles_permissions_resources
    .union(users_roles_permissions_resources)
    .union(users_groups_permissions_resources)
    .union(users_permissions_resources)
end

.users_groups_permissions_resourcesObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/super_auth/edge.rb', line 90

def users_groups_permissions_resources
  SuperAuth::User.
    join(Sequel[:super_auth_edges].as(:user_edges), user_id: :id).
    join(SuperAuth::Group.from(SuperAuth::Group.trees).as(:groups), id: :group_id).
    select(
      Sequel[:super_auth_users][:id].as(:user_id),
      Sequel[:super_auth_users][:name].as(:user_name),
      Sequel[:super_auth_users][:external_id].as(:user_external_id),
      Sequel[:super_auth_users][:created_at].cast(:text).as(:user_created_at),
      Sequel[:super_auth_users][:updated_at].cast(:text).as(:user_updated_at),

      Sequel[:groups][:id].as(:group_id),
      Sequel[:groups][:name].as(:group_name),
      Sequel[:groups][:group_path],
      Sequel[:groups][:group_name_path],
      Sequel[:groups][:parent_id].as(:group_parent_id),
      Sequel[:groups][:created_at].cast(:text).as(:group_created_at),
      Sequel[:groups][:updated_at].cast(:text).as(:group_updated_at),

      Sequel.lit(%[0 as "role_id"]),          # Sequel[:roles][:id].as(:role_id),
      Sequel::NULL.as(:role_name),            # Sequel[:roles][:name].as(:role_name),
      Sequel::NULL.as(:role_path),            # Sequel[:roles][:role_path],
      Sequel::NULL.as(:role_name_path),       # Sequel[:roles][:role_name_path].as(:role_name_path),
      Sequel::lit(%Q[0 as "role_parent_id"]), # Sequel[:roles][:parent_id].as(:role_parent_id),
      Sequel::NULL.as(:role_created_at),      # Sequel[:roles][:created_at].as(:role_created_at),
      Sequel::NULL.as(:role_updated_at),      # Sequel[:roles][:updated_at].as(:role_updated_at),

      Sequel[:super_auth_permissions][:id].as(:permission_id),
      Sequel[:super_auth_permissions][:name].as(:permission_name),
      Sequel[:super_auth_permissions][:created_at].cast(:text).as(:permission_created_at),
      Sequel[:super_auth_permissions][:updated_at].cast(:text).as(:permission_updated_at),

      Sequel[:super_auth_resources][:id].as(:resource_id),
      Sequel[:super_auth_resources][:name].as(:resource_name),
      Sequel[:super_auth_resources][:external_id].as(:resource_external_id),
    ).
    join(Sequel[:super_auth_edges].as(:permission_edges), Sequel[:permission_edges][:group_id] => Sequel[:groups][:id]).
    join(Sequel[:super_auth_permissions], id: Sequel[:permission_edges][:permission_id]).
    join(Sequel[:super_auth_edges].as(:resource_edges), Sequel[:resource_edges][:permission_id] => Sequel[:super_auth_permissions][:id]).
    join(Sequel[:super_auth_resources], id: Sequel[:resource_edges][:resource_id]).
    distinct
end

.users_groups_roles_permissions_resourcesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/super_auth/edge.rb', line 17

def users_groups_roles_permissions_resources
  users_groups_roles_ds = SuperAuth::User.join(:super_auth_edges, user_id: :id).select_all(:super_auth_users).join(SuperAuth::Group.from(SuperAuth::Group.trees).as(:groups), id: :group_id).select(
    Sequel[:super_auth_users][:id].as(:user_id),
    Sequel[:super_auth_users][:name].as(:user_name),
    Sequel[:super_auth_users][:external_id].as(:user_external_id),
    Sequel[:super_auth_users][:created_at].as(:user_created_at),
    Sequel[:super_auth_users][:updated_at].as(:user_updated_at),
    Sequel[:groups][:id].as(:group_id),
    Sequel[:groups][:name].as(:group_name),
    Sequel[:super_auth_edges][:id].as(:edge_id),
    Sequel[:super_auth_edges][:permission_id].as(:edge_permission_id),
    Sequel[:super_auth_edges][:group_id].as(:edge_group_id),
    Sequel[:super_auth_edges][:user_id].as(:edge_user_id),
    Sequel[:super_auth_edges][:role_id].as(:edge_role_id),
    Sequel[:groups][:group_path],
    Sequel[:groups][:group_name_path],
    Sequel[:groups][:parent_id],
    Sequel[:groups][:created_at].as(:group_created_at),
    Sequel[:groups][:updated_at].as(:group_updated_at),
  ).join(Sequel[:super_auth_edges].as(:group_role_edges), Sequel[:group_role_edges][:group_id] => Sequel[:groups][:id]).select_append(
    Sequel[:group_role_edges][:id].as(:group_role_edge_id),
    Sequel[:group_role_edges][:permission_id].as(:group_role_edge_permission_id),
    Sequel[:group_role_edges][:group_id].as(:group_role_edge_group_id),
    Sequel[:group_role_edges][:user_id].as(:group_role_edge_user_id),
    Sequel[:group_role_edges][:role_id].as(:group_role_edge_role_id),
  ).join(:super_auth_roles, id: Sequel[:group_role_edges][:role_id])

  SuperAuth::Edge.from(
    SuperAuth::Edge.from(
      SuperAuth::Group.cte(SuperAuth::Group.where(id: users_groups_roles_ds.select(Sequel[:groups][:id])).select(:id)).select { [id.as(:group_id), name.as(:group_name), parent_id.as(:group_parent_id), group_path, group_name_path, created_at.as(:group_created_at), updated_at.as(:group_updated_at)] },
      SuperAuth::Role.cte(users_groups_roles_ds.select(Sequel[:group_role_edges][:role_id])).select { [id.as(:role_id), name.as(:role_name), parent_id.as(:role_parent_id), role_path, role_name_path, created_at.as(:role_created_at), updated_at.as(:role_updated_at) ] }
    ).as(:users_groups_roles_permissions_resources)
  ).join(Sequel[:super_auth_edges].as(:user_edges), Sequel[:user_edges][:group_id] => Sequel[:users_groups_roles_permissions_resources][:group_id])
   .join(Sequel[:super_auth_users], id: Sequel[:user_edges][:user_id])
   .select(
      Sequel[:super_auth_users][:id].as(:user_id),
      Sequel[:super_auth_users][:name].as(:user_name),
      Sequel[:super_auth_users][:external_id].as(:user_external_id),
      Sequel[:super_auth_users][:created_at].cast(:text).as(:user_created_at),
      Sequel[:super_auth_users][:updated_at].cast(:text).as(:user_updated_at),

      Sequel[:users_groups_roles_permissions_resources][:group_id],
      Sequel[:users_groups_roles_permissions_resources][:group_name],
      Sequel[:users_groups_roles_permissions_resources][:group_path],
      Sequel[:users_groups_roles_permissions_resources][:group_name_path],
      Sequel[:users_groups_roles_permissions_resources][:group_parent_id],
      Sequel[:users_groups_roles_permissions_resources][:group_created_at].cast(:text),
      Sequel[:users_groups_roles_permissions_resources][:group_updated_at].cast(:text),

      Sequel[:users_groups_roles_permissions_resources][:role_id],
      Sequel[:users_groups_roles_permissions_resources][:role_name],
      Sequel[:users_groups_roles_permissions_resources][:role_path],
      Sequel[:users_groups_roles_permissions_resources][:role_name_path],
      Sequel[:users_groups_roles_permissions_resources][:role_parent_id],
      Sequel[:users_groups_roles_permissions_resources][:role_created_at].cast(:text),
      Sequel[:users_groups_roles_permissions_resources][:role_updated_at].cast(:text),

      Sequel[:super_auth_permissions][:id].as(:permission_id),
      Sequel[:super_auth_permissions][:name].as(:permission_name),
      Sequel[:super_auth_permissions][:created_at].cast(:text).as(:permission_created_at),
      Sequel[:super_auth_permissions][:updated_at].cast(:text).as(:permission_updated_at),

      Sequel[:super_auth_resources][:id].as(:resource_id),
      Sequel[:super_auth_resources][:name].as(:resource_name),
      Sequel[:super_auth_resources][:external_id].as(:resource_external_id)
    )
   .join(Sequel[:super_auth_edges].as(:permission_edges), Sequel[:permission_edges][:role_id] => Sequel[:users_groups_roles_permissions_resources][:role_id])
   .join(Sequel[:super_auth_permissions], id: Sequel[:permission_edges][:permission_id])
   .join(Sequel[:super_auth_edges].as(:resource_edges), Sequel[:resource_edges][:permission_id] => Sequel[:permission_edges][:permission_id])
   .join(Sequel[:super_auth_resources], id: Sequel[:resource_edges][:resource_id])
   .distinct
end

.users_permissions_resourcesObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/super_auth/edge.rb', line 176

def users_permissions_resources
  SuperAuth::User.
    join(Sequel[:super_auth_edges].as(:user_edges), user_id: :id).
    select(
      Sequel[:super_auth_users][:id].as(:user_id),
      Sequel[:super_auth_users][:name].as(:user_name),
      Sequel[:super_auth_users][:external_id].as(:user_external_id),
      Sequel[:super_auth_users][:created_at].cast(:text).as(:user_created_at),
      Sequel[:super_auth_users][:updated_at].cast(:text).as(:user_updated_at),

      Sequel.lit(%Q[0 as "group_id"]),      # Sequel[:groups][:group_id],
      Sequel::NULL.as(:group_name),       # Sequel[:groups][:group_name],
      Sequel::NULL.as(:group_path),       # Sequel[:groups][:group_path],
      Sequel::NULL.as(:group_name_path),  # Sequel[:groups][:group_name_path],
      Sequel.lit(%Q[0 as "group_parent_id"]),      # Sequel[:groups][:group_id],
      Sequel.lit(%Q['1970-01-01 00:00:00.000000-00' as "group_created_at"]), # Sequel[:groups][:group_created_at],
      Sequel.lit(%Q['1970-01-01 00:00:00.000000-00' as "group_updated_at"]), # Sequel[:groups][:group_updated_at],


      Sequel.lit(%Q[0 as "role_id"]),        # Sequel[:roles][:role_id],
      Sequel::NULL.as(:role_name),           # Sequel[:roles][:role_name],
      Sequel::NULL.as(:role_path),           # Sequel[:roles][:role_path],
      Sequel::NULL.as(:role_name_path),      # Sequel[:roles][:role_name_path],
      Sequel.lit(%Q[0 as "role_parent_id"]), # Sequel[:roles][:role_parent_id],
      Sequel::NULL.as(:role_created_at),     # Sequel[:roles][:role_created_at],
      Sequel::NULL.as(:role_updated_at),     # Sequel[:roles][:role_updated_at],

      Sequel[:super_auth_permissions][:id].as(:permission_id),
      Sequel[:super_auth_permissions][:name].as(:permission_name),
      Sequel[:super_auth_permissions][:created_at].cast(:text).as(:permission_created_at),
      Sequel[:super_auth_permissions][:updated_at].cast(:text).as(:permission_updated_at),

      Sequel[:super_auth_resources][:id].as(:resource_id),
      Sequel[:super_auth_resources][:name].as(:resource_name),
      Sequel[:super_auth_resources][:external_id].as(:resource_external_id)
    ).
  join(Sequel[:super_auth_edges].as(:permission_edges), Sequel[:permission_edges][:user_id] => Sequel[:super_auth_users][:id]).
  join(Sequel[:super_auth_permissions], id: Sequel[:permission_edges][:permission_id]).
  join(Sequel[:super_auth_edges].as(:resource_edges), Sequel[:resource_edges][:permission_id] => Sequel[:super_auth_permissions][:id]).
  join(Sequel[:super_auth_resources], id: Sequel[:resource_edges][:resource_id]).
  distinct
end

.users_roles_permissions_resourcesObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/super_auth/edge.rb', line 133

def users_roles_permissions_resources
  SuperAuth::User.
    join(Sequel[:super_auth_edges].as(:user_edges), user_id: :id).
    join(SuperAuth::Role.from(SuperAuth::Role.trees).as(:roles), id: :role_id).
    select(
      Sequel[:super_auth_users][:id].as(:user_id),
      Sequel[:super_auth_users][:name].as(:user_name),
      Sequel[:super_auth_users][:external_id].as(:user_external_id),
      Sequel[:super_auth_users][:created_at].cast(:text).as(:user_created_at),
      Sequel[:super_auth_users][:updated_at].cast(:text).as(:user_updated_at),

      Sequel.lit(%Q[0 as "group_id"]),                                       # Sequel[:super_auth_groups][:group_id],
      Sequel::NULL.as(:group_name),                                          # Sequel[:super_auth_groups][:group_name],
      Sequel::NULL.as(:group_path),                                          # Sequel[:super_auth_groups][:group_path],
      Sequel::NULL.as(:group_name_path),                                     # Sequel[:super_auth_groups][:group_name_path],
      Sequel.lit(%Q[0 as "group_parent_id"]),                                # Sequel[:super_auth_groups][:group_parent_id],
      Sequel.lit(%Q['1970-01-01 00:00:00.000000-00' as "group_created_at"]), # Sequel[:super_auth_groups][:group_created_at],
      Sequel.lit(%Q['1970-01-01 00:00:00.000000-00' as "group_updated_at"]), # Sequel[:super_auth_groups][:group_updated_at],

      Sequel[:roles][:id].as(:role_id),
      Sequel[:roles][:name].as(:role_name),
      Sequel[:roles][:role_path],
      Sequel[:roles][:role_name_path].as(:role_name_path),
      Sequel[:roles][:parent_id].as(:role_parent_id),
      Sequel[:roles][:created_at].cast(:text).as(:role_created_at),
      Sequel[:roles][:updated_at].cast(:text).as(:role_updated_at),

      Sequel[:super_auth_permissions][:id].as(:permission_id),
      Sequel[:super_auth_permissions][:name].as(:permission_name),
      Sequel[:super_auth_permissions][:created_at].cast(:text).as(:permission_created_at),
      Sequel[:super_auth_permissions][:updated_at].cast(:text).as(:permission_updated_at),

      Sequel[:super_auth_resources][:id].as(:resource_id),
      Sequel[:super_auth_resources][:name].as(:resource_name),
      Sequel[:super_auth_resources][:external_id].as(:resource_external_id),
  ).
  join(Sequel[:super_auth_edges].as(:permission_edges), Sequel[:permission_edges][:role_id] => Sequel[:roles][:id]).
  join(Sequel[:super_auth_permissions], id: Sequel[:permission_edges][:permission_id]).
  join(Sequel[:super_auth_edges].as(:resource_edges), Sequel[:resource_edges][:permission_id] => Sequel[:super_auth_permissions][:id]).
  join(Sequel[:super_auth_resources], id: Sequel[:resource_edges][:resource_id]).
  distinct
end