Skip to content

Commit

Permalink
2.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
the-teacher committed Mar 23, 2014
1 parent d6a0b74 commit f36a5c0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def destroy
protected

def role_params
params.require(:role).permit(:name, :title, :description, :the_role)
params.require(:role).permit(:name, :title, :description, :the_role, :based_on_role)
end

def role_find
Expand Down
18 changes: 15 additions & 3 deletions app/models/concerns/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@ def has_section? section_name
end

included do
attr_accessor :based_on_role

has_many :users, dependent: TheRole.config.destroy_strategy
validates :name, presence: true, uniqueness: true
validates :title, presence: true, uniqueness: true
validates :description, presence: true

private

before_save do
self.name = name.to_slug_param(sep: '_')

rules_set = self.the_role
self.the_role = {}.to_json if rules_set.blank? # blank
self.the_role = rules_set.to_json if rules_set.is_a?(Hash) # Hash
rules_set = self.the_role
self.the_role = {}.to_json if rules_set.blank?
self.the_role = rules_set.to_json if rules_set.is_a?(Hash)
end

after_create do
unless based_on_role.blank?
if base_role = self.class.where(id: based_on_role).first
update_role base_role.to_hash
end
end
end
end

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ en:
name: Name of role (underscored latin string)
title: Title of role (text)
description: Description of role (text)
based_on_role: "New role will be based on:"
role:
role_name: 'Role name:'
title: 'Title:'
Expand Down
1 change: 1 addition & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ru:
name: Имя роли (строка из латинских символов + нижнее подчеркивание)
title: Заголовок роли
description: Описание роли
based_on_role: "Новая роль будет основана на:"
role:
role_name: 'Имя роли:'
title: 'Заголовок:'
Expand Down
2 changes: 1 addition & 1 deletion lib/the_role/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TheRole
VERSION = "2.5.2"
VERSION = "2.5.3"
end
7 changes: 6 additions & 1 deletion spec/dummy_app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ gem 'jbuilder', '~> 1.0.1'
# gem 'the_string_to_slug', path: "../../../the_string_to_slug"

gem 'the_role',
"~> 2.5.2"
# path: '../../'
"~> 2.5.3"

gem 'the_role_bootstrap3_ui',
# path: "path: '../../../../../the_role_bootstrap3_ui"
github: 'the-teacher/the_role_bootstrap3_ui',
branch: 'master'

group :development do
gem 'pry-rails'
end

group :test do
gem 'factory_girl_rails', '~> 4.0'
gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git', tag: 'v1.0.0'
Expand Down

0 comments on commit f36a5c0

Please sign in to comment.