tb_core 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +89 -0
  3. data/app/assets/javascripts/{spud/admin → admin}/application.js +1 -7
  4. data/app/assets/javascripts/admin/dashboard.js +9 -0
  5. data/app/assets/javascripts/admin/split_pane.js +138 -0
  6. data/app/assets/javascripts/admin/users.js +84 -0
  7. data/app/assets/stylesheets/{spud/admin/application.css → admin/application.css.scss} +14 -104
  8. data/app/assets/stylesheets/admin/login.css.scss +49 -0
  9. data/app/assets/stylesheets/admin/split_pane.css.scss +126 -0
  10. data/app/assets/stylesheets/admin/users.css.scss +9 -0
  11. data/app/controllers/{spud/admin → admin}/application_controller.rb +29 -30
  12. data/app/controllers/admin/dashboard_controller.rb +23 -0
  13. data/app/controllers/admin/password_resets_controller.rb +51 -0
  14. data/app/controllers/admin/roles_controller.rb +58 -0
  15. data/app/controllers/admin/settings_controller.rb +19 -0
  16. data/app/controllers/admin/setup_controller.rb +24 -0
  17. data/app/controllers/{spud/admin → admin}/user_sessions_controller.rb +8 -8
  18. data/app/controllers/admin/users_controller.rb +69 -0
  19. data/app/controllers/password_resets_controller.rb +52 -0
  20. data/app/controllers/sitemaps_controller.rb +8 -0
  21. data/app/controllers/spud/application_controller.rb +6 -20
  22. data/app/controllers/user_sessions_controller.rb +26 -0
  23. data/app/helpers/{spud/admin → admin}/application_helper.rb +1 -1
  24. data/app/helpers/admin/roles_helper.rb +2 -0
  25. data/app/helpers/spud/application_helper.rb +0 -7
  26. data/app/mailers/core_mailer.rb +9 -0
  27. data/app/models/spud_permission.rb +33 -0
  28. data/app/models/spud_role.rb +32 -0
  29. data/app/models/spud_role_permission.rb +9 -0
  30. data/app/models/spud_user.rb +79 -24
  31. data/app/models/spud_user_setting.rb +3 -3
  32. data/app/views/{spud/admin → admin}/dashboard/index.html.erb +1 -4
  33. data/app/views/admin/password_resets/index.html.erb +10 -0
  34. data/app/views/admin/password_resets/show.html.erb +15 -0
  35. data/app/views/admin/roles/_form.html.erb +33 -0
  36. data/app/views/admin/roles/edit.html.erb +2 -0
  37. data/app/views/admin/roles/index.html.erb +29 -0
  38. data/app/views/admin/roles/new.html.erb +2 -0
  39. data/app/views/{spud/admin → admin}/settings/edit.html.erb +6 -1
  40. data/app/views/admin/setup/new.html.erb +44 -0
  41. data/app/views/admin/user_sessions/new.html.erb +17 -0
  42. data/app/views/{spud/admin → admin}/users/_form.html.erb +20 -20
  43. data/app/views/admin/users/_index.html.erb +15 -0
  44. data/app/views/admin/users/edit.html.erb +3 -0
  45. data/app/views/admin/users/index.html.erb +34 -0
  46. data/app/views/admin/users/new.html.erb +3 -0
  47. data/app/views/admin/users/show.html.erb +28 -0
  48. data/app/views/layouts/admin/application.html.erb +68 -0
  49. data/app/views/layouts/{spud/admin → admin}/detail.html.erb +2 -2
  50. data/app/views/layouts/admin/login.html.erb +27 -0
  51. data/app/views/password_resets/index.html.erb +11 -0
  52. data/app/views/password_resets/show.html.erb +26 -0
  53. data/app/views/user_sessions/new.html.erb +25 -0
  54. data/config/routes.rb +22 -15
  55. data/db/migrate/20130620143010_create_spud_roles.rb +10 -0
  56. data/db/migrate/20130620143941_create_spud_permissions.rb +10 -0
  57. data/db/migrate/20130620151132_create_spud_role_permissions.rb +11 -0
  58. data/db/migrate/20130620163144_drop_spud_admin_permissions.rb +15 -0
  59. data/db/seeds.rb +3 -0
  60. data/lib/spud_core/belongs_to_app.rb +35 -48
  61. data/lib/spud_core/configuration.rb +5 -10
  62. data/lib/spud_core/engine.rb +31 -6
  63. data/lib/spud_core/exceptions.rb +7 -0
  64. data/lib/spud_core/searchable.rb +9 -9
  65. data/lib/spud_core/version.rb +3 -3
  66. data/spec/controllers/{spud/admin → admin}/application_controller_spec.rb +10 -6
  67. data/spec/controllers/{spud/admin → admin}/dashboard_controller_spec.rb +17 -29
  68. data/spec/controllers/{spud/admin → admin}/password_reset_controller_spec.rb +5 -5
  69. data/spec/controllers/admin/settings_controller_spec.rb +30 -0
  70. data/spec/controllers/admin/setup_controller_spec.rb +39 -0
  71. data/spec/controllers/admin/user_sessions_controller_spec.rb +52 -0
  72. data/spec/controllers/{spud/admin → admin}/users_controller_spec.rb +19 -35
  73. data/spec/controllers/{spud/sitemap_controllers_spec.rb → sitemap_controllers_spec.rb} +1 -1
  74. data/spec/dummy/config/database.yml +2 -2
  75. data/spec/dummy/db/schema.rb +23 -5
  76. data/spec/dummy/log/test.log +36118 -0
  77. data/spec/helpers/spud/admin/application_helper_spec.rb +1 -1
  78. data/spec/models/spud_role_spec.rb +46 -0
  79. data/spec/models/spud_user_spec.rb +0 -1
  80. metadata +101 -97
  81. data/README.markdown +0 -60
  82. data/app/assets/images/back_disabled.jpg +0 -0
  83. data/app/assets/images/back_enabled.jpg +0 -0
  84. data/app/assets/images/favicon.ico +0 -0
  85. data/app/assets/images/forward_disabled.jpg +0 -0
  86. data/app/assets/images/forward_enabled.jpg +0 -0
  87. data/app/assets/images/sort_asc.png +0 -0
  88. data/app/assets/images/sort_asc_disabled.png +0 -0
  89. data/app/assets/images/sort_both.png +0 -0
  90. data/app/assets/images/sort_desc.png +0 -0
  91. data/app/assets/images/sort_desc_disabled.png +0 -0
  92. data/app/assets/images/spud/admin/flick/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  93. data/app/assets/images/spud/admin/flick/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  94. data/app/assets/images/spud/admin/flick/ui-bg_flat_55_ffffff_40x100.png +0 -0
  95. data/app/assets/images/spud/admin/flick/ui-bg_flat_75_ffffff_40x100.png +0 -0
  96. data/app/assets/images/spud/admin/flick/ui-bg_glass_65_ffffff_1x400.png +0 -0
  97. data/app/assets/images/spud/admin/flick/ui-bg_highlight-soft_100_f6f6f6_1x100.png +0 -0
  98. data/app/assets/images/spud/admin/flick/ui-bg_highlight-soft_25_0073ea_1x100.png +0 -0
  99. data/app/assets/images/spud/admin/flick/ui-bg_highlight-soft_50_dddddd_1x100.png +0 -0
  100. data/app/assets/images/spud/admin/flick/ui-icons_0073ea_256x240.png +0 -0
  101. data/app/assets/images/spud/admin/flick/ui-icons_454545_256x240.png +0 -0
  102. data/app/assets/images/spud/admin/flick/ui-icons_666666_256x240.png +0 -0
  103. data/app/assets/images/spud/admin/flick/ui-icons_ff0084_256x240.png +0 -0
  104. data/app/assets/images/spud/admin/flick/ui-icons_ffffff_256x240.png +0 -0
  105. data/app/assets/images/spud/admin/spud_logo.png +0 -0
  106. data/app/assets/images/spud/admin/spud_logo@2x.png +0 -0
  107. data/app/assets/javascripts/spud/admin/dashboard.js +0 -80
  108. data/app/assets/javascripts/spud/admin/jquery.dataTables.min.js +0 -151
  109. data/app/assets/stylesheets/spud/forms.css +0 -108
  110. data/app/assets/stylesheets/spud/login/application.css +0 -302
  111. data/app/assets/stylesheets/spud/login.css +0 -58
  112. data/app/assets/stylesheets/spud/setup.css +0 -4
  113. data/app/assets/stylesheets/spud/sitemaps.css +0 -4
  114. data/app/assets/stylesheets/spud/user_sessions.css +0 -4
  115. data/app/assets/stylesheets/spud/users.css +0 -4
  116. data/app/controllers/spud/admin/dashboard_controller.rb +0 -34
  117. data/app/controllers/spud/admin/password_resets_controller.rb +0 -52
  118. data/app/controllers/spud/admin/settings_controller.rb +0 -27
  119. data/app/controllers/spud/admin/users_controller.rb +0 -109
  120. data/app/controllers/spud/setup_controller.rb +0 -21
  121. data/app/controllers/spud/sitemaps_controller.rb +0 -8
  122. data/app/helpers/spud/password_resets_helper.rb +0 -2
  123. data/app/mailers/spud/core_mailer.rb +0 -12
  124. data/app/models/spud_admin_permission.rb +0 -5
  125. data/app/views/layouts/spud/admin/application.html.erb +0 -73
  126. data/app/views/layouts/spud/login/application.html.erb +0 -17
  127. data/app/views/layouts/spud/setup.html.erb +0 -47
  128. data/app/views/spud/admin/password_resets/index.html.erb +0 -14
  129. data/app/views/spud/admin/password_resets/show.html.erb +0 -25
  130. data/app/views/spud/admin/user_sessions/new.html.erb +0 -27
  131. data/app/views/spud/admin/users/_edit.html.erb +0 -14
  132. data/app/views/spud/admin/users/_new.html.erb +0 -15
  133. data/app/views/spud/admin/users/edit.html.erb +0 -3
  134. data/app/views/spud/admin/users/index.html.erb +0 -42
  135. data/app/views/spud/admin/users/new.html.erb +0 -3
  136. data/app/views/spud/admin/users/show.html.erb +0 -12
  137. data/app/views/spud/setup/index.html.erb +0 -43
  138. data/spec/controllers/spud/admin/settings_controller_spec.rb +0 -55
  139. data/spec/controllers/spud/admin/user_sessions_controller_spec.rb +0 -51
  140. data/spec/controllers/spud/setup_controller_spec.rb +0 -56
  141. /data/app/assets/images/{spud/admin → admin}/down_arrow.gif +0 -0
  142. /data/app/assets/images/{spud/admin → admin}/up_arrow.gif +0 -0
  143. /data/app/assets/images/{spud/admin → admin}/users_thumb.png +0 -0
  144. /data/app/assets/javascripts/{spud/admin → admin}/date_picker.js +0 -0
  145. /data/app/assets/javascripts/{spud/admin → admin}/editor.js +0 -0
  146. /data/app/assets/javascripts/{spud/admin → admin}/preinit.js +0 -0
  147. /data/app/assets/javascripts/{spud/password_resets.js → admin/roles.js} +0 -0
  148. /data/app/assets/stylesheets/{spud/admin → admin}/jquery-ui.css +0 -0
  149. /data/app/assets/stylesheets/{spud/password_resets.css → admin/roles.css} +0 -0
  150. /data/app/views/{spud/admin → admin}/settings/_form.html.erb +0 -0
  151. /data/app/views/{spud/core_mailer → core_mailer}/forgot_password_notification.html.erb +0 -0
  152. /data/app/views/{spud/core_mailer → core_mailer}/forgot_password_notification.text.erb +0 -0
  153. /data/app/views/{spud/sitemaps → sitemaps}/show.xml.builder +0 -0
