adminpanel 1.2.9 → 1.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/Gemfile +1 -0
  2. data/adminpanel.gemspec +1 -0
  3. data/app/controllers/adminpanel/analytics_controller.rb +1 -1
  4. data/app/controllers/adminpanel/application_controller.rb +6 -6
  5. data/app/controllers/adminpanel/categories_controller.rb +17 -8
  6. data/app/controllers/adminpanel/galleries_controller.rb +2 -0
  7. data/app/controllers/adminpanel/sections_controller.rb +2 -0
  8. data/app/controllers/adminpanel/sessions_controller.rb +2 -2
  9. data/app/controllers/adminpanel/users_controller.rb +2 -0
  10. data/app/helpers/adminpanel/custom_form_builder.rb +24 -0
  11. data/app/helpers/adminpanel/rest_actions_helper.rb +26 -9
  12. data/app/helpers/adminpanel/shared_pages_helper.rb +2 -1
  13. data/app/models/adminpanel/group.rb +6 -0
  14. data/app/models/adminpanel/user.rb +48 -5
  15. data/app/views/adminpanel/categories/_categories_table.html.erb +3 -2
  16. data/app/views/adminpanel/categories/_category_form.html.erb +4 -4
  17. data/app/views/adminpanel/categories/create.js.erb +2 -1
  18. data/app/views/adminpanel/categories/index.html.erb +1 -1
  19. data/app/views/adminpanel/categories/new.js.erb +2 -1
  20. data/app/views/layouts/_side_menu.html.erb +20 -18
  21. data/app/views/layouts/_top_bar.html.erb +1 -1
  22. data/app/views/shared/_form_fields.html.erb +57 -5
  23. data/app/views/shared/_modal.html.erb +8 -0
  24. data/app/views/shared/_remote_form_fields.html.erb +12 -0
  25. data/app/views/shared/create_belongs_to.js.erb +5 -0
  26. data/app/views/shared/create_has_many.js.erb +5 -0
  27. data/app/views/shared/edit.html.erb +1 -0
  28. data/app/views/shared/new.html.erb +15 -4
  29. data/app/views/shared/new.js.erb +2 -0
  30. data/config/locales/es.yml +5 -3
  31. data/lib/adminpanel.rb +1 -0
  32. data/lib/adminpanel/active_record/adminpanel_extension.rb +0 -4
  33. data/lib/adminpanel/version.rb +1 -1
  34. data/lib/generators/adminpanel/initialize/initialize_generator.rb +11 -0
  35. data/lib/generators/adminpanel/initialize/templates/ability.rb +31 -0
  36. data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +7 -7
  37. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +9 -1
  38. data/lib/tasks/adminpanel/adminpanel.rake +2 -1
  39. data/spec/dummy/app/models/ability.rb +31 -0
  40. data/spec/dummy/app/models/adminpanel/category.rb +4 -1
  41. data/spec/features/authentication_pages_spec.rb +6 -5
  42. data/spec/features/galleries_pages_spec.rb +3 -1
  43. data/spec/features/section_pages_spec.rb +2 -1
  44. data/spec/features/shared_pages_spec.rb +66 -22
  45. data/spec/generators/gallery_generator_spec.rb +3 -3
  46. data/spec/generators/resource_generator_spec.rb +3 -3
  47. data/spec/models/gallery_spec.rb +3 -1
  48. data/spec/models/section_spec.rb +12 -11
  49. data/spec/models/user_spec.rb +6 -2
  50. data/spec/spec_helper.rb +5 -2
  51. data/spec/support/define_factory_models.rb +6 -0
  52. data/spec/support/helper_methods.rb +2 -1
  53. data/spec/support/test_database.rb +7 -0
  54. data/spec/tasks/adminpanel_rake_spec.rb +1 -0
  55. metadata +53 -32
  56. data/spec/dummy/app/controllers/adminpanel/categories_controller.rb +0 -4
  57. data/spec/models/product_spec.rb +0 -39
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ gem "bcrypt-ruby", "~> 3.0.0"
11
11
  gem "rails-i18n", "~> 3.0.0"
12
12
  gem "inherited_resources", "~> 1.3.1"
13
13
  gem "google-api-client", "~> 0.7.1"
14
+ gem "cancan", "~> 1.6.10"
14
15
 
15
16
  group :test do
