adeia 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/adeia/permission.rb +7 -6
- data/lib/adeia/version.rb +1 -1
- data/lib/tasks/init.rake +2 -4
- data/spec/models/adeia/permission_spec.rb +12 -4
- data/spec/test_app/log/test.log +65 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 555890fd5721f4d65ca4345999ea2922b2fedc89
|
4
|
+
data.tar.gz: 413bafe58e642d675c199fedfef5f09695a80f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01d579a52e049466377919bf830bee122c8c3bfdda703269848cddd9a07765a1632515a2f2a04efe3fa64c27362e280c1ac868cd06e50fff5062de4e92b31bcb
|
7
|
+
data.tar.gz: 316d4188ca353f7aacf9d660c9d5796f602ee528b8b697e6b6f2553d501b2c5825e41ca8afb502997568f4c8292124695bc6d3ac61903d9ce1540350cb1de26c
|
@@ -33,11 +33,11 @@ class Adeia::Permission < ActiveRecord::Base
|
|
33
33
|
"#{id} - #{element.name} - R:#{read_right} - C:#{create_right}- U:#{update_right} - D:#{destroy_right} - #{resource_id} - #{actions.to_a}"
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.add(**args)
|
36
|
+
def self.add!(**args)
|
37
37
|
self.create!(**conditions(args))
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.find_or_add_by(**args)
|
40
|
+
def self.find_or_add_by!(**args)
|
41
41
|
conditions = conditions(args)
|
42
42
|
if permission = self.where(**conditions).first
|
43
43
|
permission
|
@@ -46,14 +46,15 @@ class Adeia::Permission < ActiveRecord::Base
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.fetch_element_and_actions(element_name, action_names)
|
50
|
-
actions = action_names.map { |action| Adeia::Action.find_or_create_by(name: action) }.compact
|
51
|
-
element = Adeia::Element.find_or_create_by(name: element_name)
|
49
|
+
def self.fetch_element_and_actions!(element_name, action_names)
|
50
|
+
actions = action_names.map { |action| Adeia::Action.find_or_create_by!(name: action) }.compact
|
51
|
+
element = Adeia::Element.find_or_create_by!(name: element_name)
|
52
52
|
return element, actions
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.conditions(args)
|
56
|
-
|
56
|
+
args[:read] = args[:create] = args[:update] = args[:destroy] = true if args[:full]
|
57
|
+
element, actions = fetch_element_and_actions!(args.fetch(:element), args.fetch(:actions, []))
|
57
58
|
return {
|
58
59
|
owner: args.fetch(:owner),
|
59
60
|
element: element,
|
data/lib/adeia/version.rb
CHANGED
data/lib/tasks/init.rake
CHANGED
@@ -3,12 +3,10 @@ namespace :adeia do
|
|
3
3
|
desc "Create the elements and a group with all the privileges"
|
4
4
|
task permissions: :environment do
|
5
5
|
elements = %w(adeia/permissions adeia/tokens adeia/groups)
|
6
|
-
elements.concat(ENV["elements"].split(",")) if ENV["elements"].present?
|
6
|
+
elements.concat(ENV["elements"].split(",").map { |e| e.strip }) if ENV["elements"].present?
|
7
7
|
owner = Adeia::Group.find_or_create_by!(name: "superadmin")
|
8
8
|
elements.each do |element|
|
9
|
-
|
10
|
-
Adeia::Permission.find_or_create_by!(adeia_element_id: element.id, owner_id: owner.id, owner_type: "Adeia::Group",
|
11
|
-
permission_type: "all_entries", read_right: true, create_right: true, update_right: true, destroy_right: true)
|
9
|
+
Adeia::Permission.find_or_add_by!(owner: owner, element: element, full: true)
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
@@ -8,7 +8,7 @@ module Adeia
|
|
8
8
|
describe "#add" do
|
9
9
|
|
10
10
|
it "creates a permission with default attributes" do
|
11
|
-
permission = Permission.add(owner: user, element: "adeia/permissions", read: true)
|
11
|
+
permission = Permission.add!(owner: user, element: "adeia/permissions", read: true)
|
12
12
|
expect(permission.owner).to eq user
|
13
13
|
expect(permission.element.name).to eq "adeia/permissions"
|
14
14
|
expect(permission.permission_type).to eq "all_entries"
|
@@ -19,20 +19,28 @@ module Adeia
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "creates a permission with good attributes" do
|
22
|
-
permission = Permission.add(owner: user, element: "adeia/permissions", type: "on_entry", read: true, resource_id: 1, actions: ["share"])
|
22
|
+
permission = Permission.add!(owner: user, element: "adeia/permissions", type: "on_entry", read: true, resource_id: 1, actions: ["share"])
|
23
23
|
expect(permission.permission_type).to eq "on_entry"
|
24
24
|
expect(permission.read_right).to be true
|
25
25
|
expect(permission.resource_id).to eq 1
|
26
26
|
expect(permission.actions.first.name).to eq "share"
|
27
27
|
end
|
28
28
|
|
29
|
+
it "creates a permission with all the rights when using the full option" do
|
30
|
+
permission = Permission.add!(owner: user, element: "adeia/permissions", full: true)
|
31
|
+
expect(permission.read_right).to be true
|
32
|
+
expect(permission.create_right).to be true
|
33
|
+
expect(permission.update_right).to be true
|
34
|
+
expect(permission.destroy_right).to be true
|
35
|
+
end
|
36
|
+
|
29
37
|
end
|
30
38
|
|
31
39
|
describe "#find_or_add_by" do
|
32
40
|
|
33
41
|
it "returns a permission when it already exists" do
|
34
|
-
permission = Permission.add(owner: user, element: "adeia/permissions", type: "on_entry", read: true, resource_id: 1, actions: ["share"])
|
35
|
-
expect(Permission.find_or_add_by(owner: user, element: "adeia/permissions", type: "on_entry")).to eq permission
|
42
|
+
permission = Permission.add!(owner: user, element: "adeia/permissions", type: "on_entry", read: true, resource_id: 1, actions: ["share"])
|
43
|
+
expect(Permission.find_or_add_by!(owner: user, element: "adeia/permissions", type: "on_entry")).to eq permission
|
36
44
|
end
|
37
45
|
|
38
46
|
end
|
data/spec/test_app/log/test.log
CHANGED
@@ -62208,3 +62208,68 @@ Migrating to CreateArticles (20151012185726)
|
|
62208
62208
|
[1m[35mAdeia::Element Load (0.1ms)[0m SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
|
62209
62209
|
[1m[36mAdeia::Permission Load (0.2ms)[0m [1mSELECT "adeia_permissions".* FROM "adeia_permissions" WHERE "adeia_permissions"."permission_type" = ? AND "adeia_permissions"."owner_type" = 'User' AND "adeia_permissions"."owner_id" = 1 AND "adeia_permissions"."adeia_element_id" = 1 ORDER BY "adeia_permissions"."id" ASC LIMIT 1[0m [["permission_type", 2]]
|
62210
62210
|
[1m[35m (0.8ms)[0m rollback transaction
|
62211
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.6ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
62212
|
+
[1m[35m (0.1ms)[0m begin transaction
|
62213
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
62214
|
+
[1m[35mSQL (1.4ms)[0m INSERT INTO "users" ("name", "password_digest", "remember_token", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["name", "admin"], ["password_digest", "$2a$04$hIlheFK4JK13c/TwBE/neebRgnAwQiduGOY.W8pfDJ01Q39/3AQl6"], ["remember_token", "-Bxu3n5h3E-hTtJ1eLEWBQ"], ["created_at", "2015-11-01 15:51:07.475630"], ["updated_at", "2015-11-01 15:51:07.475630"]]
|
62215
|
+
[1m[36m (0.4ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
62216
|
+
[1m[35mAdeia::Element Load (0.8ms)[0m SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
|
62217
|
+
[1m[36m (0.4ms)[0m [1mSAVEPOINT active_record_1[0m
|
62218
|
+
[1m[35mSQL (3.2ms)[0m INSERT INTO "adeia_elements" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "adeia/permissions"], ["created_at", "2015-11-01 15:51:07.499856"], ["updated_at", "2015-11-01 15:51:07.499856"]]
|
62219
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
62220
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
62221
|
+
[1m[36mSQL (1.6ms)[0m [1mINSERT INTO "adeia_permissions" ("owner_id", "owner_type", "adeia_element_id", "permission_type", "read_right", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)[0m [["owner_id", 1], ["owner_type", "User"], ["adeia_element_id", 1], ["permission_type", 0], ["read_right", "t"], ["created_at", "2015-11-01 15:51:07.534414"], ["updated_at", "2015-11-01 15:51:07.534414"]]
|
62222
|
+
[1m[35mAdeia::Action Load (0.7ms)[0m SELECT "adeia_actions".* FROM "adeia_actions" INNER JOIN "adeia_action_permissions" ON "adeia_actions"."id" = "adeia_action_permissions"."adeia_action_id" WHERE "adeia_action_permissions"."adeia_permission_id" = ? [["adeia_permission_id", 1]]
|
62223
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
62224
|
+
[1m[35m (1.8ms)[0m rollback transaction
|
62225
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
62226
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
62227
|
+
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "users" ("name", "password_digest", "remember_token", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)[0m [["name", "admin"], ["password_digest", "$2a$04$GuQT..kVAtaq01bYIrm4..Gy8HVM1Hpr6EPPS.CLvtiepwGb6JiRK"], ["remember_token", "VugQ5Wth9tPoAPs74_iXcg"], ["created_at", "2015-11-01 15:51:07.592621"], ["updated_at", "2015-11-01 15:51:07.592621"]]
|
62228
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
62229
|
+
[1m[36mAdeia::Action Load (0.6ms)[0m [1mSELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1[0m [["name", "share"]]
|
62230
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
62231
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "adeia_actions" ("name", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["name", "share"], ["created_at", "2015-11-01 15:51:07.599122"], ["updated_at", "2015-11-01 15:51:07.599122"]]
|
62232
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
62233
|
+
[1m[36mAdeia::Element Load (0.0ms)[0m [1mSELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1[0m [["name", "adeia/permissions"]]
|
62234
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
62235
|
+
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "adeia_elements" ("name", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["name", "adeia/permissions"], ["created_at", "2015-11-01 15:51:07.602467"], ["updated_at", "2015-11-01 15:51:07.602467"]]
|
62236
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
62237
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
62238
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO "adeia_permissions" ("owner_id", "owner_type", "adeia_element_id", "permission_type", "read_right", "resource_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?) [["owner_id", 1], ["owner_type", "User"], ["adeia_element_id", 1], ["permission_type", 2], ["read_right", "t"], ["resource_id", 1], ["created_at", "2015-11-01 15:51:07.612161"], ["updated_at", "2015-11-01 15:51:07.612161"]]
|
62239
|
+
[1m[36mSQL (1.1ms)[0m [1mINSERT INTO "adeia_action_permissions" ("adeia_action_id", "adeia_permission_id", "created_at", "updated_at") VALUES (?, ?, ?, ?)[0m [["adeia_action_id", 1], ["adeia_permission_id", 1], ["created_at", "2015-11-01 15:51:07.614087"], ["updated_at", "2015-11-01 15:51:07.614087"]]
|
62240
|
+
[1m[35mAdeia::Action Load (0.1ms)[0m SELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1 [["name", "share"]]
|
62241
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
62242
|
+
[1m[35m (1.0ms)[0m rollback transaction
|
62243
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
62244
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
62245
|
+
[1m[36mSQL (0.4ms)[0m [1mINSERT INTO "users" ("name", "password_digest", "remember_token", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)[0m [["name", "admin"], ["password_digest", "$2a$04$a/O3zJrlU3A2gAnnNtlt.OVuh8IaQ0lu6I7UZv15XgYTDgCKwfDZO"], ["remember_token", "zG0YaKIxhe_F7HPuhJciSw"], ["created_at", "2015-11-01 15:51:07.625291"], ["updated_at", "2015-11-01 15:51:07.625291"]]
|
62246
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
62247
|
+
[1m[36mAdeia::Element Load (0.0ms)[0m [1mSELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1[0m [["name", "adeia/permissions"]]
|
62248
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
62249
|
+
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "adeia_elements" ("name", "created_at", "updated_at") VALUES (?, ?, ?)[0m [["name", "adeia/permissions"], ["created_at", "2015-11-01 15:51:07.640444"], ["updated_at", "2015-11-01 15:51:07.640444"]]
|
62250
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
62251
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
62252
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO "adeia_permissions" ("owner_id", "owner_type", "adeia_element_id", "permission_type", "read_right", "create_right", "update_right", "destroy_right", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["owner_id", 1], ["owner_type", "User"], ["adeia_element_id", 1], ["permission_type", 0], ["read_right", "t"], ["create_right", "t"], ["update_right", "t"], ["destroy_right", "t"], ["created_at", "2015-11-01 15:51:07.642893"], ["updated_at", "2015-11-01 15:51:07.642893"]]
|
62253
|
+
[1m[36mAdeia::Action Load (0.1ms)[0m [1mSELECT "adeia_actions".* FROM "adeia_actions" INNER JOIN "adeia_action_permissions" ON "adeia_actions"."id" = "adeia_action_permissions"."adeia_action_id" WHERE "adeia_action_permissions"."adeia_permission_id" = ?[0m [["adeia_permission_id", 1]]
|
62254
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
62255
|
+
[1m[36m (0.8ms)[0m [1mrollback transaction[0m
|
62256
|
+
[1m[35m (0.1ms)[0m begin transaction
|
62257
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
62258
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "password_digest", "remember_token", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["name", "admin"], ["password_digest", "$2a$04$PRphb4/hw4yAL4AECgeP9ePxRTzTu2ikKELQ8p0LxvpIqXYV1GsAe"], ["remember_token", "qxXZksrow_ZNBnF7tJ7j6w"], ["created_at", "2015-11-01 15:51:07.651492"], ["updated_at", "2015-11-01 15:51:07.651492"]]
|
62259
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
62260
|
+
[1m[35mAdeia::Action Load (0.0ms)[0m SELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1 [["name", "share"]]
|
62261
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
62262
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "adeia_actions" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "share"], ["created_at", "2015-11-01 15:51:07.654218"], ["updated_at", "2015-11-01 15:51:07.654218"]]
|
62263
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
62264
|
+
[1m[35mAdeia::Element Load (0.1ms)[0m SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
|
62265
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
62266
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "adeia_elements" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "adeia/permissions"], ["created_at", "2015-11-01 15:51:07.656456"], ["updated_at", "2015-11-01 15:51:07.656456"]]
|
62267
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
62268
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
62269
|
+
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "adeia_permissions" ("owner_id", "owner_type", "adeia_element_id", "permission_type", "read_right", "resource_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?)[0m [["owner_id", 1], ["owner_type", "User"], ["adeia_element_id", 1], ["permission_type", 2], ["read_right", "t"], ["resource_id", 1], ["created_at", "2015-11-01 15:51:07.659961"], ["updated_at", "2015-11-01 15:51:07.659961"]]
|
62270
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "adeia_action_permissions" ("adeia_action_id", "adeia_permission_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["adeia_action_id", 1], ["adeia_permission_id", 1], ["created_at", "2015-11-01 15:51:07.661279"], ["updated_at", "2015-11-01 15:51:07.661279"]]
|
62271
|
+
[1m[36mAdeia::Action Load (0.1ms)[0m [1mSELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1[0m [["name", "share"]]
|
62272
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
62273
|
+
[1m[36mAdeia::Element Load (0.1ms)[0m [1mSELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1[0m [["name", "adeia/permissions"]]
|
62274
|
+
[1m[35mAdeia::Permission Load (0.2ms)[0m SELECT "adeia_permissions".* FROM "adeia_permissions" WHERE "adeia_permissions"."permission_type" = ? AND "adeia_permissions"."owner_type" = 'User' AND "adeia_permissions"."owner_id" = 1 AND "adeia_permissions"."adeia_element_id" = 1 ORDER BY "adeia_permissions"."id" ASC LIMIT 1 [["permission_type", 2]]
|
62275
|
+
[1m[36m (0.9ms)[0m [1mrollback transaction[0m
|