@@ -0,0 +1,26 @@
1
+ <div class="login-form">
2
+ <h1>Password Reset</h1>
3
+ <%= form_for @user, url: password_reset_path(:id => @user.perishable_token) do |f| %>
4
+ <% if @user.errors.any? %>
5
+ <div class="form-errors">
6
+ <h2>Please correct the following <%= pluralize(@user.errors.size, 'error') %>:</h2>
7
+ <ul>
8
+ <% @user.errors.full_messages.each do |msg| %>
9
+ <li><%= msg %></li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
13
+ <% end %>
14
+ <div class="field-group">
15
+ <%= f.label :password %>
16
+ <%= f.password_field :password %>
17
+ </div>
18
+ <div class="field-group">
19
+ <%= f.label :password_confirmation %>
20
+ <%= f.password_field :password_confirmation %>
21
+ </div>
22
+ <div class="field-group">
23
+ <%= f.submit "Reset Password" %>
24
+ </div>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,25 @@
1
+ <h1>Login</h1>
2
+
3
+ <%= form_for @user_session, :url => login_path, :html => {:class => 'spud-login-form'} do |f| %>
4
+ <% if @user_session.errors.any? %>
5
+ <div class="form-errors">
6
+ <h2>Please correct the following <%= pluralize(@user_session.errors.size, 'error') %>:</h2>
7
+ <ul>
8
+ <% @user_session.errors.full_messages.each do |msg| %>
9
+ <li><%= msg %></li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
13
+ <% end %>
14
+ <div class="form-row">
15
+ <%= f.label :login %>
16
+ <%= f.text_field :login %>
17
+ </div>
18
+ <div class="form-row">
19
+ <%= f.label :password %>
20
+ <%= f.password_field :password %>
21
+ </div>
22
+ <div class="form-row">
23
+ <%= f.submit "Login", :class => 'btn btn-primary' %> or <%=link_to "Forgot Password?", password_resets_path %>
24
+ </div>
25
+ <% end %>
data/config/routes.rb CHANGED
@@ -1,27 +1,34 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- namespace :spud, :path => '/' do
4
- namespace :admin do
3
+ namespace :admin do
5
4
 
