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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48b608ba6fd11efea91823a1be4b8d390d08e53f
4
- data.tar.gz: dedc7c6f1500b5f137f0a1ec7bdf1029c6f66462
3
+ metadata.gz: 555890fd5721f4d65ca4345999ea2922b2fedc89
4
+ data.tar.gz: 413bafe58e642d675c199fedfef5f09695a80f2d
5
5
  SHA512:
6
- metadata.gz: b2edfd6e4da84b1afff33fa0ee64cf312b921d13d3c285136a94478e86c7a42ab3bd4cb6c272dbca37809498ea3e709f9f58ac096e3fb1f91b1ac865be1f9a30
7
- data.tar.gz: 09b82b09a77c4c540b1f9b63b2802a9e0fd030560351d7a922e2c63968935042ee4d775f0dfccfb42363060afa862cbcd44ec413d6c13c4905e14f66469749a1
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
- element, actions = fetch_element_and_actions(args.fetch(:element), args.fetch(:actions, []))
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
@@ -1,3 +1,3 @@
1
1
  module Adeia
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
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
- element = Adeia::Element.find_or_create_by!(name: element)
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
@@ -62208,3 +62208,68 @@ Migrating to CreateArticles (20151012185726)
62208
62208
  Adeia::Element Load (0.1ms) SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
62209
62209
  Adeia::Permission Load (0.2ms) 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]]
62210
62210
   (0.8ms) rollback transaction
62211
+ ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
62212
+  (0.1ms) begin transaction
62213
+  (0.1ms) SAVEPOINT active_record_1
62214
+ SQL (1.4ms) 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
+  (0.4ms) RELEASE SAVEPOINT active_record_1
62216
+ Adeia::Element Load (0.8ms) SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
62217
+  (0.4ms) SAVEPOINT active_record_1
62218
+ SQL (3.2ms) 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
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62220
+  (0.1ms) SAVEPOINT active_record_1
62221
+ SQL (1.6ms) INSERT INTO "adeia_permissions" ("owner_id", "owner_type", "adeia_element_id", "permission_type", "read_right", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["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
+ Adeia::Action Load (0.7ms) 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
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62224
+  (1.8ms) rollback transaction
62225
+  (0.1ms) begin transaction
62226
+  (0.1ms) SAVEPOINT active_record_1
62227
+ SQL (0.3ms) INSERT INTO "users" ("name", "password_digest", "remember_token", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["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
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62229
+ Adeia::Action Load (0.6ms) SELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1 [["name", "share"]]
62230
+  (0.1ms) SAVEPOINT active_record_1
62231
+ SQL (0.4ms) INSERT INTO "adeia_actions" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "share"], ["created_at", "2015-11-01 15:51:07.599122"], ["updated_at", "2015-11-01 15:51:07.599122"]]
62232
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62233
+ Adeia::Element Load (0.0ms) SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
62234
+  (0.0ms) SAVEPOINT active_record_1
62235
+ SQL (0.1ms) INSERT INTO "adeia_elements" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "adeia/permissions"], ["created_at", "2015-11-01 15:51:07.602467"], ["updated_at", "2015-11-01 15:51:07.602467"]]
62236
+  (0.0ms) RELEASE SAVEPOINT active_record_1
62237
+  (0.1ms) SAVEPOINT active_record_1
62238
+ SQL (0.2ms) 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
+ SQL (1.1ms) 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.614087"], ["updated_at", "2015-11-01 15:51:07.614087"]]
62240
+ Adeia::Action Load (0.1ms) SELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1 [["name", "share"]]
62241
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62242
+  (1.0ms) rollback transaction
62243
+  (0.1ms) begin transaction
62244
+  (0.1ms) SAVEPOINT active_record_1
62245
+ SQL (0.4ms) INSERT INTO "users" ("name", "password_digest", "remember_token", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["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
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62247
+ Adeia::Element Load (0.0ms) SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
62248
+  (0.1ms) SAVEPOINT active_record_1
62249
+ SQL (0.3ms) INSERT INTO "adeia_elements" ("name", "created_at", "updated_at") VALUES (?, ?, ?) [["name", "adeia/permissions"], ["created_at", "2015-11-01 15:51:07.640444"], ["updated_at", "2015-11-01 15:51:07.640444"]]
62250
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62251
+  (0.0ms) SAVEPOINT active_record_1
62252
+ SQL (0.2ms) 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
+ Adeia::Action Load (0.1ms) 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]]
62254
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62255
+  (0.8ms) rollback transaction
62256
+  (0.1ms) begin transaction
62257
+  (0.1ms) SAVEPOINT active_record_1
62258
+ SQL (0.3ms) 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
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62260
+ Adeia::Action Load (0.0ms) SELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1 [["name", "share"]]
62261
+  (0.0ms) SAVEPOINT active_record_1
62262
+ SQL (0.3ms) 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
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62264
+ Adeia::Element Load (0.1ms) SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
62265
+  (0.0ms) SAVEPOINT active_record_1
62266
+ SQL (0.1ms) 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
+  (0.0ms) RELEASE SAVEPOINT active_record_1
62268
+  (0.1ms) SAVEPOINT active_record_1
62269
+ SQL (0.1ms) 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.659961"], ["updated_at", "2015-11-01 15:51:07.659961"]]
62270
+ SQL (0.1ms) 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
+ Adeia::Action Load (0.1ms) SELECT "adeia_actions".* FROM "adeia_actions" WHERE "adeia_actions"."name" = ? LIMIT 1 [["name", "share"]]
62272
+  (0.1ms) RELEASE SAVEPOINT active_record_1
62273
+ Adeia::Element Load (0.1ms) SELECT "adeia_elements".* FROM "adeia_elements" WHERE "adeia_elements"."name" = ? LIMIT 1 [["name", "adeia/permissions"]]
62274
+ Adeia::Permission Load (0.2ms) 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
+  (0.9ms) rollback transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adeia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - khcr