casdoor-ruby-sdk 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +134 -55
- data/lib/casdoor/adapter.rb +48 -0
- data/lib/casdoor/application.rb +48 -0
- data/lib/casdoor/auth.rb +143 -0
- data/lib/casdoor/cert.rb +47 -0
- data/lib/casdoor/email.rb +33 -0
- data/lib/casdoor/enforce.rb +47 -0
- data/lib/casdoor/enforcer.rb +48 -0
- data/lib/casdoor/entity.rb +17 -44
- data/lib/casdoor/global.rb +34 -0
- data/lib/casdoor/group.rb +48 -0
- data/lib/casdoor/invitation.rb +57 -0
- data/lib/casdoor/jwt.rb +75 -0
- data/lib/casdoor/ldap.rb +67 -0
- data/lib/casdoor/logout.rb +41 -0
- data/lib/casdoor/mfa.rb +53 -0
- data/lib/casdoor/model.rb +48 -0
- data/lib/casdoor/notification.rb +29 -0
- data/lib/casdoor/order.rb +59 -0
- data/lib/casdoor/order_pay.rb +40 -0
- data/lib/casdoor/organization.rb +47 -0
- data/lib/casdoor/payment.rb +61 -0
- data/lib/casdoor/permission.rb +57 -0
- data/lib/casdoor/plan.rb +48 -0
- data/lib/casdoor/policy.rb +67 -0
- data/lib/casdoor/pricing.rb +48 -0
- data/lib/casdoor/product.rb +48 -0
- data/lib/casdoor/provider.rb +48 -0
- data/lib/casdoor/record.rb +43 -0
- data/lib/casdoor/resource.rb +75 -0
- data/lib/casdoor/role.rb +52 -0
- data/lib/casdoor/session.rb +53 -0
- data/lib/casdoor/sms.rb +31 -0
- data/lib/casdoor/subscription.rb +48 -0
- data/lib/casdoor/syncer.rb +48 -0
- data/lib/casdoor/token.rb +60 -0
- data/lib/casdoor/transaction.rb +62 -0
- data/lib/casdoor/url.rb +47 -0
- data/lib/casdoor/user.rb +124 -0
- data/lib/casdoor/util.rb +147 -0
- data/lib/casdoor/util_modify.rb +65 -0
- data/lib/casdoor/version.rb +1 -1
- data/lib/casdoor/webhook.rb +48 -0
- data/lib/casdoor.rb +13 -5
- metadata +41 -6
- data/lib/casdoor/api/auth.rb +0 -153
- data/lib/casdoor/api/crud.rb +0 -122
- data/lib/casdoor/api/enforce.rb +0 -44
- data/lib/casdoor/api/users.rb +0 -83
- data/lib/casdoor/client.rb +0 -143
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Order < Entity; end
|
|
19
|
+
|
|
20
|
+
# A product in an order, e.g. ProductInfo.new(name: "product-1", quantity: 1)
|
|
21
|
+
class ProductInfo < Entity; end
|
|
22
|
+
|
|
23
|
+
# The order APIs, the counterpart of order.go of the Go SDK
|
|
24
|
+
class Client
|
|
25
|
+
def get_orders
|
|
26
|
+
get_objects('get-orders', Order, 'owner' => organization_name)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
30
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
31
|
+
def get_pagination_orders(page, page_size, query_map = {})
|
|
32
|
+
get_pagination_objects('get-orders', Order, organization_name, page, page_size, query_map)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def get_user_orders(user_name)
|
|
36
|
+
get_objects('get-user-orders', Order, 'owner' => organization_name, 'user' => user_name)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get_order(name)
|
|
40
|
+
get_object('get-order', Order, 'id' => get_id(name))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update_order(order)
|
|
44
|
+
modify_object('update-order', Order, order, organization_name)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def add_order(order)
|
|
48
|
+
modify_object('add-order', Order, order, organization_name)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def delete_order(order)
|
|
52
|
+
modify_object('delete-order', Order, order, organization_name)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def cancel_order(name)
|
|
56
|
+
do_post('cancel-order', { 'id' => get_id(name) }, '')['data'] == 'Affected'
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
# Placing and paying orders, the counterpart of order_pay.go of the Go SDK
|
|
19
|
+
class Client
|
|
20
|
+
# Places an order of the products for the user (the name in the client's organization).
|
|
21
|
+
# product_infos are like [ProductInfo.new(name: "product-1", quantity: 1)].
|
|
22
|
+
def place_order(product_infos, user_name)
|
|
23
|
+
query = { 'owner' => organization_name }
|
|
24
|
+
query['userName'] = user_name unless user_name.to_s.empty?
|
|
25
|
+
body = { 'productInfos' => product_infos.map { |info| to_entity(ProductInfo, info) } }
|
|
26
|
+
Order.new(do_post('place-order', query, body)['data'])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Pays the order with the payment provider, returns the payment
|
|
30
|
+
def pay_order(order_name, provider_name)
|
|
31
|
+
query = { 'id' => get_id(order_name), 'providerName' => provider_name }
|
|
32
|
+
Payment.new(do_post('pay-order', query, '')['data'])
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Places an order of one product for the user, it's then paid with pay_order
|
|
36
|
+
def buy_product(name, _provider_name, user_name)
|
|
37
|
+
place_order([ProductInfo.new(name: name, quantity: 1)], user_name)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Organization < Entity; end
|
|
19
|
+
|
|
20
|
+
# The organization APIs, the counterpart of organization.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_organization(name)
|
|
23
|
+
get_object('get-organization', Organization, 'id' => get_admin_id(name))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_organizations
|
|
27
|
+
get_objects('get-organizations', Organization, 'owner' => 'admin')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The organizations with only their names and display names
|
|
31
|
+
def get_organization_names
|
|
32
|
+
get_objects('get-organization-names', Organization, 'owner' => 'admin')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_organization(organization)
|
|
36
|
+
modify_object('add-organization', Organization, organization, 'admin')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def delete_organization(organization)
|
|
40
|
+
modify_object('delete-organization', Organization, organization, 'admin')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update_organization(organization)
|
|
44
|
+
modify_object('update-organization', Organization, organization, 'admin')
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Payment < Entity; end
|
|
19
|
+
|
|
20
|
+
# The payment APIs, the counterpart of payment.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_payments
|
|
23
|
+
get_objects('get-payments', Payment, 'owner' => organization_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
27
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
28
|
+
def get_pagination_payments(page, page_size, query_map = {})
|
|
29
|
+
get_pagination_objects('get-payments', Payment, organization_name, page, page_size, query_map)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_payment(name)
|
|
33
|
+
get_object('get-payment', Payment, 'id' => get_id(name))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get_user_payments(user_name)
|
|
37
|
+
get_objects('get-user-payments', Payment,
|
|
38
|
+
'owner' => organization_name, 'organization' => organization_name, 'user' => user_name)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def update_payment(payment)
|
|
42
|
+
modify_object('update-payment', Payment, payment, organization_name)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def add_payment(payment)
|
|
46
|
+
modify_object('add-payment', Payment, payment, organization_name)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def delete_payment(payment)
|
|
50
|
+
modify_object('delete-payment', Payment, payment, organization_name)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def notify_payment(payment)
|
|
54
|
+
modify_object('notify-payment', Payment, payment, organization_name)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def invoice_payment(payment)
|
|
58
|
+
modify_object('invoice-payment', Payment, payment, organization_name)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Permission < Entity; end
|
|
19
|
+
|
|
20
|
+
# The permission APIs, the counterpart of permission.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_permissions
|
|
23
|
+
get_objects('get-permissions', Permission, 'owner' => organization_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The permissions that the role is granted
|
|
27
|
+
def get_permissions_by_role(name)
|
|
28
|
+
get_objects('get-permissions-by-role', Permission, 'id' => get_id(name))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
32
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
33
|
+
def get_pagination_permissions(page, page_size, query_map = {})
|
|
34
|
+
get_pagination_objects('get-permissions', Permission, organization_name, page, page_size, query_map)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def get_permission(name)
|
|
38
|
+
get_object('get-permission', Permission, 'id' => get_id(name))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def update_permission(permission)
|
|
42
|
+
modify_object('update-permission', Permission, permission, organization_name)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def update_permission_for_columns(permission, columns)
|
|
46
|
+
modify_object('update-permission', Permission, permission, organization_name, columns)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def add_permission(permission)
|
|
50
|
+
modify_object('add-permission', Permission, permission, organization_name)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def delete_permission(permission)
|
|
54
|
+
modify_object('delete-permission', Permission, permission, organization_name)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/casdoor/plan.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Plan < Entity; end
|
|
19
|
+
|
|
20
|
+
# The plan APIs, the counterpart of plan.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_plans
|
|
23
|
+
get_objects('get-plans', Plan, 'owner' => organization_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
27
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
28
|
+
def get_pagination_plans(page, page_size, query_map = {})
|
|
29
|
+
get_pagination_objects('get-plans', Plan, organization_name, page, page_size, query_map)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_plan(name)
|
|
33
|
+
get_object('get-plan', Plan, 'id' => get_id(name))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update_plan(plan)
|
|
37
|
+
modify_object('update-plan', Plan, plan, organization_name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_plan(plan)
|
|
41
|
+
modify_object('add-plan', Plan, plan, organization_name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def delete_plan(plan)
|
|
45
|
+
modify_object('delete-plan', Plan, plan, organization_name)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
# A policy of an enforcer, e.g. CasbinRule.new(ptype: "p", v0: "alice", v1: "data1", v2: "read"). Casdoor names
|
|
19
|
+
# its JSON fields "Ptype", "V0", ..., "V5".
|
|
20
|
+
class CasbinRule < Entity
|
|
21
|
+
def self.field_key(name)
|
|
22
|
+
name.to_s.capitalize
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A filter of get_filtered_policies, e.g. PolicyFilter.new(ptype: "g", field_index: 0, field_values: ["alice"])
|
|
27
|
+
class PolicyFilter < Entity; end
|
|
28
|
+
|
|
29
|
+
# The policy APIs of the enforcers, the counterpart of policy.go of the Go SDK
|
|
30
|
+
class Client
|
|
31
|
+
def add_policy(enforcer, policy)
|
|
32
|
+
modify_policy('add-policy', enforcer, [policy])
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def update_policy(enforcer, old_policy, new_policy)
|
|
36
|
+
modify_policy('update-policy', enforcer, [old_policy, new_policy])
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def remove_policy(enforcer, policy)
|
|
40
|
+
modify_policy('remove-policy', enforcer, [policy])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# adapter_id ("owner/name") can be empty to use the adapter of the enforcer
|
|
44
|
+
def get_policies(enforcer_name, adapter_id)
|
|
45
|
+
get_objects('get-policies', CasbinRule, 'id' => get_id(enforcer_name), 'adapterId' => adapter_id)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The policies of the enforcer ("owner/name") that match all the filters
|
|
49
|
+
def get_filtered_policies(enforcer_id, filters)
|
|
50
|
+
filters = filters.map { |filter| to_entity(PolicyFilter, filter) }
|
|
51
|
+
(do_post('get-filtered-policies', { 'id' => enforcer_id }, filters)['data'] || []).map do |item|
|
|
52
|
+
CasbinRule.new(item)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def modify_policy(action, enforcer, policies)
|
|
59
|
+
enforcer = to_entity(Enforcer, enforcer)
|
|
60
|
+
enforcer.owner = organization_name if enforcer.owner.to_s.empty?
|
|
61
|
+
policies = policies.map { |policy| to_entity(CasbinRule, policy) }
|
|
62
|
+
|
|
63
|
+
body = action == 'update-policy' ? policies : policies.first
|
|
64
|
+
do_post(action, { 'id' => enforcer.get_id }, body)['data'] == 'Affected'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Pricing < Entity; end
|
|
19
|
+
|
|
20
|
+
# The pricing APIs, the counterpart of pricing.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_pricings
|
|
23
|
+
get_objects('get-pricings', Pricing, 'owner' => organization_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
27
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
28
|
+
def get_pagination_pricings(page, page_size, query_map = {})
|
|
29
|
+
get_pagination_objects('get-pricings', Pricing, organization_name, page, page_size, query_map)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_pricing(name)
|
|
33
|
+
get_object('get-pricing', Pricing, 'id' => get_id(name))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update_pricing(pricing)
|
|
37
|
+
modify_object('update-pricing', Pricing, pricing, organization_name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_pricing(pricing)
|
|
41
|
+
modify_object('add-pricing', Pricing, pricing, organization_name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def delete_pricing(pricing)
|
|
45
|
+
modify_object('delete-pricing', Pricing, pricing, organization_name)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Product < Entity; end
|
|
19
|
+
|
|
20
|
+
# The product APIs, the counterpart of product.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_products
|
|
23
|
+
get_objects('get-products', Product, 'owner' => organization_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
27
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
28
|
+
def get_pagination_products(page, page_size, query_map = {})
|
|
29
|
+
get_pagination_objects('get-products', Product, organization_name, page, page_size, query_map)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_product(name)
|
|
33
|
+
get_object('get-product', Product, 'id' => get_id(name))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update_product(product)
|
|
37
|
+
modify_object('update-product', Product, product, organization_name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_product(product)
|
|
41
|
+
modify_object('add-product', Product, product, organization_name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def delete_product(product)
|
|
45
|
+
modify_object('delete-product', Product, product, organization_name)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Provider < Entity; end
|
|
19
|
+
|
|
20
|
+
# The provider APIs, the counterpart of provider.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_providers
|
|
23
|
+
get_objects('get-providers', Provider, 'owner' => organization_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
27
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
28
|
+
def get_pagination_providers(page, page_size, query_map = {})
|
|
29
|
+
get_pagination_objects('get-providers', Provider, organization_name, page, page_size, query_map)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_provider(name)
|
|
33
|
+
get_object('get-provider', Provider, 'id' => get_id(name))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update_provider(provider)
|
|
37
|
+
modify_object('update-provider', Provider, provider, organization_name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_provider(provider)
|
|
41
|
+
modify_object('add-provider', Provider, provider, organization_name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def delete_provider(provider)
|
|
45
|
+
modify_object('delete-provider', Provider, provider, organization_name)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Record < Entity; end
|
|
19
|
+
|
|
20
|
+
# The record APIs, the counterpart of record.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
def get_records
|
|
23
|
+
get_objects('get-records', Record, 'owner' => organization_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the objects of the page and the total count. query_map can filter and sort them, e.g.
|
|
27
|
+
# { field: "name", value: "alice", sort_field: "created_time", sort_order: "descend" }
|
|
28
|
+
def get_pagination_records(page, page_size, query_map = {})
|
|
29
|
+
get_pagination_objects('get-records', Record, organization_name, page, page_size, query_map)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_record(name)
|
|
33
|
+
get_object('get-record', Record, 'id' => get_id(name))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def add_record(record)
|
|
37
|
+
record = to_entity(Record, record)
|
|
38
|
+
record.owner = organization_name if record.owner.to_s.empty?
|
|
39
|
+
record.organization = organization_name if record.organization.to_s.empty?
|
|
40
|
+
do_post('add-record', nil, record)['data'] == 'Affected'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2026 The Casdoor Authors. All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
module Casdoor
|
|
18
|
+
class Resource < Entity; end
|
|
19
|
+
|
|
20
|
+
# The resource (uploaded file) APIs, the counterpart of resource.go of the Go SDK
|
|
21
|
+
class Client
|
|
22
|
+
# id is "owner/name", where the name of a resource is its path, like "/casdoor/avatar/casbin/alice.png"
|
|
23
|
+
def get_resource(id)
|
|
24
|
+
get_object('get-resource', Resource, 'owner' => organization_name, 'id' => id)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def get_resource_ex(owner, name)
|
|
28
|
+
get_resource("#{owner}/#{name}")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_resources(owner, user, field, value, sort_field, sort_order)
|
|
32
|
+
get_objects('get-resources', Resource, 'owner' => owner, 'user' => user, 'field' => field, 'value' => value,
|
|
33
|
+
'sortField' => sort_field, 'sortOrder' => sort_order)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get_pagination_resources(owner, user, field, value, page_size, page, sort_field, sort_order)
|
|
37
|
+
get_objects('get-resources', Resource, 'owner' => owner, 'user' => user, 'field' => field, 'value' => value,
|
|
38
|
+
'p' => page.to_s, 'pageSize' => page_size.to_s,
|
|
39
|
+
'sortField' => sort_field, 'sortOrder' => sort_order)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Uploads a file for the user with the storage provider of the client's application.
|
|
43
|
+
# Returns [the URL of the file, the name of the resource].
|
|
44
|
+
def upload_resource(user, tag, parent, full_file_path, file_bytes)
|
|
45
|
+
upload_resource_ex(user, tag, parent, full_file_path, file_bytes, nil, nil)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def upload_resource_ex(user, tag, parent, full_file_path, file_bytes, created_time, description)
|
|
49
|
+
query = { 'owner' => organization_name, 'user' => user, 'application' => application_name, 'tag' => tag,
|
|
50
|
+
'parent' => parent, 'fullFilePath' => full_file_path, 'createdTime' => created_time,
|
|
51
|
+
'description' => description }
|
|
52
|
+
response = do_post('upload-resource', query, file_bytes, true, true)
|
|
53
|
+
[response['data'], response['data2']]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def add_resource(resource)
|
|
57
|
+
modify_object('add-resource', Resource, resource, organization_name)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def update_resource(resource)
|
|
61
|
+
modify_object('update-resource', Resource, resource, organization_name)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def delete_resource(resource)
|
|
65
|
+
delete_resource_with_tag(resource, '')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# A tag of "avatar" etc. also deletes the file from the storage
|
|
69
|
+
def delete_resource_with_tag(resource, tag)
|
|
70
|
+
resource = to_entity(Resource, resource)
|
|
71
|
+
resource.owner = organization_name if resource.owner.to_s.empty?
|
|
72
|
+
do_post('delete-resource', { 'tag' => tag }, resource)['data'] == 'Affected'
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|