6
- get 'login' => 'user_sessions#new', :as => 'login'
7
- post 'login' => 'user_sessions#create'
8
- match 'logout' => 'user_sessions#destroy', :as => 'logout'
5
+ get 'login' => 'user_sessions#new', :as => 'login'
6
+ post 'login' => 'user_sessions#create'
7
+ match 'logout' => 'user_sessions#destroy', :as => 'logout'
9
8
 
10
- resources :password_resets, :only => [:index, :create, :show, :update], :path => 'forgot'
9
+ resources :password_resets, :only => [:index, :create, :show, :update], :path => 'login/forgot'
11
10
 
12
- get 'settings' => 'settings#edit', :as => 'settings'
13
- put 'settings' => 'settings#update'
11
+ get 'settings' => 'settings#edit', :as => 'settings'
12
+ put 'settings' => 'settings#update'
14
13
 
15
- root :to => "dashboard#index"
16
- resources :users
17
- match 'switch' => "dashboard#switch"
18
- end
14
+ root :to => "dashboard#index"
15
+ resources :users, :controller
16
+ resources :roles
19
17
 
20
- resource :sitemap, :only => [:show]
18
+ match 'switch' => "dashboard#switch"
21
19
 
22
- match 'setup' => 'setup#index'
20
+ get 'setup' => 'setup#new'
21
+ post 'setup' => 'setup#create'
23
22
  end
