releaf-permissions 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +24 -0
- data/app/assets/stylesheets/releaf/controllers/releaf/permissions/sessions.scss +70 -0
- data/app/builders/releaf/permissions/profile/form_builder.rb +7 -0
- data/app/builders/releaf/permissions/roles/form_builder.rb +28 -0
- data/app/builders/releaf/permissions/roles/table_builder.rb +16 -0
- data/app/builders/releaf/permissions/users/form_builder.rb +11 -0
- data/app/builders/releaf/permissions/users/table_builder.rb +11 -0
- data/app/controllers/releaf/permissions/home_controller.rb +32 -0
- data/app/controllers/releaf/permissions/profile_controller.rb +56 -0
- data/app/controllers/releaf/permissions/roles_controller.rb +7 -0
- data/app/controllers/releaf/permissions/sessions_controller.rb +34 -0
- data/app/controllers/releaf/permissions/users_controller.rb +19 -0
- data/app/lib/releaf/permissions/access_control.rb +36 -0
- data/app/models/releaf/permissions/permission.rb +6 -0
- data/app/models/releaf/permissions/role.rb +38 -0
- data/app/models/releaf/permissions/user.rb +31 -0
- data/app/views/releaf/permissions/sessions/new.html.haml +14 -0
- data/lib/releaf-permissions.rb +32 -0
- data/lib/releaf/permissions/builders_autoload.rb +11 -0
- data/lib/releaf/permissions/devise_component.rb +8 -0
- data/lib/releaf/permissions/engine.rb +24 -0
- data/lib/releaf/permissions/profile_component.rb +9 -0
- data/lib/releaf/permissions/roles_component.rb +7 -0
- data/lib/releaf/permissions/users_component.rb +7 -0
- data/releaf-permissions.gemspec +19 -0
- data/spec/builders/profile/form_builder_spec.rb +18 -0
- data/spec/builders/roles/form_builder_spec.rb +38 -0
- data/spec/builders/roles/table_builder_spec.rb +29 -0
- data/spec/builders/users/form_builder_spec.rb +23 -0
- data/spec/builders/users/table_builder_spec.rb +21 -0
- data/spec/controllers/permissions/home_controller_spec.rb +52 -0
- data/spec/controllers/permissions/profile_controller_spec.rb +66 -0
- data/spec/controllers/permissions/users_controller_spec.rb +28 -0
- data/spec/features/profile_updating_spec.rb +35 -0
- data/spec/features/roles_spec.rb +64 -0
- data/spec/features/users_spec.rb +107 -0
- data/spec/lib/access_control_spec.rb +81 -0
- data/spec/models/permissions/role_spec.rb +41 -0
- data/spec/models/permissions/user_spec.rb +23 -0
- metadata +124 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
feature "Roles management", js: true do
|
3
|
+
background do
|
4
|
+
auth_as_user
|
5
|
+
@role = Releaf::Permissions::Role.first
|
6
|
+
end
|
7
|
+
|
8
|
+
scenario "Role search", focus: true do
|
9
|
+
create(:admin_role, name: 'super role')
|
10
|
+
visit releaf_permissions_roles_path
|
11
|
+
expect(page).to have_content @role.name
|
12
|
+
expect(page).to have_content 'super role'
|
13
|
+
search "super"
|
14
|
+
expect(page).to have_no_content @role.name
|
15
|
+
expect(page).to have_content 'super role'
|
16
|
+
end
|
17
|
+
|
18
|
+
scenario "User creates a new role" do
|
19
|
+
visit releaf_permissions_roles_path
|
20
|
+
create_resource do
|
21
|
+
fill_in("Name", with: "second role")
|
22
|
+
select('Releaf/content/nodes', from: 'Default controller')
|
23
|
+
end
|
24
|
+
visit releaf_permissions_roles_path
|
25
|
+
expect(page).to have_content "second role"
|
26
|
+
end
|
27
|
+
|
28
|
+
scenario "User updates an existing role" do
|
29
|
+
visit releaf_permissions_roles_path
|
30
|
+
click_link @role.name
|
31
|
+
update_resource do
|
32
|
+
fill_in("Name", with: "new name")
|
33
|
+
end
|
34
|
+
|
35
|
+
visit releaf_permissions_roles_path
|
36
|
+
expect(page).to have_content "new name"
|
37
|
+
end
|
38
|
+
|
39
|
+
scenario "User changes the default controller of a role" do
|
40
|
+
visit releaf_permissions_roles_path
|
41
|
+
click_link @role.name
|
42
|
+
update_resource do
|
43
|
+
select('Admin/books', from: 'Default controller')
|
44
|
+
end
|
45
|
+
|
46
|
+
expect(page).to have_select('Default controller', selected: 'Admin/books')
|
47
|
+
end
|
48
|
+
|
49
|
+
scenario "User changes permissions of a role controller" do
|
50
|
+
visit releaf_permissions_roles_path
|
51
|
+
click_link @role.name
|
52
|
+
update_resource do
|
53
|
+
uncheck('Admin/books')
|
54
|
+
end
|
55
|
+
|
56
|
+
Releaf.application.config.available_controllers.each do |controller|
|
57
|
+
if controller == "admin/books"
|
58
|
+
expect(page).to have_unchecked_field(I18n.t(controller, scope: 'admin.controllers'))
|
59
|
+
else
|
60
|
+
expect(page).to have_checked_field(I18n.t(controller, scope: 'admin.controllers'))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
feature "Users", js: true do
|
3
|
+
let!(:user){ create(:user, email: "admin@example.com") }
|
4
|
+
let!(:simple_user){ create(:content_user, email: "simple@example.com") }
|
5
|
+
|
6
|
+
describe "users CRUD" do
|
7
|
+
background do
|
8
|
+
visit "/admin"
|
9
|
+
within("form.login") do
|
10
|
+
fill_in 'Email', with: user.email
|
11
|
+
fill_in 'Password', with: user.password
|
12
|
+
end
|
13
|
+
click_button 'Sign in'
|
14
|
+
expect(page).to have_css('body > header form.sign-out button')
|
15
|
+
end
|
16
|
+
|
17
|
+
scenario "new user creation", js: true do
|
18
|
+
visit releaf_permissions_users_path
|
19
|
+
create_resource do
|
20
|
+
fill_in 'Name', with: "John"
|
21
|
+
fill_in 'Surname', with: "Appleseed"
|
22
|
+
fill_in 'Email', with: "john@example.com"
|
23
|
+
fill_in 'Password', with: "password", match: :prefer_exact
|
24
|
+
fill_in 'Password confirmation', with: "password", match: :prefer_exact
|
25
|
+
|
26
|
+
expect(page).to have_select('Locale', options: ["", "En", "Lv"])
|
27
|
+
select 'En', from: 'Locale'
|
28
|
+
end
|
29
|
+
|
30
|
+
expect(page).to have_content 'John Appleseed'
|
31
|
+
visit '/admin/users'
|
32
|
+
expect(page).to have_content 'john@example.com'
|
33
|
+
|
34
|
+
visit (releaf_permissions_users_path)
|
35
|
+
open_toolbox_dialog("Delete", Releaf::Permissions::User.last)
|
36
|
+
click_button 'Yes'
|
37
|
+
expect(page).not_to have_content 'john@example.com'
|
38
|
+
end
|
39
|
+
|
40
|
+
scenario "user search" do
|
41
|
+
visit '/admin/users'
|
42
|
+
expect(page).to have_content 'simple@example.com'
|
43
|
+
search "admin@example.com"
|
44
|
+
expect(page).not_to have_content 'simple@example.com'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "login as user procedure" do
|
49
|
+
background do
|
50
|
+
visit "/admin"
|
51
|
+
within("form.login") do
|
52
|
+
fill_in 'Email', with: user.email
|
53
|
+
fill_in 'Password', with: user.password
|
54
|
+
end
|
55
|
+
click_button 'Sign in'
|
56
|
+
end
|
57
|
+
|
58
|
+
scenario "user page content" do
|
59
|
+
expect(page).to have_css('body > header form.sign-out button')
|
60
|
+
expect(page).to have_content 'Releaf/content'
|
61
|
+
expect(page).to have_content 'Permissions'
|
62
|
+
expect(page).to have_content 'Releaf/i18n database/translations'
|
63
|
+
# admin/users index view
|
64
|
+
expect(page).to have_content 'admin@example.com'
|
65
|
+
expect(page).to have_content 'simple@example.com'
|
66
|
+
end
|
67
|
+
|
68
|
+
scenario "logout sequence" do
|
69
|
+
find('body > header form.sign-out button').click
|
70
|
+
|
71
|
+
expect(page).to have_content 'Welcome to Releaf'
|
72
|
+
|
73
|
+
visit "/admin"
|
74
|
+
expect(page).to have_content 'Sign in'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "login as simple user procedure" do
|
79
|
+
background do
|
80
|
+
visit "/admin"
|
81
|
+
within("form.login") do
|
82
|
+
fill_in 'Email', with: simple_user.email
|
83
|
+
fill_in 'Password', with: simple_user.password
|
84
|
+
end
|
85
|
+
click_button 'Sign in'
|
86
|
+
end
|
87
|
+
|
88
|
+
scenario "user page content" do
|
89
|
+
expect(page).to have_css('body > header form.sign-out button')
|
90
|
+
expect(page).to have_content 'Releaf/content'
|
91
|
+
end
|
92
|
+
|
93
|
+
scenario "translations module access denied" do
|
94
|
+
visit "/admin/translations"
|
95
|
+
expect(page).to have_content 'You are not authorized to access translations'
|
96
|
+
end
|
97
|
+
|
98
|
+
scenario "logout sequence" do
|
99
|
+
find('body > header form.sign-out button').click
|
100
|
+
|
101
|
+
expect(page).to have_content 'Welcome to Releaf'
|
102
|
+
|
103
|
+
visit "/admin"
|
104
|
+
expect(page).to have_content 'Sign in'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
describe Releaf::Permissions::AccessControl do
|
4
|
+
class AcessControllDummyController < ActionController::Base; end
|
5
|
+
|
6
|
+
let(:controller){ AcessControllDummyController.new }
|
7
|
+
let(:role){ Releaf::Permissions::Role.new }
|
8
|
+
let(:user){ Releaf::Permissions::User.new(role: role) }
|
9
|
+
subject{ described_class.new(controller: controller) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(controller).to receive(:current_releaf_permissions_user).and_return(user)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#controller_permitted" do
|
16
|
+
before do
|
17
|
+
allow(subject).to receive(:permitted_controllers).and_return(["a", "b"])
|
18
|
+
allow(role).to receive(:controller_permitted?).with("c").and_return(true)
|
19
|
+
allow(role).to receive(:controller_permitted?).with("d").and_return(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when permitted controllers contains given controller" do
|
23
|
+
it "returns true" do
|
24
|
+
expect(subject.controller_permitted?("a")).to be true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when user role permit given controller" do
|
29
|
+
it "returns true" do
|
30
|
+
expect(subject.controller_permitted?("c")).to be true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when neither permitted controllers contains given controller or user role permit given controller" do
|
35
|
+
it "returns true" do
|
36
|
+
expect(subject.controller_permitted?("d")).to be false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#current_controller_name" do
|
42
|
+
it "returns normalized access controller assign controller name" do
|
43
|
+
expect(subject.current_controller_name).to eq("acess_controll_dummy")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#user" do
|
48
|
+
it "returns current controller devise user instance" do
|
49
|
+
expect(subject.user).to eq(user)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#permitted_controllers" do
|
54
|
+
it "returns array with `releaf/permissions/home` and `releaf/core/errors` as permanently permitted controllers" do
|
55
|
+
expect(subject.permitted_controllers).to match_array(['releaf/permissions/home', 'releaf/core/errors'])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#authorized?" do
|
60
|
+
it "returns whether devise has signed in current user" do
|
61
|
+
expect(controller).to receive(:releaf_permissions_user_signed_in?).and_return(true)
|
62
|
+
expect(subject.authorized?).to be true
|
63
|
+
expect(controller).to receive(:releaf_permissions_user_signed_in?).and_return(false)
|
64
|
+
expect(subject.authorized?).to be false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#authenticate!" do
|
69
|
+
it "returns whether devise has signed in current user" do
|
70
|
+
expect(controller).to receive(:authenticate_releaf_permissions_user!)
|
71
|
+
subject.authenticate!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#devise_model_name" do
|
76
|
+
it "returns normalized Releaf devise model name" do
|
77
|
+
allow(Releaf.application.config).to receive(:devise_for).and_return("asdasd/asdasd")
|
78
|
+
expect(subject.devise_model_name).to eq("asdasd_asdasd")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
describe Releaf::Permissions::Role do
|
4
|
+
describe 'validations' do
|
5
|
+
it { is_expected.to validate_presence_of(:name) }
|
6
|
+
it { is_expected.to validate_presence_of(:default_controller) }
|
7
|
+
it { is_expected.to validate_uniqueness_of(:name).case_insensitive }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'associations' do
|
11
|
+
it { is_expected.to have_many(:users).dependent(:restrict_with_exception) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#controller_permitted?" do
|
15
|
+
before do
|
16
|
+
allow(subject).to receive(:allowed_controllers).and_return(["a", "b"])
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when given controller name exists within permissions" do
|
20
|
+
it "returns true" do
|
21
|
+
expect(subject.controller_permitted?("a")).to be true
|
22
|
+
expect(subject.controller_permitted?("b")).to be true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when given controller name does not exist within permissions" do
|
27
|
+
it "returns false" do
|
28
|
+
expect(subject.controller_permitted?("c")).to be false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#allowed_controllers" do
|
34
|
+
it "returns array of roles allowed controllers" do
|
35
|
+
subject.permissions.build(permission: "controller.a")
|
36
|
+
subject.permissions.build(permission: "controller.x")
|
37
|
+
subject.permissions.build(permission: "export.some_data")
|
38
|
+
expect(subject.allowed_controllers).to match_array(["a", "x"])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
describe Releaf::Permissions::User do
|
4
|
+
describe 'validations' do
|
5
|
+
it { is_expected.to validate_presence_of(:name) }
|
6
|
+
it { is_expected.to validate_presence_of(:surname) }
|
7
|
+
it { is_expected.to validate_presence_of(:role) }
|
8
|
+
it { is_expected.to validate_presence_of(:locale) }
|
9
|
+
it { is_expected.to validate_presence_of(:email) }
|
10
|
+
it { create(:user); is_expected.to validate_uniqueness_of(:email).case_insensitive }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'associations' do
|
14
|
+
it { is_expected.to belong_to(:role) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#display_name" do
|
18
|
+
let(:user){ FactoryGirl.create(:user) }
|
19
|
+
it "returns concated name and surname" do
|
20
|
+
expect(user.display_name).to eq(user.name + " " + user.surname)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: releaf-permissions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CubeSystems
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: releaf-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: devise
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Admin/role subsystem for releaf
|
42
|
+
email: info@cubesystems.lv
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- app/assets/stylesheets/releaf/controllers/releaf/permissions/sessions.scss
|
49
|
+
- app/builders/releaf/permissions/profile/form_builder.rb
|
50
|
+
- app/builders/releaf/permissions/roles/form_builder.rb
|
51
|
+
- app/builders/releaf/permissions/roles/table_builder.rb
|
52
|
+
- app/builders/releaf/permissions/users/form_builder.rb
|
53
|
+
- app/builders/releaf/permissions/users/table_builder.rb
|
54
|
+
- app/controllers/releaf/permissions/home_controller.rb
|
55
|
+
- app/controllers/releaf/permissions/profile_controller.rb
|
56
|
+
- app/controllers/releaf/permissions/roles_controller.rb
|
57
|
+
- app/controllers/releaf/permissions/sessions_controller.rb
|
58
|
+
- app/controllers/releaf/permissions/users_controller.rb
|
59
|
+
- app/lib/releaf/permissions/access_control.rb
|
60
|
+
- app/models/releaf/permissions/permission.rb
|
61
|
+
- app/models/releaf/permissions/role.rb
|
62
|
+
- app/models/releaf/permissions/user.rb
|
63
|
+
- app/views/releaf/permissions/sessions/new.html.haml
|
64
|
+
- lib/releaf-permissions.rb
|
65
|
+
- lib/releaf/permissions/builders_autoload.rb
|
66
|
+
- lib/releaf/permissions/devise_component.rb
|
67
|
+
- lib/releaf/permissions/engine.rb
|
68
|
+
- lib/releaf/permissions/profile_component.rb
|
69
|
+
- lib/releaf/permissions/roles_component.rb
|
70
|
+
- lib/releaf/permissions/users_component.rb
|
71
|
+
- releaf-permissions.gemspec
|
72
|
+
- spec/builders/profile/form_builder_spec.rb
|
73
|
+
- spec/builders/roles/form_builder_spec.rb
|
74
|
+
- spec/builders/roles/table_builder_spec.rb
|
75
|
+
- spec/builders/users/form_builder_spec.rb
|
76
|
+
- spec/builders/users/table_builder_spec.rb
|
77
|
+
- spec/controllers/permissions/home_controller_spec.rb
|
78
|
+
- spec/controllers/permissions/profile_controller_spec.rb
|
79
|
+
- spec/controllers/permissions/users_controller_spec.rb
|
80
|
+
- spec/features/profile_updating_spec.rb
|
81
|
+
- spec/features/roles_spec.rb
|
82
|
+
- spec/features/users_spec.rb
|
83
|
+
- spec/lib/access_control_spec.rb
|
84
|
+
- spec/models/permissions/role_spec.rb
|
85
|
+
- spec/models/permissions/user_spec.rb
|
86
|
+
homepage: https://github.com/cubesystems/releaf
|
87
|
+
licenses: []
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.8
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Built-in admin and role support for releaf
|
109
|
+
test_files:
|
110
|
+
- spec/builders/profile/form_builder_spec.rb
|
111
|
+
- spec/builders/roles/form_builder_spec.rb
|
112
|
+
- spec/builders/roles/table_builder_spec.rb
|
113
|
+
- spec/builders/users/form_builder_spec.rb
|
114
|
+
- spec/builders/users/table_builder_spec.rb
|
115
|
+
- spec/controllers/permissions/home_controller_spec.rb
|
116
|
+
- spec/controllers/permissions/profile_controller_spec.rb
|
117
|
+
- spec/controllers/permissions/users_controller_spec.rb
|
118
|
+
- spec/features/profile_updating_spec.rb
|
119
|
+
- spec/features/roles_spec.rb
|
120
|
+
- spec/features/users_spec.rb
|
121
|
+
- spec/lib/access_control_spec.rb
|
122
|
+
- spec/models/permissions/role_spec.rb
|
123
|
+
- spec/models/permissions/user_spec.rb
|
124
|
+
has_rdoc:
|