mokio 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +15 -1
  3. data/app/assets/javascripts/backend/datatable.js.coffee.erb +2 -3
  4. data/app/assets/javascripts/backend/head.js +2 -2
  5. data/app/assets/javascripts/backend/main.js +2 -2
  6. data/app/assets/stylesheets/{backend.css.scss → backend.scss} +0 -0
  7. data/app/assets/stylesheets/backend/bootstrap/{bootstrap2-switch.css.scss → bootstrap2-switch.scss} +0 -0
  8. data/app/assets/stylesheets/backend/{comments.css.scss → comments.scss} +0 -0
  9. data/app/assets/stylesheets/backend/{custom.css.scss → custom.scss} +0 -0
  10. data/app/assets/stylesheets/backend/{dashboard.css.scss → dashboard.scss} +0 -0
  11. data/app/assets/stylesheets/backend/{errors.css.scss → errors.scss} +0 -0
  12. data/app/assets/stylesheets/backend/{icons.css.scss → icons.scss} +6278 -6278
  13. data/app/assets/stylesheets/backend/{main.css.scss → main.scss} +3189 -3189
  14. data/app/assets/stylesheets/backend/{menu.css.scss → menu.scss} +0 -0
  15. data/app/assets/stylesheets/backend/{mov_gallery.css.scss → mov_gallery.scss} +0 -0
  16. data/app/assets/stylesheets/backend/{new.css.scss → new.scss} +15 -15
  17. data/app/assets/stylesheets/backend/plugins/forms/select2/{select2.css.scss → select2.scss} +0 -0
  18. data/app/assets/stylesheets/backend/plugins/tables/dataTables/{jquery.dataTables.css.scss → jquery.dataTables.scss} +0 -0
  19. data/app/assets/stylesheets/backend/supr-theme/{jquery-ui-timepicker-addon.css.scss → jquery-ui-timepicker-addon.scss} +0 -0
  20. data/app/assets/stylesheets/backend/supr-theme/{jquery.ui.datepicker.css.scss → jquery.ui.datepicker.scss} +0 -0
  21. data/app/assets/stylesheets/backend/supr-theme/{jquery.ui.supr.css.scss → jquery.ui.supr.scss} +10 -10
  22. data/app/assets/stylesheets/backend/supr-theme/{jquery.ui.theme.css.scss → jquery.ui.theme.scss} +263 -263
  23. data/app/assets/stylesheets/{dashboard.css.scss → dashboard.scss} +0 -0
  24. data/app/assets/stylesheets/{scaffolds.css.scss → scaffolds.scss} +0 -0
  25. data/app/controllers/mokio/support_controller.rb +3 -1
  26. data/app/helpers/mokio/backend/backend_helper.rb +25 -3
  27. data/app/helpers/mokio/backend/menu_helper.rb +4 -4
  28. data/app/models/devise_custom_failure.rb +5 -0
  29. data/app/models/{ability.rb → mokio/ability.rb} +25 -28
  30. data/app/views/devise/sessions/new.html.haml +1 -1
  31. data/app/views/layouts/mokio/backend.html.haml +3 -1
  32. data/app/views/mokio/common/index.html.slim +1 -0
  33. data/app/views/mokio/layout/_user_widget.html.slim +1 -1
  34. data/app/views/mokio/layout/sidebar.html.slim +1 -1
  35. data/app/views/mokio/menus/_form.html.haml +2 -2
  36. data/config/initializers/devise.rb +3 -2
  37. data/config/routes.rb +1 -4
  38. data/lib/mokio/concerns/common/controller_functions.rb +9 -2
  39. data/lib/mokio/concerns/common/controller_object.rb +14 -5
  40. data/lib/mokio/concerns/controllers/application.rb +2 -2
  41. data/lib/mokio/concerns/controllers/base.rb +7 -0
  42. data/lib/mokio/concerns/controllers/common.rb +9 -5
  43. data/lib/mokio/concerns/controllers/dashboard.rb +4 -4
  44. data/lib/mokio/concerns/models/common.rb +6 -6
  45. data/lib/mokio/concerns/models/user.rb +4 -4
  46. data/lib/mokio/version.rb +1 -1
  47. data/spec/dummy/config/routes.rb +1 -1
  48. metadata +104 -177
@@ -3,7 +3,9 @@ class Mokio::SupportController < Mokio::CommonController
3
3
  helper :application
4
4
 
5
5
  def index
6
-
6
+ respond_to do |format|
7
+ format.html
8
+ end
7
9
  end
8
10
 
9
11
 