24
-
23
+
24
+ resource :sitemap, :only => [:show]
25
+
26
+ # Non-admin login paths
27
+ get 'login' => 'user_sessions#new', :as => 'login'
28
+ post 'login' => 'user_sessions#create'
29
+ match 'logout' => 'user_sessions#destroy', :as => 'logout'
30
+ resources :password_resets, :only => [:index, :create, :show, :update], :path => 'login/forgot'
31
+
25
32
  get 'spud/admin' => 'spud/admin/user_sessions#legacy_redirect'
26
33
 
27
34
  end
@@ -0,0 +1,10 @@
1
+ class CreateSpudRoles < ActiveRecord::Migration
2
+ def change
3
+ create_table :spud_roles do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ add_column :spud_users, :spud_role_id, :integer
8
+ add_index :spud_users, :spud_role_id
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSpudPermissions < ActiveRecord::Migration
2
+ def change
3
+ create_table :spud_permissions do |t|
4
+ t.string :name, :null => false
5
+ t.string :tag, :null => false
6
+ t.timestamps
7
+ end
8
+ add_index :spud_permissions, :tag, :unique => true
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSpudRolePermissions < ActiveRecord::Migration
2
+ def change
3
+ create_table :spud_role_permissions do |t|
4
+ t.integer :spud_role_id, :null => false
5
+ t.string :spud_permission_tag, :null => false
6
+ t.timestamps
7
+ end
8
+ add_index :spud_role_permissions, :spud_role_id
9
+ add_index :spud_role_permissions, :spud_permission_tag
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class DropSpudAdminPermissions < ActiveRecord::Migration
2
+ def up
3
+ drop_table :spud_admin_permissions
4
+ end
5
+
6
+ def down
7
+ create_table :spud_admin_permissions do |t|
8
+ t.integer :user_id
9
+ t.string :name
10
+ t.boolean :access
11
+ t.string :scope
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,3 @@
1
+ role = SpudRole.where(:name => 'User Moderator').first || SpudRole.new(:name => 'User Moderator')
2
+ role.permission_tags = ['users.manage', 'users.roles']
3
+ role.save()
@@ -1,59 +1,46 @@
1
1
  module Spud::BelongsToApp
