-
Notifications
You must be signed in to change notification settings - Fork 16
/
oso.rb
112 lines (104 loc) · 2.04 KB
/
oso.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require 'exceptions'
OSO = Oso::Oso.new not_found_error: Exceptions::NotFound, forbidden_error: Exceptions::Forbidden
Relation = Oso::Polar::DataFiltering::Relation
require 'oso/polar/data/adapter/active_record_adapter'
OSO.data_filtering_adapter = ::Oso::Polar::Data::Adapter::ActiveRecordAdapter.new
OSO.register_class(
User,
fields: {
email: String,
org_roles: Relation.new(
kind: 'many',
other_type: OrgRole,
my_field: 'id',
other_field: 'user_id'
),
repo_roles: Relation.new(
kind: 'many',
other_type: RepoRole,
my_field: 'id',
other_field: 'user_id'
)
}
)
OSO.register_class(
Org,
fields: {
name: String,
base_repo_role: String,
billing_address: String,
repos: Relation.new(
kind: 'many',
other_type: 'Repo',
my_field: 'id',
other_field: 'org_id',
)
}
)
OSO.register_class(
Repo,
fields: {
name: String,
org: Relation.new(
kind: 'one',
other_type: 'Org',
my_field: 'org_id',
other_field: 'id'
),
issues: Relation.new(
kind: 'many',
other_type: 'Issue',
my_field: 'id',
other_field: 'repo_id'
)
}
)
OSO.register_class(
Issue,
fields: {
title: String,
repo: Relation.new(
kind: 'one',
other_type: 'Repo',
my_field: 'repo_id',
other_field: 'id'
)
}
)
OSO.register_class(
OrgRole,
fields: {
name: String,
org: Relation.new(
kind: 'one',
other_type: 'Org',
my_field: 'org_id',
other_field: 'id'
),
user: Relation.new(
kind: 'one',
other_type: 'User',
my_field: 'user_id',
other_field: 'id'
)
}
)
OSO.register_class(
RepoRole,
fields: {
name: String,
repo: Relation.new(
kind: 'one',
other_type: 'Repo',
my_field: 'repo_id',
other_field: 'id'
),
user: Relation.new(
kind: 'one',
other_type: 'User',
my_field: 'user_id',
other_field: 'id'
)
}
)
OSO.load_files ["app/policy/authorization.polar"]