16
17
  gem "bundler", "~> 1.3"
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "bcrypt-ruby", "~> 3.0.0"
27
27
  spec.add_dependency "rails-i18n", "~> 3.0.0"
28
28
  spec.add_dependency "inherited_resources", "~> 1.3.1"
29
+ spec.add_dependency "cancan", "~> 1.6.10"
29
30
  spec.add_dependency "google-api-client", "~> 0.7.1"
30
31
 
31
32
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -1,6 +1,6 @@
1
1
  module Adminpanel
2
2
  class AnalyticsController < Adminpanel::ApplicationController
3
-
3
+ authorize_resource :class => false
4
4
  skip_before_filter :set_model
5
5
 
6
6
  API_VERSION = 'v3'
@@ -7,13 +7,17 @@ module Adminpanel
7
7
  include SessionsHelper
8
8
  include RestActionsHelper
9
9
 
10
- layout "admin"
10
+ layout 'admin'
11
11
 
12
12
  before_filter :signed_in_user, :set_model
13
13
 
14
+ rescue_from CanCan::AccessDenied do |exception|
15
+ sign_out
16
+ redirect_to signin_path, :alert => I18n.t('authentication.not_authorized')
17
+ end
14
18
 
15
19
  def signed_in_user
16
- redirect_to signin_url, :notice => "Favor de Iniciar sesion" unless signed_in?
20
+ redirect_to signin_url, :notice => I18n.t("authentication.welcome") unless signed_in?
17
21
  end
18
22
 
19
23
  def set_model
@@ -24,9 +28,5 @@ module Adminpanel
24
28
  sign_out
25
29
  super
26
30
  end
27
-
28
- # def get_menu_elements
29
- # @menu_items = menu_items
30
- # end
31
31
  end
32
32
  end
@@ -1,5 +1,7 @@
1
1
  module Adminpanel
2
2
  class CategoriesController < ApplicationController
3
+ load_and_authorize_resource
4
+
3
5
  def index
4
6
  @categories = Category.all
5
7
  end
@@ -8,30 +10,37 @@ module Adminpanel
8
10
  set_collections
9
11
  new! do |format|
10
12
  format.html { render "shared/new" }
11
- format.js {render :locals => {:category => resource, :model => params[:model]}}
13
+ format.js do
14
+ render :locals => {:resource => resource}
15
+ end
12
16
  end
13
17
  end
14
18
 
15
19
 
16
20
  def create
21
+ params.merge({:model_name => params[:model_name]}) if params[:model_name].present?
22
+ params.merge({:model => params[:model]}) if params[:model].present?
23
+ params.merge({:currentcontroller => params[:currentcontroller]}) if params[:currentcontroller].present?
24
+
17
25
  create! do |success, failure|
18
26
  success.html do
19
- flash.now[:success] = I18n.t("action.save_success")
20
- # render "shared/index"
27
+ flash[:success] = I18n.t("action.save_success")
21
28
  redirect_to categories_path
22
29
  end
23
30
  failure.html do
24
31
  set_collections
25
32
  render "shared/new"
26
33
  end
27
-
28
34
  success.js do
29
- render :locals => {:category => resource }
30
-
35
+ if params[:currentcontroller] == 'adminpanel/categories'
36
+ render 'create', :locals => {:category => resource}
37
+ else
38
+ render 'shared/create_has_many', :locals => {:resource => resource}
39
+ end
31
40
  end
32
41
  failure.js do
33
42
  set_collections
34
- render "new", :locals => {:category => resource, :model => resource.model }, :formats => [:js]
43
+ render "new", :locals => {:resource => resource }
35
44
 
36
45
  end
37
46
  end
@@ -49,7 +58,7 @@ module Adminpanel
49
58
  def update
50
59
  update! do |success, failure|
51
60
  success.html do
52
- flash.now[:success] = I18n.t("action.save_success")
61
+ flash[:success] = I18n.t("action.save_success")
53
62
  # render "shared/index"
54
63
  redirect_to categories_path
55
64
  end
@@ -1,5 +1,7 @@
1
1
  module Adminpanel
2
2
  class GalleriesController < Adminpanel::ApplicationController
3
+ load_and_authorize_resource
4
+
3
5
  def index
4
6
  @galleries = Gallery.find(:all)
5
7
  end
@@ -1,5 +1,7 @@
1
1
  module Adminpanel
2
2
  class SectionsController < Adminpanel::ApplicationController