2
- extend ActiveSupport::Concern
3
- included do
4
- extend ClassMethods
5
- end
6
- # class Config
7
- # attr_reader :page_application
8
- # attr_reader :page_thumbnail
9
- # def initialize(app,thumb)
10
- # @page_application = app
11
- # @page_thumbnail = thumb
12
- # end
13
- # end
14
- module ClassMethods
15
- def belongs_to_spud_app(name=nil,options={})
16
- @page_title = options[:page_title]
17
- Spud::Core.admin_applications.each do |app|
18
- if app[:name].parameterize.underscore.to_sym == name
19
- @page_application = app
20
- break
21
- end
22
- end
23
- self.class_eval do
2
+ extend ActiveSupport::Concern
24
3
 
25
- before_filter { |controller|
26
- @page_thumbnail = self.class.page_application[:thumbnail]
27
- @application_name = self.class.page_application[:name]
28
- @page_name = self.class.page_title
29
-
30
- if current_user.super_admin == false
31
- permission = current_user_permissions.select{|perm| perm.name == @application_name}
32
- if permission.blank?
33
- flash[:error] = "You do not have access to this area."
34
- redirect_to spud_admin_root_url and return
35
- end
36
- end
37
-
38
- if controller.action_name == 'new' || controller.action_name == 'create'
39
- @page_name = "New #{@page_name.singularize}"
40
- elsif controller.action_name == 'edit' || controller.action_name == 'update'
41
- @page_name = "Edit #{@page_name.singularize}"
42
- elsif controller.action_name == 'show'
43
- @page_name = "Show #{@page_name.singularize}"
44
- end
4
+ included do
5
+ extend ClassMethods
6
+ end
45
7
 
46
- }
8
+ module ClassMethods
9
+ def belongs_to_spud_app(name=nil,options={})
10
+ @page_title = options[:page_title]
11
+ Spud::Core.admin_applications.each do |app|
12
+ if app[:name].parameterize.underscore.to_sym == name
13
+ @page_application = app
14
+ break
15
+ end
16
+ end
17
+ self.class_eval do
18
+ before_filter do |controller|
19
+ @page_thumbnail = self.class.page_application[:thumbnail]
20
+ @application_name = self.class.page_application[:name]
21
+ @page_name = self.class.page_title
47
22
 
48
- end
23
+ if !current_user.can_view_app?(self.class.page_application)
24
+ raise Spud::AccessDeniedError.new("You do not have access to this area.")
25
+ end
49
26
 
50
- end
51
- def page_application
27
+ if controller.action_name == 'new' || controller.action_name == 'create'
28
+ @page_name = "New #{@page_name.singularize}"
29
+ elsif controller.action_name == 'edit' || controller.action_name == 'update'
30
+ @page_name = "Edit #{@page_name.singularize}"
31
+ elsif controller.action_name == 'show'
32
+ @page_name = "Show #{@page_name.singularize}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def page_application
52
39
  @page_application || self.superclass.instance_variable_get('@page_application')
53
40
  end
54
41
 
55
42
  def page_title
56
- @page_title || self.superclass.instance_variable_get('@page_title') || page_application[:name]
43
+ @page_title || self.superclass.instance_variable_get('@page_title') || page_application[:name]
57
44
  end
58
- end
45
+ end
59
46
  end
@@ -1,13 +1,8 @@
1
1
  module Spud
2
2
  module Core
3
3
  include ActiveSupport::Configurable
4
- config_accessor :site_name,:admin_applications,:sitemap_urls,:multisite_mode_enabled,:multisite_config,:from_address,:site_id,:short_name, :javascripts,:stylesheets, :admin_javascripts, :admin_stylesheets
5
- self.admin_applications = [{
6
- :name => "Users",
7
- :thumbnail => "spud/admin/users_thumb.png",
8
- :url => '/admin/users',
9
- :order => 100
10
- }]
4
+ config_accessor :site_name,:admin_applications,:sitemap_urls,:multisite_mode_enabled,:multisite_config,:from_address,:site_id,:short_name, :javascripts,:stylesheets, :admin_javascripts, :admin_stylesheets, :permissions
5
+ self.admin_applications = []
11
6
  self.site_name = "Company Name"
12
7
  self.site_id = 0
13
8
  self.short_name = 'default'
@@ -17,9 +12,9 @@ module Spud
17
12
  self.multisite_mode_enabled = false
