bsm_oa 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Gemfile +6 -0
- data/Gemfile.lock +138 -142
- data/app/controllers/bsm_oa/accounts_controller.rb +19 -4
- data/app/controllers/bsm_oa/admin_controller.rb +5 -0
- data/app/controllers/bsm_oa/applications_controller.rb +36 -15
- data/app/controllers/bsm_oa/authorizations_controller.rb +7 -6
- data/app/controllers/bsm_oa/base_controller.rb +5 -0
- data/app/controllers/bsm_oa/roles_controller.rb +3 -4
- data/app/views/bsm_oa/applications/_application.html.erb +2 -2
- data/app/views/bsm_oa/applications/_inputs.html.erb +6 -11
- data/app/views/bsm_oa/applications/edit.html.erb +2 -2
- data/app/views/bsm_oa/applications/index.html.erb +1 -1
- data/app/views/bsm_oa/applications/new.html.erb +2 -2
- data/app/views/bsm_oa/applications/show.html.erb +40 -0
- data/app/views/bsm_oa/authorizations/_inputs.html.erb +2 -2
- data/app/views/bsm_oa/authorizations/edit.html.erb +1 -1
- data/app/views/bsm_oa/authorizations/new.html.erb +2 -3
- data/app/views/bsm_oa/roles/_inputs.html.erb +3 -4
- data/app/views/bsm_oa/roles/edit.html.erb +1 -1
- data/app/views/bsm_oa/roles/new.html.erb +1 -1
- data/app/views/bsm_oa/roles/show.html.erb +1 -1
- data/bsm_oa.gemspec +6 -11
- data/db/migrate/20150507113313_bsm_oa_create_doorkeeper_tables.rb +1 -1
- data/db/migrate/20150513155732_bsm_oa_create_tables.rb +1 -1
- data/lib/bsm_oa.rb +0 -3
- data/lib/bsm_oa/application.rb +31 -0
- data/lib/bsm_oa/authorization.rb +8 -15
- data/lib/bsm_oa/config.rb +5 -0
- data/lib/bsm_oa/engine.rb +2 -4
- data/lib/bsm_oa/role.rb +1 -1
- data/lib/bsm_oa/routes.rb +29 -3
- data/lib/bsm_oa/version.rb +1 -1
- data/spec/controllers/bsm_oa/accounts_controller_spec.rb +15 -12
- data/spec/controllers/bsm_oa/applications_controller_spec.rb +22 -28
- data/spec/controllers/bsm_oa/authorizations_controller_spec.rb +17 -22
- data/spec/controllers/bsm_oa/roles_controller_spec.rb +14 -16
- data/spec/factories.rb +1 -1
- data/spec/lib/bsm_oa/{application_mixin_spec.rb → application_spec.rb} +13 -9
- data/spec/lib/bsm_oa/authorization_spec.rb +5 -9
- data/spec/lib/bsm_oa/role_spec.rb +1 -1
- data/spec/spec_helper.rb +18 -8
- metadata +22 -104
- data/app/views/bsm_oa/accounts/show.json.jbuilder +0 -7
- data/app/views/bsm_oa/applications/_application.json.jbuilder +0 -1
- data/app/views/bsm_oa/applications/create.json.jbuilder +0 -1
- data/app/views/bsm_oa/applications/index.json.jbuilder +0 -1
- data/app/views/bsm_oa/applications/show.json.jbuilder +0 -1
- data/app/views/bsm_oa/applications/update.json.jbuilder +0 -1
- data/app/views/bsm_oa/authorizations/_authorization.json.jbuilder +0 -1
- data/app/views/bsm_oa/authorizations/index.json.jbuilder +0 -1
- data/app/views/bsm_oa/authorizations/toggle.json.jbuilder +0 -1
- data/lib/bsm_oa/application_mixin.rb +0 -37
@@ -1,9 +1,10 @@
|
|
1
1
|
module BsmOa
|
2
|
-
class AuthorizationsController <
|
2
|
+
class AuthorizationsController < AdminController
|
3
3
|
respond_to :html
|
4
4
|
respond_to :json, except: [:new, :edit]
|
5
5
|
respond_to :js, only: [:toggle]
|
6
|
-
|
6
|
+
|
7
|
+
before_action :redirect_to_index_on_html, only: [:show]
|
7
8
|
|
8
9
|
def index
|
9
10
|
@authorizations = apply_scopes(resource_scope)
|
@@ -33,19 +34,19 @@
|
|
33
34
|
def update
|
34
35
|
@authorization = resource_scope.find params[:id]
|
35
36
|
@authorization.update(permitted_params)
|
36
|
-
respond_with @authorization
|
37
|
+
respond_with @authorization
|
37
38
|
end
|
38
39
|
|
39
40
|
def toggle
|
40
41
|
@authorization = resource_scope.find params[:id]
|
41
|
-
@authorization.
|
42
|
+
@authorization.toggle_permission!(params[:permission])
|
42
43
|
respond_with @authorization
|
43
44
|
end
|
44
45
|
|
45
46
|
def destroy
|
46
47
|
@authorization = resource_scope.find params[:id]
|
47
48
|
@authorization.destroy
|
48
|
-
respond_with @authorization, location:
|
49
|
+
respond_with @authorization, location: @authorization.role
|
49
50
|
end
|
50
51
|
|
51
52
|
protected
|
@@ -65,7 +66,7 @@
|
|
65
66
|
end
|
66
67
|
|
67
68
|
def permitted_params
|
68
|
-
params.require(:
|
69
|
+
params.require(:bsm_oa_authorization).permit :application_id, :uid, :secret
|
69
70
|
end
|
70
71
|
|
71
72
|
def redirect_to_index_on_html
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module BsmOa
|
2
|
-
class RolesController <
|
2
|
+
class RolesController < AdminController
|
3
3
|
respond_to :html
|
4
4
|
respond_to :json, except: [:new, :edit]
|
5
|
-
|
6
|
-
has_scope :ordered, default: true, only: [:index]
|
5
|
+
has_scope :ordered, default: true, only: [:index]
|
7
6
|
|
8
7
|
def index
|
9
8
|
@roles = apply_scopes(resource_scope)
|
@@ -51,7 +50,7 @@ module BsmOa
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def permitted_params
|
54
|
-
params.require(:
|
53
|
+
params.require(:bsm_oa_role).permit :name, :description
|
55
54
|
end
|
56
55
|
|
57
56
|
end
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<span class="label label-info"><%= "#{pm}" %></span>
|
10
10
|
<% end %>
|
11
11
|
<td>
|
12
|
-
<%= link_to t('doorkeeper.applications.buttons.edit'),
|
13
|
-
<%= link_to 'Delete',
|
12
|
+
<%= link_to t('doorkeeper.applications.buttons.edit'), edit_doorkeeper_application_path(application), class: 'btn btn-default btn-xs' %>
|
13
|
+
<%= link_to 'Delete', application, data: { confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-default btn-xs'%>
|
14
14
|
</td>
|
15
15
|
</tr>
|
@@ -1,11 +1,6 @@
|
|
1
|
-
<%= f.
|
2
|
-
|
3
|
-
<%= f.
|
4
|
-
|
5
|
-
<%= f.
|
6
|
-
|
7
|
-
<%= f.input :redirect_uri, placeholder: "Enter redirect url"%>
|
8
|
-
|
9
|
-
<%= f.input :permissions_string, placeholder: "Enter comma separated permissions"%>
|
10
|
-
|
11
|
-
<%= f.button :submit %>
|
1
|
+
<%= f.text_field :name, placeholder: "Enter name"%>
|
2
|
+
<%= f.text_field :uid, placeholder: "Enter application UID"%>
|
3
|
+
<%= f.password_field :secret, placeholder: "Enter application secret"%>
|
4
|
+
<%= f.url_field :redirect_uri, placeholder: "Enter redirect url"%>
|
5
|
+
<%= f.text_field :permissions, placeholder: "Enter comma separated permissions"%>
|
6
|
+
<%= f.submit %>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<div class="page-header">
|
2
2
|
<div class="pull-right">
|
3
|
-
<%= link_to "← Back".html_safe,
|
3
|
+
<%= link_to "← Back".html_safe, bsm_oa_applications_path, class: 'btn btn-lg btn-default'%>
|
4
4
|
</div>
|
5
5
|
<h1>Edit Application</h1>
|
6
6
|
</div>
|
7
7
|
|
8
|
-
<%=
|
8
|
+
<%= form_for @application do |f| %>
|
9
9
|
<%= render 'inputs', f: f %>
|
10
10
|
<% end %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<div class="page-header">
|
2
2
|
<div class="pull-right">
|
3
|
-
<%= link_to 'New Application',
|
3
|
+
<%= link_to 'New Application', new_bsm_oa_application_path, class: 'btn btn-lg btn-primary' %>
|
4
4
|
</div>
|
5
5
|
<h1>Applications</h1>
|
6
6
|
</div>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<div class="page-header">
|
2
2
|
<div class="pull-right">
|
3
|
-
<%= link_to "← Back".html_safe,
|
3
|
+
<%= link_to "← Back".html_safe, bsm_oa_applications_path, class: 'btn btn-lg btn-default'%>
|
4
4
|
</div>
|
5
5
|
<h1>New Application</h1>
|
6
6
|
</div>
|
7
7
|
|
8
|
-
<%=
|
8
|
+
<%= form_for @application do |f| %>
|
9
9
|
<%= render 'inputs', f: f %>
|
10
10
|
<% end %>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<div class="page-header">
|
2
|
+
<div class="pull-right">
|
3
|
+
<%= link_to "← Back".html_safe, bsm_oa_applications_path, class: 'btn btn-lg btn-default'%>
|
4
|
+
</div>
|
5
|
+
<h1><%= @application.name %></h1>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<h3>Details</h3>
|
9
|
+
<div class="table-responsive">
|
10
|
+
<table class="table table-hover">
|
11
|
+
<tr>
|
12
|
+
<th>Name:</th>
|
13
|
+
<td><%= @application.name %></td>
|
14
|
+
</tr>
|
15
|
+
<tr>
|
16
|
+
<th>Callback URL:</th>
|
17
|
+
<td>
|
18
|
+
<%= @application.redirect_uri %>
|
19
|
+
</td>
|
20
|
+
</tr>
|
21
|
+
<tr>
|
22
|
+
<th>Permissions:</th>
|
23
|
+
<td>
|
24
|
+
<%= @application.permissions.to_sentence %>
|
25
|
+
</td>
|
26
|
+
</tr>
|
27
|
+
<tr>
|
28
|
+
<th>UID:</th>
|
29
|
+
<td>
|
30
|
+
<%= @application.uid %>
|
31
|
+
</td>
|
32
|
+
</tr>
|
33
|
+
<tr>
|
34
|
+
<th>Secret:</th>
|
35
|
+
<td>
|
36
|
+
<%= @application.secret %>
|
37
|
+
</td>
|
38
|
+
</tr>
|
39
|
+
</table>
|
40
|
+
</div>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
<%= f.
|
2
|
-
<%= f.
|
1
|
+
<%= f.collection_select :application_id, BsmOa::Application.ordered, :id, :name, prompt: true %>
|
2
|
+
<%= f.submit %>
|
@@ -5,7 +5,6 @@
|
|
5
5
|
<h1>New Authorization</h1>
|
6
6
|
</div>
|
7
7
|
|
8
|
-
<%=
|
9
|
-
<%=
|
10
|
-
<%= f.button :submit %>
|
8
|
+
<%= form_for [@parent, @authorization], url: bsm_oa_role_bsm_oa_authorizations_url do |f| %>
|
9
|
+
<%= render 'inputs', f: f %>
|
11
10
|
<% end %>
|
@@ -1,5 +1,4 @@
|
|
1
|
-
<%= f.
|
2
|
-
<%= f.
|
3
|
-
|
4
|
-
<%= f.button :submit %>
|
1
|
+
<%= f.text_field :name, placeholder: "Enter name" %>
|
2
|
+
<%= f.text_field :description, placeholder: "Enter description" %>
|
3
|
+
<%= f.submit %>
|
5
4
|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
<h3>
|
26
26
|
Authorizations
|
27
|
-
<%= link_to 'New',
|
27
|
+
<%= link_to 'New', [:new, @role, :bsm_oa_authorization], class: 'btn btn-sm btn-primary' %>
|
28
28
|
</h3>
|
29
29
|
<div class="table-responsive">
|
30
30
|
<table class="table table-hover">
|
data/bsm_oa.gemspec
CHANGED
@@ -16,22 +16,17 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
17
17
|
s.require_paths = ['lib']
|
18
18
|
|
19
|
-
s.add_dependency 'railties', '
|
20
|
-
s.add_dependency 'doorkeeper', '~>
|
21
|
-
s.add_dependency 'responders', '~> 2.
|
22
|
-
s.add_dependency 'jbuilder', '~> 2.2'
|
23
|
-
s.add_dependency 'bsm-models'
|
19
|
+
s.add_dependency 'railties', '~> 5.0'
|
20
|
+
s.add_dependency 'doorkeeper', '~> 4.2.0'
|
21
|
+
s.add_dependency 'responders', '~> 2.1'
|
24
22
|
s.add_dependency 'has_scope', '~> 0.6'
|
25
|
-
s.add_dependency 'simple_form', '~> 3.1'
|
26
|
-
s.add_dependency 'jquery-rails'
|
27
23
|
|
28
|
-
s.add_development_dependency 'rails', '>=
|
29
|
-
s.add_development_dependency 'combustion', '~> 0.
|
24
|
+
s.add_development_dependency 'rails', '>= 5.0'
|
25
|
+
s.add_development_dependency 'combustion', '~> 0.7.0'
|
30
26
|
s.add_development_dependency 'rspec-rails'
|
31
27
|
s.add_development_dependency 'factory_girl'
|
32
|
-
s.add_development_dependency 'json_spec'
|
33
28
|
s.add_development_dependency 'faker'
|
34
|
-
s.add_development_dependency 'shoulda-matchers'
|
35
29
|
s.add_development_dependency 'database_cleaner'
|
36
30
|
s.add_development_dependency 'sqlite3'
|
31
|
+
s.add_development_dependency 'rails-controller-testing'
|
37
32
|
end
|
data/lib/bsm_oa.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module BsmOa
|
2
|
+
class Application < Doorkeeper::Application
|
3
|
+
|
4
|
+
has_many :authorizations, class_name: 'BsmOa::Authorization', inverse_of: :application, dependent: :destroy
|
5
|
+
has_many :roles, inverse_of: :applications, class_name: 'BsmOa::Role', through: :authorizations, foreign_key: :role_id
|
6
|
+
|
7
|
+
serialize :permissions, JSON
|
8
|
+
validate :must_have_simple_word_permissions
|
9
|
+
|
10
|
+
before_validation :normalize_permissions!
|
11
|
+
|
12
|
+
scope :ordered, -> { order(:name) }
|
13
|
+
|
14
|
+
# @param [Array|String] permissions
|
15
|
+
def permissions=(vals)
|
16
|
+
super Array.wrap(vals).map {|s| s.to_s.split(/[\s,]+/) }.flatten
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def must_have_simple_word_permissions
|
22
|
+
errors.add :permissions, :invalid if permissions.any? {|pm| pm =~ /[^a-z0-9]/ }
|
23
|
+
end
|
24
|
+
|
25
|
+
def normalize_permissions!
|
26
|
+
self.permissions = Array.wrap(permissions).reject(&:blank?).map(&:strip).map(&:downcase).uniq
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/lib/bsm_oa/authorization.rb
CHANGED
@@ -4,10 +4,10 @@ module BsmOa
|
|
4
4
|
|
5
5
|
# ---> ASSOCIATIONS
|
6
6
|
belongs_to :role, inverse_of: :authorizations
|
7
|
-
belongs_to :application, inverse_of: :authorizations, class_name:
|
7
|
+
belongs_to :application, inverse_of: :authorizations, class_name: 'BsmOa::Application', foreign_key: :application_id
|
8
8
|
|
9
9
|
# ---> ATTRIBUTES
|
10
|
-
serialize :permissions,
|
10
|
+
serialize :permissions, JSON
|
11
11
|
attr_readonly :application_id, :role_id, :application
|
12
12
|
|
13
13
|
# ---> VALIDATIONS
|
@@ -21,26 +21,19 @@ module BsmOa
|
|
21
21
|
scope :ordered, -> { order(id: :desc) }
|
22
22
|
|
23
23
|
# @param [String] name permission name
|
24
|
-
def
|
25
|
-
|
26
|
-
self.permissions = permissions - [name]
|
27
|
-
else
|
28
|
-
self.permissions = permissions + [name]
|
29
|
-
end
|
30
|
-
save
|
31
|
-
end
|
32
|
-
|
33
|
-
def permissions_string=(str)
|
34
|
-
self.permissions = str.split("\s")
|
24
|
+
def toggle_permission!(name)
|
25
|
+
update permissions: (permissions.include?(name) ? permissions - [name] : permissions + [name])
|
35
26
|
end
|
36
27
|
|
37
|
-
|
38
|
-
|
28
|
+
# @param [Array|String] permissions
|
29
|
+
def permissions=(vals)
|
30
|
+
super Array.wrap(vals).map {|s| s.to_s.split(/[\s,]+/) }.flatten
|
39
31
|
end
|
40
32
|
|
41
33
|
protected
|
42
34
|
|
43
35
|
def normalize_permissions!
|
36
|
+
self.permissions ||= []
|
44
37
|
self.permissions = permissions.reject(&:blank?).map(&:strip).map(&:downcase).uniq
|
45
38
|
self.permissions &= application.permissions if application
|
46
39
|
end
|
data/lib/bsm_oa/config.rb
CHANGED
data/lib/bsm_oa/engine.rb
CHANGED
@@ -15,11 +15,9 @@ module BsmOa
|
|
15
15
|
|
16
16
|
initializer "bsm_oa.models" do
|
17
17
|
ActiveSupport.on_load(:active_record) do
|
18
|
-
require 'bsm_oa/
|
19
|
-
require 'bsm_oa/authorization'
|
18
|
+
require 'bsm_oa/application'
|
20
19
|
require 'bsm_oa/role'
|
21
|
-
|
22
|
-
Doorkeeper::Application.send :include, ApplicationMixin
|
20
|
+
require 'bsm_oa/authorization'
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
data/lib/bsm_oa/role.rb
CHANGED
@@ -4,7 +4,7 @@ module BsmOa
|
|
4
4
|
|
5
5
|
# ---> ASSOCIATIONS
|
6
6
|
has_many :authorizations, inverse_of: :role, dependent: :destroy
|
7
|
-
has_many :applications, inverse_of: :roles, class_name:
|
7
|
+
has_many :applications, inverse_of: :roles, class_name: 'BsmOa::Application', through: :authorizations, foreign_key: :application_id
|
8
8
|
|
9
9
|
# ---> VALIDATIONS
|
10
10
|
validates :name,
|
data/lib/bsm_oa/routes.rb
CHANGED
@@ -8,14 +8,40 @@ module BsmOa
|
|
8
8
|
module Helper
|
9
9
|
|
10
10
|
def mount_bsm_oa
|
11
|
-
|
12
|
-
|
11
|
+
mount_bsm_oa_me
|
12
|
+
mount_bsm_oa_admin
|
13
|
+
mount_bsm_oa_callbacks
|
14
|
+
end
|
15
|
+
|
16
|
+
def mount_bsm_oa_admin
|
17
|
+
mount_bsm_oa_applications
|
18
|
+
mount_bsm_oa_roles
|
19
|
+
mount_bsm_oa_authorizations
|
20
|
+
end
|
21
|
+
|
22
|
+
def mount_bsm_oa_me
|
23
|
+
get 'me(.:format)', to: BsmOa::AccountsController.action(:show), as: :bsm_oa_me
|
24
|
+
end
|
25
|
+
|
26
|
+
def mount_bsm_oa_applications
|
27
|
+
resources :applications, controller: 'bsm_oa/applications', as: :bsm_oa_applications
|
28
|
+
end
|
29
|
+
|
30
|
+
def mount_bsm_oa_roles
|
31
|
+
resources :roles, controller: 'bsm_oa/roles', as: :bsm_oa_roles
|
32
|
+
end
|
33
|
+
|
34
|
+
def mount_bsm_oa_authorizations
|
35
|
+
resources :roles, only: [], as: :bsm_oa_roles do
|
13
36
|
resources :authorizations, controller: 'bsm_oa/authorizations', as: :bsm_oa_authorizations, shallow: true do
|
14
37
|
put :toggle, on: :member, path: "toggle/:permission"
|
15
38
|
end
|
16
39
|
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def mount_bsm_oa_callbacks
|
17
43
|
use_doorkeeper do
|
18
|
-
|
44
|
+
skip_controllers :applications, :authorized_applications
|
19
45
|
end
|
20
46
|
end
|
21
47
|
|