aptible-rails 0.4.12 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aptible/rails/decorators/account_decorator.rb +12 -0
- data/lib/aptible/rails/decorators/application_decorator.rb +2 -1
- data/lib/aptible/rails/decorators/operation_decorator.rb +13 -0
- data/lib/aptible/rails/decorators/resource_decorator.rb +1 -1
- data/lib/aptible/rails/decorators/role_decorator.rb +16 -0
- data/lib/aptible/rails/decorators/user_decorator.rb +31 -3
- data/lib/aptible/rails/garner.rb +1 -1
- data/lib/aptible/rails/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc1c1db94972af41d22e03c859b11fe13e6c6074
|
4
|
+
data.tar.gz: fac8a5dca172e1aa46fa6af418e4e9ee70658a0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d292f742fe7e8722fbdfd58d9aee624eea2a0ae00631831a2dddeb050eb0f35212a5e6eee24c661e22743bba813f0fb8ba4b484b34c33fbbaf685da75996d847
|
7
|
+
data.tar.gz: 2d1c48ee5c2b2eece49ca6bdb0ae1294605835df2b9279c406cac2776e2c416b9a13552a342bd009ef004aa9286006f42a799637724e1f3a710a54efcbdd4bdc
|
@@ -2,4 +2,16 @@ class AccountDecorator < ApplicationDecorator
|
|
2
2
|
def needs_startup_guide?
|
3
3
|
object.apps.count == 0 && object.databases.count == 0
|
4
4
|
end
|
5
|
+
|
6
|
+
def cached_permissions
|
7
|
+
garner.bind(h.controller.session_token) do
|
8
|
+
object.permissions
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# rubocop:disable PredicateName
|
13
|
+
def has_scope?(scope)
|
14
|
+
cached_permissions.map(&:scope).include? scope
|
15
|
+
end
|
16
|
+
# rubocop:enable PredicateName
|
5
17
|
end
|
@@ -14,7 +14,8 @@ require_relative 'resource_decorator'
|
|
14
14
|
require_relative 'criterion_decorator'
|
15
15
|
require_relative 'account_decorator'
|
16
16
|
require_relative 'app_decorator'
|
17
|
-
require_relative 'database_decorator'
|
18
17
|
require_relative 'operation_decorator'
|
19
18
|
require_relative 'organization_decorator'
|
19
|
+
require_relative 'role_decorator'
|
20
20
|
require_relative 'user_decorator'
|
21
|
+
require_relative 'database_decorator'
|
@@ -1,5 +1,18 @@
|
|
1
1
|
class OperationDecorator < ApplicationDecorator
|
2
|
+
# TODO: cleanup after manual migration of user data to operations
|
3
|
+
|
2
4
|
def past_tense
|
3
5
|
object.type.humanize + (type[-1] == 'e' ? 'd' : 'ed')
|
4
6
|
end
|
7
|
+
|
8
|
+
def creator_gravatar
|
9
|
+
return nil if object.user.nil? && object.user_email.nil?
|
10
|
+
email = object.user_email || object.user.email
|
11
|
+
h.gravatar_url(email, 32)
|
12
|
+
end
|
13
|
+
|
14
|
+
def creator_name
|
15
|
+
return nil if object.user.nil? && object.user_name.nil?
|
16
|
+
object.user_name || object.user.name
|
17
|
+
end
|
5
18
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class RoleDecorator < ApplicationDecorator
|
2
|
+
def can?(scope, account)
|
3
|
+
role_scopes = account_permissions(account).map(&:scope)
|
4
|
+
role_scopes.include?('manage') || role_scopes.include?(scope)
|
5
|
+
end
|
6
|
+
|
7
|
+
def has?(scope, account)
|
8
|
+
account_permissions(account).map(&:scope).include?(scope)
|
9
|
+
end
|
10
|
+
|
11
|
+
def cached_permissions
|
12
|
+
garner.bind(h.controller.session_token) do
|
13
|
+
object.permissions
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,13 +1,41 @@
|
|
1
1
|
class UserDecorator < ApplicationDecorator
|
2
|
+
def can?(scope, account)
|
3
|
+
return true if object.can_manage?(account.organization)
|
4
|
+
user_scopes = account_permissions(account).map(&:scope)
|
5
|
+
user_scopes.include?('manage') || user_scopes.include?(scope)
|
6
|
+
end
|
7
|
+
|
2
8
|
def cached_organizations
|
9
|
+
garner
|
10
|
+
.bind(h.controller.session_token)
|
11
|
+
.bind(h.controller.current_organization) do
|
12
|
+
object.organizations
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def organization_count
|
17
|
+
cached_organizations.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def cached_roles
|
3
21
|
garner.bind(h.controller.session_token) do
|
4
|
-
object.
|
22
|
+
object.roles
|
5
23
|
end
|
6
24
|
end
|
7
25
|
|
8
|
-
def
|
26
|
+
def cached_permissions
|
9
27
|
garner.bind(h.controller.session_token) do
|
10
|
-
|
28
|
+
permissions = []
|
29
|
+
cached_roles.each do |role|
|
30
|
+
permissions += role.permissions
|
31
|
+
end
|
32
|
+
permissions
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def account_permissions(account)
|
37
|
+
cached_permissions.select do |permission|
|
38
|
+
permission.links[:account].href == account.href
|
11
39
|
end
|
12
40
|
end
|
13
41
|
|
data/lib/aptible/rails/garner.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptible-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Macreery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_config
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/aptible/rails/decorators/operation_decorator.rb
|
191
191
|
- lib/aptible/rails/decorators/organization_decorator.rb
|
192
192
|
- lib/aptible/rails/decorators/resource_decorator.rb
|
193
|
+
- lib/aptible/rails/decorators/role_decorator.rb
|
193
194
|
- lib/aptible/rails/decorators/user_decorator.rb
|
194
195
|
- lib/aptible/rails/draper_extensions.rb
|
195
196
|
- lib/aptible/rails/garner.rb
|
@@ -224,3 +225,4 @@ specification_version: 4
|
|
224
225
|
summary: Rails helpers for Aptible service applications
|
225
226
|
test_files:
|
226
227
|
- spec/spec_helper.rb
|
228
|
+
has_rdoc:
|