@@ -1,6 +1,6 @@
1
1
  module Mokio
2
2
  module Backend
3
- module BackendHelper
3
+ module BackendHelper
4
4
  include Haml::Helpers
5
5
  #
6
6
  # Translate methods
@@ -55,7 +55,8 @@ module Mokio
55
55
  # i.e.(can? : manage, Mokio::Menu)
56
56
  # * +plus_icon_class+ Icon css class for "+" button
57
57
  def sidebar_btn(type, icon_class, label="", add_btn = true, check_permissions = true, plus_icon_class = "icomoon-icon-plus")
58
- table = type.to_s.demodulize.tableize #Mokio::Menu => menus
58
+
59
+ table = generate_tableize_name(type.to_s) #Mokio::Menu => menus or Mokio::MyModule::Menu => mymodule_menus
59
60
  model = table.singularize#Mokio::Menu => menu
60
61
 
61
62
  if label.empty?
@@ -98,6 +99,27 @@ module Mokio
98
99
  html.html_safe
99
100
  end
100
101
 
102
+ #
103
+ # Can user manage any site elements
104
+ #
105
+ def can_manage_site_elements?
106
+ (
107
+ (can? :manage, Mokio::StaticModule) ||
108
+ (can? :create, Mokio::StaticModule) ||
109
+ (can? :manage, Mokio::ModulePosition) ||
110
+ (can? :create, Mokio::ModulePosition) ||
111
+ (can? :manage, Mokio::ExternalScript) ||
112
+ (can? :create, Mokio::ExternalScript)
113
+ )
114
+ end
115
+
116
+ #return table name for type
117
+ def generate_tableize_name(type)
118
+ type.gsub!("Mokio::","")
119
+ type.gsub!("::","_") if(type.include? "::")
120
+ type.tableize
121
+ end
122
+
101
123
  end
102
124
  end
103
- end
125
+ end
@@ -3,10 +3,10 @@ module Mokio
3
3
  module MenuHelper
4
4
  include Haml::Helpers
5
5
 
6
- #displays breadcrump to current menu element
7
- def tree_menu_breadcrumps(menu)
6
+ #displays breadcrumb to current menu element
7
+ def tree_menu_breadcrumbs(menu)
8
8
  unless menu.nil?
9
- @tree_nodes = menu.ancestors << menu
9
+ @tree_nodes = menu.ancestors.to_a << menu
10
10
  @tree_nodes.map do |m|
11
11
  if m.present? and m != menu
12
12
  link_to(m.name, edit_menu_path(m)) + " -> "
@@ -214,4 +214,4 @@ module Mokio
214
214
 
215
215
  end
216
216
  end
217
- end
217
+ end
@@ -0,0 +1,5 @@
1
+ class DeviseCustomFailure < Devise::FailureApp
2
+ def redirect_url
3
+ '/backend/users/sign_in'
4
+ end
5
+ end
@@ -1,7 +1,7 @@
1
- class Ability
2
- include CanCan::Ability
1
+ module Mokio
2
+ class Ability
3
+ include CanCan::Ability
3
4
 
4
- def initialize(user)
5
5
  # Define abilities for the passed in user here. For example:
6
6
  #
7
7
  # user ||= User.new # guest user (not logged in)
@@ -28,31 +28,28 @@ class Ability
28
28
  #
29
29
  # See the wiki for details:
30
30
  # https://github.com/bryanrite/cancancan/wiki/Defining-Abilities
31
+ def initialize(user)
32
+ if user.has_role? :admin
33
+ can :manage, :all
34
+ end
35
+ if user.has_role? :content_editor
36
+ can :manage, [Mokio::Content]
37
+ end
38
+ if user.has_role? :menu_editor
39
+ can :manage, [Mokio::Menu]
40
+ end
41
+ if user.has_role? :static_module_editor
42
+ can :manage, [Mokio::StaticModule]
43
+ end
44
+ if user.has_role? :user_editor
45
+ can :manage, [Mokio::User]
46
+ end
47
+ if user.has_role? :reader
48
+ can :read, :all
49
+ end
31
50
 
32
- if user.has_role? :admin
33
- can :manage, :all
51
+ can :edit_password, Mokio::User
52
+ can :update_password, Mokio::User
34
53
  end
35
- if user.has_role? :content_editor
36
- can :manage, [Mokio::Content]
37
- end
38
- if user.has_role? :menu_editor
39
- can :manage, [Mokio::Menu]
40
- end
41
- if user.has_role? :static_module_editor
42
- can :manage, [Mokio::StaticModule]
43
- end
44
- if user.has_role? :user_editor
45
- can :manage, [Mokio::User]
46
- end
47
- if user.has_role? :reader
48
- can :read, :all
49
- end
50
-
51
- can :edit_password, Mokio::User
52
- can :update_password, Mokio::User
53
-
54
-
55
-
56
54
  end
57
- end
58
-
55
+ end
@@ -34,4 +34,4 @@
34
34
  %div
35
35
  =flash[:alert]
36
36
  %br
37
- = link_to t("devise.link.forgot_password"), new_password_path(resource_name)
37
+ = link_to t("devise.link.forgot_password"), new_password_path(resource_name)
@@ -68,5 +68,7 @@
68
68
  = render :template => "mokio/site_helper/first_login"
69
69
 
70
70
  = javascript_include_tag 'backend'
71
- = yield :js
71
+ = yield :js
72
72
 
73
+ :javascript
74
+ CKEDITOR.config.entities = false;
@@ -22,6 +22,7 @@
22
22
  - content_for :js do
23
23
  javascript:
24
24
  var obj_table = "#{@obj_class.to_s.demodulize.tableize}"
25
+ var obj_class = "#{@obj_path}"
25
26
  = javascript_include_tag "backend/datatable"
26
27
 
27
28
  /-if Mokio.solr_enabled == false
@@ -4,7 +4,7 @@
4
4
  span.icon16.icomoon-icon-user.white
5
5
  = current_user.email
6
6
  li#support
7
- a href="#{support_path}"
7
+ a href="#{support_index_path}"
8
8
  span.icon16.entypo-icon-help
9
9
  = bts("support")
10
10
  li
@@ -35,7 +35,7 @@
35
35
  = sidebar_btn Mokio::Contact, "icomoon-icon-mail-3"
36
36
 
37
37
  / SITE ELEMENTS
38
- - if can? :create, Mokio::Content
38
+ - if can_manage_site_elements?
39
39
  li.site_elements_nav
40
40
  a href="#"
41
41
  span.icon16.icomoon-icon-puzzle
@@ -23,14 +23,14 @@
23
23
  #url_box{:style => "display: #{!@menu.external_link.blank? ? 'block' : 'none'};"}
24
24
  = f.input :external_link, label: btc("external_link",'Menu'), disabled: !@menu.display_editable_field?('external_link')
25
25
  = f.input :follow, :as => :select, :collection => [[bt("follow",'Menu'), "true"], [bt("nofollow",'Menu'), "false"]], :include_blank => false
26
- = f.input :parent_id, :collection => @menu.parent_tree.collect{|m| ["#{'-' * m.ancestry.count('/')}#{m.name}", m.id]}, include_blank: false, disabled: !@menu.display_editable_field?('parent_id')
26
+ = f.input :parent_id, :collection => @menu.parent_tree.where.not(ancestry: nil).collect{|m| ["#{'-' * (m.depth - 1)} #{m.name}", m.id]}, include_blank: false, disabled: !@menu.display_editable_field?('parent_id')
27
27
 
28
28
  .row-fluid
29
29
  %label.form-label.span2
30
30
  = btc('path', Mokio::Menu)
31
31
  .span10
32
32
  #menu_breadcrumps
33
- = tree_menu_breadcrumps(@menu.parent)
33
+ = tree_menu_breadcrumbs(@menu.parent)
34
34
 
35
35
  = f.input :target, :collection => [[bt("current_window_inside",Mokio::Menu), nil], [bt("new_window",Mokio::Menu), "_blank"]], include_blank: false, disabled: !@menu.display_editable_field?('target')
36
36
 
@@ -235,10 +235,11 @@ Devise.setup do |config|
235
235
  # If you want to use other strategies, that are not supported by Devise, or
236
236
  # change the failure app, you can configure them inside the config.warden block.
237
237
  #
238
- # config.warden do |manager|
238
+ config.warden do |manager|
239
+ manager.failure_app = DeviseCustomFailure
239
240
  # manager.intercept_401 = false
240
241
  # manager.default_strategies(scope: :user).unshift :some_external_strategy
241
- # end
242
+ end
242
243
 
243
244
  # ==> Mountable engine configurations
244
245
  # When using Devise inside an engine, let's call it `MyEngine`, and this engine
@@ -206,10 +206,7 @@ Mokio::Engine.routes.draw do
206
206
  end
207
207
  end
208
208
 
209
-
210
- namespace :support do
211
- get '/', to: :index
212
- end
209
+ resources :support, only: :index
213
210
 
214
211
  end
215
212
 
@@ -66,11 +66,18 @@ module Mokio
66
66
  parameters
67
67
  end
68
68
 
69
+ def generate_path
70
+ path = @obj_class.name
71
+ path = path.gsub("Mokio::","") if path.include? "Mokio::"
72
+ path = path.tableize.gsub("/","_")
73
+ path
74
+ end
75
+
69
76
  #
70
77
  # Returns obj index url
71
78
  #
72
79
  def obj_index_url #:doc:
73
- send("#{self.controller_name.demodulize}_url") # call your_controller index path
80
+ send("#{generate_path}_url") # call your_controller index path
74
81
  end
75
82
 
76
83
  #
@@ -89,7 +96,7 @@ module Mokio
89
96
  # Returns obj new url
90
97
  #
91
98
  def obj_new_url(obj) #:doc:
92
- send("new_#{self.controller_name.demodulize.singularize}_path", obj) # call your_controller edit path for obj
99
+ send("new_#{generate_path.singularize}_path", obj) # call your_controller edit path for obj
93
100
  end
94
101
  end
95
102
  end
@@ -1,6 +1,6 @@
1
1
  module Mokio
2
- module Concerns
3
- module Common
2
+ module Concerns
3
+ module Common
4
4
  #
5
5
  # Most important logic for CommonController
6
6
  #
@@ -16,7 +16,7 @@ module Mokio
16
16
 
17
17
  private
18
18
  #
19
- # Returns inherited conroller singularized name
19
+ # Returns inherited conroller singularized name
20
20
  #
21
21
  def obj_name #:doc:
22
22
  self.controller_name.singularize
@@ -68,13 +68,22 @@ module Mokio
68
68
  create_obj( @obj_class.respond_to?(:friendly) ? @obj_class.friendly.find(params[:id]) : @obj_class.find(params[:id]) )
69
69
  end
70
70
 
71
-
71
+
72
72
  #
73
73
  # Setting constant parsed from controller name to @obj_class variable.
74
74
  # Our controllers are named to match model name. <b>before_filter</b> in CommonController
75
75
  #
76
76
  def set_obj_class #:doc:
77
- @obj_class = "Mokio::#{self.class.name.demodulize.gsub("Controller", "").classify}".constantize
77
+
78
+ class_name = (self.class.name.include? "Mokio::") ? self.class.name.gsub("Mokio::", "") : self.class.name
79
+ #check is class in Mokio module
80
+ @obj_class = "Mokio::#{class_name.gsub("Controller", "").classify}".constantize rescue nil
81
+ #if there is no class in Mokio module check outside
82
+ if @obj_class.nil?
83
+ @obj_class = "#{class_name.gsub("Controller", "").classify}".constantize rescue nil
84
+ end
85
+ #used for path to update_active action in datatable.js.coffee.erb
86
+ @obj_path = ((@obj_class.to_s.include? "Mokio::") ? @obj_class.to_s.gsub("Mokio::","") : @obj_class.to_s).tableize
78
87
  end
79
88
 
80
89
  #
@@ -24,7 +24,7 @@ module Mokio
24
24
  # <b>before_filter</b> in ApplicationController using <b>gem devise</b>
25
25
  #
26
26
  def configure_permitted_parameters
27
- devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email, :password, :password_confirmation, roles: [])}
27
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :password, :password_confirmation])
28
28
  end
29
29
 
30
30
  #
@@ -73,4 +73,4 @@ module Mokio
73
73
  end
74
74
  end
75
75
  end
76
- end
76
+ end
@@ -54,6 +54,13 @@ module Mokio
54
54
  @breadcrumbs_prefix = ""
55
55
  @breadcrumbs_prefix_link = ""
56
56
  end
57
+
58
+ #
59
+ # override current_ability to use Mokio's one
60
+ #
61
+ def current_ability
62
+ @current_ability ||= Mokio::Ability.new(current_user)
63
+ end
57
64
  end
58
65
  end
59
66
  end
@@ -1,7 +1,7 @@
1
1
  module Mokio
2
2
  module Concerns
3
3
  module Controllers
4
- #
4
+ #
5
5
  # Concern for CommonController. Many important controller logic is placed here.
6
6
  #
7
7
  # Most of Mokio's controllers are inherited by this controller. The main logic is to not repeat same part of code with changing only variables.
@@ -12,10 +12,10 @@ module Mokio
12
12
  # == CommonController provides:
13
13
  #
14
14
  # * +index+ method with json sending data.
15
- # Its using common/index view and place date into jquery.datatable plugin (you can see in backend/datatable.js.coffee.erb file).
15
+ # Its using common/index view and place date into jquery.datatable plugin (you can see in backend/datatable.js.coffee.erb file).
16
16
  # We send json as CommonsDatatable object (app/datatables/commons_datatable.rb)