3
+ load_and_authorize_resource
4
+
3
5
  def new
4
6
  @section = Section.new
5
7
  end
@@ -15,10 +15,10 @@ module Adminpanel
15
15
  user = User.find_by_email(params[:session][:email].downcase)
16
16
  if user && user.authenticate(params[:session][:password])
17
17
  sign_in user
18
- flash[:success] = I18n.t("authentication.signin success")
18
+ flash[:success] = I18n.t("authentication.signin_success")
19
19
  redirect_to root_url
20
20
  else
21
- flash.now[:error] = I18n.t("authentication.signin error")
21
+ flash.now[:error] = I18n.t("authentication.signin_error")
22
22
  render 'new'
23
23
  end
24
24
  end
@@ -1,5 +1,7 @@
1
1
  module Adminpanel
2
2
  class UsersController < Adminpanel::ApplicationController
3
+ # authorize_resource :class => false
4
+ load_and_authorize_resource
3
5
  # GET /admin/users
4
6
  # GET /admin/users.json
5
7
  # def index
@@ -123,6 +123,30 @@ module Adminpanel
123
123
  )
124
124
  end
125
125
 
126
+ def boolean(name, *args)
127
+ options = args.extract_options!
128
+
129
+ @template.content_tag(
130
+ :div,
131
+ @template.content_tag(
132
+ :div,
133
+ options['label'],
134
+ :class => 'control-label') +
135
+ @template.content_tag(
136
+ :div,
137
+ @template.content_tag(
138
+ :label,
139
+ check_box(
140
+ name
141
+ ),
142
+ :class => 'checkbox'
143
+ ),
144
+ :class => 'controls'
145
+ ),
146
+ :class => 'control-group'
147
+ )
148
+ end
149
+
126
150
  def select(name, select_options, *args)
127
151
  options = args.extract_options!
128
152
 
@@ -16,22 +16,39 @@ module Adminpanel
16
16
  set_collections
17
17
  new! do |format|
18
18
  format.html { render "shared/new" }
19
+ format.js { render 'shared/new', :locals => { :resource => resource }}
19
20
  end
20
21
  end
21
22
 
22
23
  def create
23
- create! do |success, failure|
24
- success.html do
25
- flash.now[:success] = I18n.t("action.save_success")
26
- render "shared/index"
27
- end
28
- failure.html do
24
+ params.merge({:model => params[:model]}) if params[:model].present?
25
+ params.merge({:model_name => params[:model_name]}) if params[:model_name].present?
26
+ params.merge({:belongs_request => params[:belongs_request]}) if params[:belongs_request].present?
27
+ create! do |success, failure|
28
+ success.html do
29
+ flash[:success] = I18n.t("action.save_success")
30
+ redirect_to resource
31
+ end
32
+ failure.html do
29
33
  set_collections
30
- render "shared/new"
34
+ render "shared/new"
31
35
  end
32
- end
36
+ success.js do
37
+ flash.now[:success] = I18n.t("action.save_success")
38
+ if params[:belongs_request]
39
+ render 'shared/create_belongs_to', :locals => {:resource => resource }
40
+ else
41
+ render 'shared/create_has_many', :locals => {:resource => resource }
42
+ end
43
+ end
44
+ failure.js do
45
+ set_collections
46
+ render 'shared/new', :locals => {:resource => resource }
47
+ end
48
+ end
33
49
  end
34
50
 
51
+
35
52
  def edit
36
53
  edit! do |format|
37
54
  format.html do
@@ -44,7 +61,7 @@ module Adminpanel
44
61
  def update
45
62
  update! do |success, failure|
46
63
  success.html do
47
- flash.now[:success] = I18n.t("action.save_success")
64
+ flash[:success] = I18n.t("action.save_success")
48
65
  render "shared/index"
49
66
  end
50
67
  failure.html do
@@ -5,8 +5,9 @@ module Adminpanel
5
5
  if association.klass.to_s == parent_model
6
6
  if !resource.send(association.name).nil?
7
7
  return resource.send(association.name).name
8
+ # return resource.client
8
9
  else
9
- return "N/A"
10
+ return "N/A #{association.klass.to_s}"
10
11
  end
11
12
  end
12
13
  end
@@ -0,0 +1,6 @@
1
+ module Adminpanel
2
+ class Group < ActiveRecord::Base
3
+ attr_accessible :name
4
+
5
+ end
6
+ end
@@ -1,7 +1,11 @@
1
1
  module Adminpanel
2
2
  class User < ActiveRecord::Base
3
- attr_accessible :email, :name, :password, :password_confirmation
3
+ attr_accessible :email, :name, :password, :password_confirmation, :group_id
4
4
  has_secure_password
5
+ belongs_to :group
6
+
7
+ #group validation
8
+ validates_presence_of :group_id
5
9
 
6
10
  #name validations
7
11
  validates_presence_of :name
@@ -30,10 +34,49 @@ module Adminpanel
30
34
 
31
35
  def self.form_attributes
32
36
  [
33
- {"name" => {"type" => "text_field", "name" => "Nombre", 'label' => "Nombre", "placeholder" => "Nombre"}},
34
- {"email" => {"type" => "text_field", "name" => "Correo", 'label' => 'Correo', 'placeholder' => 'Correo'}},
35
- {"password" => {"type" => "password_field", "name" => "Contrasena", 'label' => I18n.t('model.attributes.password'), "placeholder" => I18n.t('model.attributes.password'), 'show' => 'false'}},
36
- {"password_confirmation" => {"type" => "password_field", "name" => "Confirmacion de contrasena", 'placeholder' => I18n.t('model.attributes.password_confirmation'), 'label' => I18n.t('model.attributes.password_confirmation'), 'show' => 'false'}},
37
+ {
38
+ 'name' => {
39
+ 'type' => 'text_field',
40
+ 'name' => 'Nombre',
41
+ 'label' => 'Nombre',
42
+ 'placeholder' => 'Nombre'
43
+ }
44
+ },
45
+ {
46
+ 'email' => {
47
+ 'type' => 'text_field',
48
+ 'name' => 'Correo',
49
+ 'label' => 'Correo',
50
+ 'placeholder' => 'Correo'
51
+ }
52
+ },
53
+ {
54
+ 'password' => {
55
+ 'type' => 'password_field',
56
+ 'name' => 'Contrasena',
57
+ 'label' => I18n.t('model.attributes.password'),
58
+ 'placeholder' => I18n.t('model.attributes.password'),
59
+ 'show' => 'false'
60
+ }
61
+ },
62
+ {
63
+ 'password_confirmation' => {
64
+ 'type' => 'password_field',
65
+ 'name' => 'Confirmacion de contrasena',
66
+ 'placeholder' => I18n.t('model.attributes.password_confirmation'),
67
+ 'label' => I18n.t('model.attributes.password_confirmation'),
68
+ 'show' => 'false'
69
+ }
70
+ },
71
+ {
72
+ 'group_id' => {
73
+ 'type' => 'belongs_to',
74
+ 'model' => 'Adminpanel::Group',
75
+ 'remote_resource' => false,
76
+ 'placeholder' => I18n.t('model.attributes.group_id'),
77
+ 'label' => I18n.t('model.attributes.group_id')
78
+ }
79
+ },
37
80
  ]
38
81
  end
39
82
 
@@ -15,9 +15,10 @@
15
15
  {
16
16
  :controller => params[:controller],
17
17
  :action => "new",
18
- :"model" => model
18
+ :"model" => model,
19
+ :currentcontroller => params[:controller]
19
20
  },
20
- :"data-target" => '#example_modal',
21
+ :"data-target" => '#new-category',
21
22
  :"data-toggle" => 'modal',
22
23
  :remote => true
23
24
  )
@@ -1,13 +1,13 @@
1
- <%= custom_form_for(resource, :remote => true, :html => {:class => "form-horizontal", :id => "new_resource"}) do |f| -%>
1
+ <%= custom_form_for(resource, :url => {:action => :create, :model => params[:model], :model_name => params[:model_name], :currentcontroller => params[:currentcontroller]}, :remote => true, :html => {:class => "form-horizontal", :id => "new-category-form"}) do |f| -%>
2
2
  <div class="row-fluid">
3
3
  <div class="modal-body">
4
4
  <%= render 'shared/error_messages', :object => resource %>
5
- <%= render 'shared/form_fields', :f => f %>
6
- <%= f.hidden_field :model, :value => model %>
5
+ <%= render 'shared/form_fields', :f => f, :remote_request => true %>
6
+ <%= f.hidden_field :model, :value => params[:model] %>
7
7
  </div>
8
8
  </div>
9
9
  <div class="modal-footer">
10
10
  <button id="modal-button" class="btn" data-dismiss="modal" aria-hidden="true"><%= I18n.t('action.close') %></button>
11
- <%= f.submit t("action.add") + " " + @model.display_name, :disable_with => t("action.submitting"), :id =>"new-resource-button" %>
11
+ <%= f.submit t("action.add") + " " + @model.display_name, :disable_with => t("action.submitting"), :id =>"new-#{@model.name.demodulize}-button" %>
12
12
  </div>
13
13
  <% end -%>
@@ -1,4 +1,5 @@
1
- $("#modal-button").trigger("click");
1
+ // $("#modal-button").trigger("click");
2
+ $('#new-category').modal('toggle');
2
3
  row = "<tr><td><%= escape_javascript link_to resource.name, category_path(resource) %></td>";
3
4
  row = row + "<td><%= escape_javascript link_to content_tag(:i, nil, :class => 'icon-pencil'), edit_category_path(category), :title => 'Editar' %> ";
4
5
  row = row + "<%= escape_javascript link_to content_tag(:i, nil, :class => 'icon-remove'),[category], :title => 'Editar', :method => :delete %></td>";
@@ -46,7 +46,7 @@
46
46
  </div>
47
47
 
48
48
  <!-- example modal -->
49
- <div id="example_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
49
+ <div id="new-category" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
50
50
  <div class="modal-header" id="modal-header">
51
51
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
52
52
  <h3 id="myModalLabel">Crear Categoría</h3>
@@ -1 +1,2 @@
1
- $("#modal-container").html('<%= escape_javascript(render "category_form", :resource => resource, :model => model) %>');
1
+ $("#modal-title").html('Agregar <%= @model.display_name %>');
2
+ $("#modal-container").html('<%= escape_javascript(render "category_form", :resource => resource) %>');
@@ -2,34 +2,36 @@
2
2
  <div class="sidebar-nav nav-collapse collapse" id="sidebar-navigation">
3
3
  <div class="user_side clearfix">
4
4
  <h5>
5
- <%= @current_user.name.humanize %>
5
+ <%= current_user.name.humanize %>
6
6
  </h5>
7
7
  <%=
8
8
  link_to(
9
- content_tag(:i, nil, :class => 'icon-cog') + ' Editar',
10
- edit_user_path(@current_user)
9
+ "#{current_user.group.name}",
10
+ "#"
11
11
  )
12
12
  %>
13
13
  </div>
14
14
  <div class="accordion" id="accordion2">
15
15
  <% Adminpanel.displayable_resources.each do |resource| %>
16
16
  <% resource_class = symbol_class(resource) %>
17
- <div class="accordion-group">
18
- <div class="accordion-heading">
19
- <%=
20
- link_to(
21
- content_tag(
22
- :i,
23
- nil,
24
- :class => resource_class.icon) +
25
- content_tag(:span," #{resource_class.display_name}"),
26
- [route_symbol(resource.to_s)],
27
- :class => "accordion-toggle b_99FFCC
28
- #{is_current_section?(resource_class.display_name)}"
29
- )
30
- %>
17
+ <% if can? :read, resource_class %>
18
+ <div class="accordion-group">
19
+ <div class="accordion-heading">
20
+ <%=
21
+ link_to(
22
+ content_tag(
23
+ :i,
24
+ nil,
25
+ :class => resource_class.icon) +
26
+ content_tag(:span," #{resource_class.display_name}"),
27
+ [route_symbol(resource.to_s)],
28
+ :class => "accordion-toggle b_99FFCC
29
+ #{is_current_section?(resource_class.display_name)}"
30
+ )
31
+ %>
32
+ </div>
31
33
  </div>
32
- </div>
34
+ <% end %>
33
35
  <% end %>
34
36
 
35
37
  </div>
@@ -2,7 +2,7 @@
2
2
  <div class="navbar-inner">
3
3
  <div class="container-fluid">
4
4
  <div class="logo">
5
- <%= link_to image_tag("adminpanel/codn.png", :alt => "logo"), main_root_path %>
5
+ <%= link_to image_tag("adminpanel/codn.png", :alt => "logo"), main_root_path, :target => '_blank' %>
6
6
  </div>
7
7
  <% if signed_in? %>
8
8
  <a class="btn btn-navbar visible-phone" data-toggle="collapse" data-target=".nav-collapse">