18
13
  self.multisite_config = []
19
14
  self.from_address = "no-reply@spudengine.com"
20
-
21
- self.admin_javascripts = ['spud/admin/application']
22
- self.admin_stylesheets = ['spud/admin/application']
15
+ self.permissions = []
16
+ self.admin_javascripts = ['admin/application']
17
+ self.admin_stylesheets = ['admin/application']
23
18
 
24
19
  def self.site_config_for_host(host)
25
20
  configs = Spud::Core.multisite_config.select{|p| p[:hosts].include?(host)}
@@ -14,6 +14,7 @@ module Spud
14
14
  module Core
15
15
  class Engine < ::Rails::Engine
16
16
  require "#{root}/lib/spud_core/belongs_to_app"
17
+ require "#{root}/lib/spud_core/exceptions"
17
18
  require "#{root}/lib/spud_core/searchable"
18
19
  require "#{root}/lib/responds_to_parent"
19
20
 
@@ -27,7 +28,7 @@ module Spud
27
28
 
28
29
  engine_name :tb_core
29
30
 
30
- initializer :assets do |config|
31
+ initializer 'tb_core.assets' do |config|
31
32
  Rails.application.config.assets.precompile += [
32
33
  "tiny_mce/plugins/**/*",
33
34
  "tiny_mce/themes/**/*",
@@ -38,18 +39,42 @@ module Spud
38
39
  ]
39
40
  end
40
41
 
41
- initializer :controller_overrides do |config|
42
- ActionController::Base.class_eval do
42
+ initializer 'tb_core.controller_overrides' do |config|
43
+ ActionController::Base.class_eval do
43
44
  include Spud::BelongsToApp
44
- end
45
+ end
45
46
  end
46
47
 
47
- initializer :model_overrides do |config|
48
+ initializer 'tb_core.model_overrides' do |config|
48
49
  ActiveRecord::Base.class_eval do
49
50
  include Spud::Searchable
50
51
  end
51
52
  end
52
53
 
54
+ initializer 'tb_core.admin', :after => :admin do |config|
55
+ # Translate Hash configured permissions into SpudPermission objects
56
+ Spud::Core.permissions.collect! do |p|
57
+ if p.class == Hash
58
+ p = SpudPermission.new(p[:tag], p[:name], p[:apps])
59
+ end
60
+ p
61
+ end
62
+ # Append Users admin module
63
+ Spud::Core.config.admin_applications.unshift({
64
+ :name => "Users",
65
+ :thumbnail => "admin/users_thumb.png",
66
+ :url => '/admin/users',
67
+ :order => 100
68
+ })
69
+ # Create default permissions for modules
70
+ Spud::Core.admin_applications.each do |admin_application|
71
+ admin_application[:key] ||= admin_application[:name].gsub(' ', '_').downcase.to_sym
72
+ tag = "admin.#{admin_application[:key]}.full_access"
73
+ name = "#{admin_application[:name]} admin"
74
+ apps = [admin_application[:key]]
75
+ Spud::Core.permissions.push(SpudPermission.new(tag, name, apps))
76
+ end
77
+ end
53
78
  end
54
79
  end
55
- end
80
+ end
@@ -0,0 +1,7 @@
1
+ class Spud::AccessDeniedError < StandardError
2
+
3
+ end
4
+
5
+ class Spud::NotFoundError < StandardError
6
+
7
+ end
@@ -1,11 +1,11 @@
1
1
  module Spud::Searchable
2
- extend ActiveSupport::Concern
3
- included do
4
- extend ClassMethods
5
- end
6
- module ClassMethods
7
- def spud_searchable
8
- # puts "Place Holder For #{self.name}"
9
- end
10
- end
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ extend ClassMethods
5
+ end
6
+ module ClassMethods
7
+ def spud_searchable
8
+ # puts "Place Holder For #{self.name}"
9
+ end
10
+ end
11
11
  end
@@ -1,5 +1,5 @@
1
1
  module Spud
2
- module Core
3
- VERSION = "1.0.2"
4
- end
2
+ module Core
3
+ VERSION = "1.1.0"
4
+ end
5
5
  end
@@ -1,16 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spud::Admin::ApplicationController do
3
+ describe Admin::ApplicationController do
4
4
 
5
5
 
6
6
  before :each do
7
7
  activate_authlogic
8
8
  @user = FactoryGirl.create(:spud_user)
9
+ @role = FactoryGirl.create(:spud_role)
9
10
  @session = SpudUserSession.create(@user)
10
11
  end
11
12
 
12
- describe :require_admin_user do
13
- controller(Spud::Admin::ApplicationController) do
13
+ describe :require_user do
14
+ controller(Admin::ApplicationController) do
14
15
  def index
15
16
  render :nothing => true
16
17
  end
@@ -23,7 +24,10 @@ describe Spud::Admin::ApplicationController do
23
24
  end
24
25
 
25
26
  it "should respond successfully if the current user has admin permissions" do
26
- @user.spud_admin_permissions.create(:name => "pages", :access => true)
27
+ @role.permission_tags = ['admin.users.full_access']
28
+ @role.save()
29
+ @user.role = @role
30
+ @user.save()
27
31
  get :index
28
32
 
29
33
  response.should be_success
@@ -33,12 +37,12 @@ describe Spud::Admin::ApplicationController do
33
37
  @session.destroy
34
38
  get :index
35
39
 
36
- response.should redirect_to(spud_admin_login_path)
40
+ response.should redirect_to(admin_login_path)
37
41
  end
38
42
 
39
43
  it "should redirect to the root for a user without administrative priviledges" do
40
44
  @user.super_admin = false
41
- @user.spud_admin_permissions = []
45
+ @user.role = nil
42
46
  @user.save
43
47
  get :index
44
48
 
@@ -1,61 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spud::Admin::DashboardController do
3
+ describe Admin::DashboardController do
4
4
  before(:all) do
5
- Spud::Core.configure do |config|
6
- config.admin_applications = [
7
- {name: "Blog", thumbnail: "/url/to/image", url: "/url/to/app", order: 0},
8
- {name: "Settings", thumbnail: "/url/to/image", url: "/url/to/app", order: 0},
9
- {name: "Pages", thumbnail: "/url/to/image", url: "/url/to/app", order: 0}
10
- ]
11
- end
5
+ Spud::Core.admin_applications += [{
6
+ :name => 'Test App',
7
+ :url => '/test/app',
8
+ :permissions => ["admin.test_app.full_access"]
9
+ }]
12
10
  end
13
11
 
14
12
  before(:each) do
15
13
  activate_authlogic
16
14
  @user = FactoryGirl.create(:spud_user)
15
+ @user.role = FactoryGirl.create(:spud_role)
16
+ @user.save()
17
17
  SpudUserSession.create(@user)
18
18
  end
19
19
 
20
20
  describe :index do
21
21
  it "should display applications the current user has access to given that the current user is not a super admin" do
22
22
  @user.super_admin = false
23
- @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Blog", :access => true))
24
- @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Pages", :access => true))
25
- @user.save
23
+ @user.role.permission_tags = ['admin.users.full_access']
24
+ @user.role.save()
25
+ @user.save()
26
26
  get :index
27
27
 
28
- assigns(:admin_applications).collect{|app| app[:name] }.should =~ @user.spud_admin_permissions.collect{|permission| permission.name }
28
+ assigns(:admin_applications).collect{|app| app[:name] }.should =~ ['Users']
29
29
  end
30
30
 
31
31
  it "should not display applications the current user does not have access to given that the current user is not a super admin" do
32
32
  @user.super_admin = false
33
- @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Blog", :access => true))
34
- @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Pages", :access => true))
35
- @user.save
33
+ @user.role.permission_tags = ['admin.users.full_access']
34
+ @user.role.save()
35
+ @user.save()
36
36
  get :index
37
37
 
38
- assigns(:admin_applications).collect{|app| app[:name] }.should_not include(:settings)
38
+ assigns(:admin_applications).collect{|app| app[:name] }.should_not include(:test_app)
39
39
  end
40
40
 
41
41
  it "should display all the applications despite the users permissions given the current user is a super admin" do
42
42
  @user.super_admin = true
43
- @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Blog", :access => true))
43
+ @user.role = nil
44
44
  @user.save
45
45
  get :index
46
46
 
47
47
  assigns(:admin_applications).collect{|app| app[:name] }.should =~ Spud::Core.admin_applications.collect{|app| app[:name] }
48
48
  end
49
-
50
- it "should display applications in order of user preference if available" do
51
- @user.super_admin = true
52
- @user.save
53
- @user.spud_user_settings.create(:key => "app_order",:value => "Pages,Settings")
54
- get :index
55
-
56
- assigns(:admin_applications).collect{|app| app[:name] }.should =~ ["Pages","Settings","Blog"]
57
-
58
- end
59
49
  end
60
50
 
61
51
  describe :switch do
@@ -65,7 +55,6 @@ describe Spud::Admin::DashboardController do
65
55
  config.multisite_mode_enabled = true
66
56
  end
67
57
  @user.super_admin = true
68
- @user.spud_admin_permissions.build(FactoryGirl.attributes_for(:spud_admin_permission, :name => "Blog", :access => true))
69
58
  @user.save
70
59
  end
71
60
 
@@ -90,7 +79,6 @@ describe Spud::Admin::DashboardController do
90
79
  config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
91
80
 
92
81
  end
93
- # Spud::Core.stubs(:multisite_config).returns([{:site_id => 1}])
94
82
  end
95
83
 
96
84
  it "should set the session's admin site" do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spud::Admin::PasswordResetsController do
3
+ describe Admin::PasswordResetsController do
4
4
  let(:user) { FactoryGirl.build(:spud_user, :id => 1) }
5
5
 
6
6
  context :get do
@@ -30,7 +30,7 @@ describe Spud::Admin::PasswordResetsController do
30
30
 
31
31
  it "should redirect to the login form" do
32
32
  get :show, :id => user.id
33
- response.should redirect_to(spud_admin_login_path)
33
+ response.should redirect_to(admin_login_path)
34
34
  end
35
35
  end
36
36
  end
@@ -46,13 +46,13 @@ describe Spud::Admin::PasswordResetsController do
46
46
  end
47
47
 
48
48
  it "should trigger the password notificiation" do
49
- Spud::CoreMailer.expects(:forgot_password_notification).returns(stub(:deliver))
49
+ CoreMailer.expects(:forgot_password_notification).returns(stub(:deliver))
50
50
  post :create, :email => user.email
51
51
  end
52
52
 
53
53
  it "should redirect to the login form" do
54
54
  post :create, :email => user.email
55
- response.should redirect_to(spud_admin_login_path)
55
+ response.should redirect_to(admin_login_path)
56
56
  end
57
57
  end
58
58
 
@@ -78,7 +78,7 @@ describe Spud::Admin::PasswordResetsController do
78
78
  context "with valid password entry" do
79
79
  it "should save and redirect to the login form" do
80
80
  post :update, valid_data
81
- response.should redirect_to(spud_admin_login_path)
81
+ response.should redirect_to(admin_login_path)
82
82
  end
83
83
  end
84
84
 
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::SettingsController do
4
+ before(:each) do
5
+ activate_authlogic
6
+ user = FactoryGirl.build(:spud_user)
7
+ user.super_admin = true
8
+ SpudUserSession.create(user)
9
+ end
10
+
11
+ describe :edit do
12
+ it "should respond with success" do
13
+ get :edit
14
+ response.should be_success
15
+ end
16
+ end
17
+
18
+ describe :update do
19
+ it "should redirect to the admin root with a successful update" do
20
+ put :update, :spud_user => {:first_name => "Mike"}
21
+ response.should redirect_to(admin_root_path)
22
+ end
23
+
24
+ it "should put a message in the flash notice" do
25
+ put :update, :spud_user => {:first_name => "Mike"}
26
+ flash[:notice].should_not be_blank
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::SetupController do
4
+
5
+ describe :new do
6
+ it "should be successful" do
7
+ get :new
8
+
9
+ response.should be_success
10
+ end
11
+
12
+ it "should set a flash error message when a spud user exists" do
13
+ SpudUser.stubs(:count).returns(1)
14
+ get :new
15
+
16
+ flash[:error].should_not be_blank
17
+ end
18
+
19
+ it "should redirect to the admin login form when there is already a user" do
20
+ SpudUser.stubs(:count).returns(1)
21
+ get :new
22
+
23
+ response.should redirect_to(admin_login_path)
24
+ end
25
+ end
26
+
27
+ describe :create do
28
+ it "should create a new user" do
29
+ lambda {
30
+ post :create, :spud_user => FactoryGirl.attributes_for(:spud_user)
31
+ }.should change(SpudUser, :count).by(1)
32
+ end
33
+
34
+ it "should redirect to the admin dashboard when first admin user has been created" do
35
+ post :create, :spud_user => FactoryGirl.attributes_for(:spud_user)
36
+ response.should redirect_to(admin_root_path)
37
+ end
38
+ end
39
+ end