17
17
  # Columns displayed in table are specified in used model inside method called columns_for_table.
18
- #
18
+ #
19
19
  # * +new+ method with building meta/gmap if they are enabled in used model
20
20
  # Its using common/new view and need partial '_form' with specifed form elements. Main form uses simple_form.
21
21
  #
@@ -23,7 +23,7 @@ module Mokio
23
23
  # Its using common/edit and need same partial as in 'new' action.
24
24
  #
25
25
  # * +create+ method
26
- # Simple creating and saving object to database if passed validation.
26
+ # Simple creating and saving object to database if passed validation.
27
27
  #
28
28
  # * +update+ method
29
29
  # Simple updating object in database
@@ -49,7 +49,11 @@ module Mokio
49
49
  include Mokio::Concerns::Common::ControllerObject
50
50
  include Mokio::Concerns::Common::ControllerFunctions
51
51
 
52
- load_and_authorize_resource
52
+ before_action :authorize_actions
53
+ def authorize_actions
54
+ authorize!(params[:action].to_sym, @obj_class)
55
+ end
56
+
53
57
  end
54
58
 
55
59
  #
@@ -25,9 +25,9 @@ module Mokio
25
25
  #
26
26
  # menu without displayed content
27
27
  #
28
- @menu_with_invisible_content = (Mokio::Menu.includes(:contents).where('mokio_contents.id is not NULL').references(:contents)).select{|menu| menu.invisible_content}
29
- @empty_menu = Mokio::Menu.includes(:contents).where(:mokio_content_links => {:menu_id => nil}, :external_link => nil, :fake => false)
30
- @empty_menu = @empty_menu.concat(@menu_with_invisible_content)
28
+ @menu_with_invisible_content = (Mokio::Menu.includes(:contents).where('mokio_contents.id is not NULL').references(:contents)).select{|menu| menu.invisible_content}.pluck :id
29
+ @empty_menu = Mokio::Menu.includes(:contents).where(:mokio_content_links => {:menu_id => nil}, :external_link => nil, :fake => false).pluck :id
30
+ @empty_menu = Mokio::Menu.where id: @empty_menu + @menu_with_invisible_content
31
31
  @empty_menu = @empty_menu.first(Mokio.dashboard_size.to_i)
32
32
  @more_empty_menu = @empty_menu.size
33
33
 
@@ -38,4 +38,4 @@ module Mokio
38
38
  end
39
39
  end
40
40
  end
41
- end
41
+ end
@@ -29,7 +29,7 @@ module Mokio
29
29
  #
30
30
  if Mokio.solr_enabled
31
31
  exceptions = Mokio::SolrConfig.all_exceptions # Classes which are excluded from indexing or have own searchable method
32
-
32
+
33
33
  unless exceptions.include? self.name.demodulize.downcase.to_sym
34
34
  searchable do # Columns where Sunspot knows which data use to index
35
35
  text :title, :boost => 5
@@ -37,7 +37,7 @@ module Mokio
37
37
  end
38
38
  end
39
39
  end
40
- end
40
+ end
41
41
 
42
42
  module ClassMethods
43
43
  #
@@ -60,12 +60,12 @@ module Mokio
60
60
  #
61
61
  def active_view
62
62
  "<div class=\"activebutton\">
63
- <input type=\"checkbox\"
64
- #{"checked=\"checked\"" if self.active}
63
+ <input type=\"checkbox\"
64
+ #{"checked=\"checked\"" if self.active}
65
65
  class=\"activebtn switch-small\"
66
66
  data-on=\"success\"
67
67
  data-off=\"danger\"
68
- data-on-label=\"<i class='icomoon-icon-checkmark white'></i>\"
68
+ data-on-label=\"<i class='icomoon-icon-checkmark white'></i>\"
69
69
  data-off-label=\"<i class='icomoon-icon-cancel-3 white'></i>\"
70
70
  >
71
71
  </div>"
@@ -103,7 +103,7 @@ module Mokio
103
103
  def some_editable
104
104
  if !self.editable && !self.changed.nil?
105
105
  (self.changed.to_set - self.always_editable_fields.to_set).each do |field|
106
- errors.add(field.to_sym, "#{I18n.t('activerecord.errors.editable.not_permitted')}")
106
+ errors.add(field.to_sym, "#{I18n.t('activerecord.errors.editable.not_permitted')}")
107
107
  end
108
108
  end
109
109
  end