destiny-rails 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d50f700397f25507ff740607629d8423ae613653
4
- data.tar.gz: 8172af96c06e85e2aed7229d1bf8eeac10a2b9f8
3
+ metadata.gz: 82e0fb482a9edca20552d9f0ccfb0c6347bcf20f
4
+ data.tar.gz: d2445fe6d824947f555a5ef7e489daaa866ca2f5
5
5
  SHA512:
6
- metadata.gz: 315fd8200e89aab2e4d27e28b442a3da378d28567982c91f306c29ee78a5d375e8ddf9ad527a5637f7ead11b59c164c274c3564cdf1f652d8f1267cd5724438d
7
- data.tar.gz: 16f7ae13309213e4993ee037521eda0251d5f72c233d6942458ed89d2e82283a0047921654ee50b40aa21f813651c5c8463bc2538a4a9f41795b98d7cf6f0b64
6
+ metadata.gz: 0fdc6c8ebc179921ccaebf2ee4a460d0d2f4bbfa11115203b31113410fbc7a52729273dec8398220898df85d9f9b5f8095ef90811ef3e4f06aaee52cdcd35b32
7
+ data.tar.gz: 6265aaf5476cf150d3eec2532f0f838748379f0c4b452165e686d6056c3fabcb0dc00525e66310dd51f49eb8a4b3d42d8ef9fc29ebfe28e9da026a4febcc5d0f
data/README.md CHANGED
@@ -1,12 +1,34 @@
1
1
  # Destiny
2
2
  Simple role managment system
3
3
 
4
- Roles persisted in the database. Role is as a composition of grants. Roles may be assigned to user.
4
+ ## Concepts
5
+
6
+ Developer should be able to check permission of a user to perform an action.
7
+ Grant is an opportunity to make a particular action with some class of objects. Role is an aggregation of grants.
8
+ Roles persisted in the database.
9
+ Any number of roles may be assigned to user.
5
10
 
6
11
  ## Installation
7
12
 
13
+ ### Gem
14
+ In the command line
15
+ ```
16
+ gem install destiny-rails
17
+ ```
18
+ or in your Gemfile
19
+ ```
20
+ gem 'destiny-rails'
21
+ ```
22
+
8
23
  ### Rails
9
24
 
10
25
  ```bash
11
26
  rails g destiny:install
12
27
  ```
28
+
29
+ ## Assumptions
30
+
31
+ 1. Your app has a user model called 'User'
32
+ 2. App's controller should have (integration purpose only)
33
+ * 'current_user' method returning instance of a user model
34
+ * 'access_denied' method which contains response logic in this case
@@ -10,8 +10,17 @@ module Destiny
10
10
  data.to_hash
11
11
  end
12
12
 
13
- def role_hash
14
- to_hash
13
+ def grant(section_name, privilege)
14
+ data[section_name] ||= {}
15
+ data[section_name][privilege] = true
15
16
  end
17
+
18
+ def revoke(section_name, privilege)
19
+ if data.key? section_name
20
+ data[section_name].delete(privilege) if data[section_name].key? privilege
21
+ data.delete(section_name) if data[section_name].empty?
22
+ end
23
+ end
24
+
16
25
  end
17
26
  end
@@ -6,12 +6,12 @@ module Destiny
6
6
  has_and_belongs_to_many :roles, join_table: :users_roles
7
7
  end
8
8
 
9
- def has_grant?(section_name, grant_name)
9
+ def permitted?(section_name, privilege)
10
10
  return true if is_admin?
11
11
  return false unless role_hash[section_name]
12
- return false unless role_hash[section_name].key? grant_name
12
+ return false unless role_hash[section_name].key? privilege
13
13
 
14
- role_hash[section_name][grant_name]
14
+ role_hash[section_name][privilege]
15
15
  end
16
16
 
17
17
  def owner?(obj)
@@ -30,11 +30,12 @@ module Destiny
30
30
 
31
31
  # compatibility with The_Role gem
32
32
  alias_method :admin?, :is_admin?
33
- alias_method :has_role?, :has_grant?
33
+ alias_method :has_role?, :permitted?
34
+ alias_method :has_grant?, :permitted?
34
35
 
35
36
  module ClassMethods
36
37
  def with_role(role_name)
37
- ::Role.find_by_name(role_name).users
38
+ ::Role.find_by_name(role_name).try(:users)
38
39
  end
39
40
  end
40
41
 
@@ -1,3 +1,3 @@
1
1
  module Destiny
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: destiny-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Zhukov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler