Permalink
Browse files

In the beginning...

  • Loading branch information...
Lee Smith
Lee Smith committed Dec 31, 2009
0 parents commit 50ddae891b765a0372487739965e200565678c21
Showing with 13,553 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +21 −0 LICENSE
  3. +70 −0 README.rdoc
  4. +10 −0 Rakefile
  5. +154 −0 app/controllers/admin_controller.rb
  6. +32 −0 app/controllers/alerts_controller.rb
  7. +87 −0 app/controllers/application_controller.rb
  8. +54 −0 app/controllers/attachments_controller.rb
  9. +48 −0 app/controllers/comments_controller.rb
  10. +115 −0 app/controllers/contacts_controller.rb
  11. +31 −0 app/controllers/dashboard_controller.rb
  12. +50 −0 app/controllers/password_resets_controller.rb
  13. +144 −0 app/controllers/tickets_controller.rb
  14. +34 −0 app/controllers/user_sessions_controller.rb
  15. +117 −0 app/controllers/users_controller.rb
  16. +2 −0 app/helpers/admin_helper.rb
  17. +2 −0 app/helpers/alerts_helper.rb
  18. +25 −0 app/helpers/application_helper.rb
  19. +2 −0 app/helpers/attachments_helper.rb
  20. +2 −0 app/helpers/comments_helper.rb
  21. +2 −0 app/helpers/contacts_helper.rb
  22. +2 −0 app/helpers/dashboard_helper.rb
  23. +2 −0 app/helpers/password_resets_helper.rb
  24. +57 −0 app/helpers/tickets_helper.rb
  25. +2 −0 app/helpers/user_sessions_helper.rb
  26. +2 −0 app/helpers/users_helper.rb
  27. +10 −0 app/models/alert.rb
  28. +64 −0 app/models/attachment.rb
  29. +14 −0 app/models/attachment_observer.rb
  30. +62 −0 app/models/audit_sweeper.rb
  31. +10 −0 app/models/comment.rb
  32. +24 −0 app/models/contact.rb
  33. +18 −0 app/models/group.rb
  34. +27 −0 app/models/notifier.rb
  35. +23 −0 app/models/priority.rb
  36. +18 −0 app/models/status.rb
  37. +55 −0 app/models/ticket.rb
  38. +11 −0 app/models/ticket_observer.rb
  39. +53 −0 app/models/user.rb
  40. +12 −0 app/models/user_session.rb
  41. +156 −0 app/views/admin/index.html.erb
  42. +8 −0 app/views/attachments/_attachment.html.erb
  43. +11 −0 app/views/comments/_comment.html.erb
  44. +10 −0 app/views/contacts/_alphabet.html.erb
  45. +19 −0 app/views/contacts/_contacts.html.erb
  46. +20 −0 app/views/contacts/_form.html.erb
  47. +9 −0 app/views/contacts/edit.html.erb
  48. +18 −0 app/views/contacts/index.html.erb
  49. +1 −0 app/views/contacts/index.js.erb
  50. +9 −0 app/views/contacts/new.html.erb
  51. +34 −0 app/views/contacts/show.html.erb
  52. +102 −0 app/views/dashboard/index.html.erb
  53. +74 −0 app/views/layouts/application.html.erb
  54. +36 −0 app/views/layouts/user_sessions.html.erb
  55. +18 −0 app/views/notifier/owner_alert.text.html.erb
  56. +5 −0 app/views/notifier/password_reset_instructions.text.plain.erb
  57. +16 −0 app/views/notifier/ticket_alert.text.html.erb
  58. +17 −0 app/views/password_resets/edit.html.erb
  59. +15 −0 app/views/password_resets/new.html.erb
  60. +34 −0 app/views/tickets/_form.html.erb
  61. +94 −0 app/views/tickets/_ticket_filter.html.erb
  62. +37 −0 app/views/tickets/_tickets.html.erb
  63. +4 −0 app/views/tickets/_tickets_per_page.html.erb
  64. +3 −0 app/views/tickets/edit.html.erb
  65. +25 −0 app/views/tickets/index.html.erb
  66. +1 −0 app/views/tickets/index.js.erb
  67. +3 −0 app/views/tickets/new.html.erb
  68. +89 −0 app/views/tickets/show.html.erb
  69. +54 −0 app/views/tickets/show.pdf.prawn
  70. +18 −0 app/views/user_sessions/new.html.erb
  71. +27 −0 app/views/users/_form.erb
  72. +23 −0 app/views/users/_users.html.erb
  73. +9 −0 app/views/users/edit.html.erb
  74. +18 −0 app/views/users/index.html.erb
  75. +1 −0 app/views/users/index.js.erb
  76. +12 −0 app/views/users/new.html.erb
  77. +85 −0 app/views/users/show.html.erb
  78. +110 −0 config/boot.rb
  79. +20 −0 config/config.yml
  80. +22 −0 config/database.example.yml
  81. +49 −0 config/environment.rb
  82. +17 −0 config/environments/development.rb
  83. +28 −0 config/environments/production.rb
  84. +28 −0 config/environments/test.rb
  85. +7 −0 config/initializers/backtrace_silencers.rb
  86. +10 −0 config/initializers/inflections.rb
  87. +2 −0 config/initializers/load_config.rb
  88. +5 −0 config/initializers/mime_types.rb
  89. +21 −0 config/initializers/new_rails_defaults.rb
  90. +3 −0 config/initializers/paperclip.rb
  91. +15 −0 config/initializers/session_store.rb
  92. +5 −0 config/locales/en.yml
  93. +83 −0 config/routes.rb
  94. +28 −0 db/migrate/20081129214804_create_tickets.rb
  95. +12 −0 db/migrate/20081130035032_create_groups.rb
  96. +12 −0 db/migrate/20081130035501_create_statuses.rb
  97. +12 −0 db/migrate/20081130035552_create_priorities.rb
  98. +18 −0 db/migrate/20081205024712_create_comments.rb
  99. +35 −0 db/migrate/20081228061919_create_users.rb
  100. +19 −0 db/migrate/20090513023515_create_contacts.rb
  101. +20 −0 db/migrate/20090618031802_create_attachments.rb
  102. +17 −0 db/migrate/20090914141258_create_alerts.rb
  103. +129 −0 db/schema.rb
  104. +43 −0 db/seeds.rb
  105. +2 −0 doc/README_FOR_APP
  106. +80 −0 lib/tasks/faker.rake
  107. +40 −0 public/404.html
  108. +40 −0 public/422.html
  109. +41 −0 public/500.html
  110. BIN public/favicon.ico
  111. BIN public/images/accept.png
  112. BIN public/images/add-alert.png
  113. BIN public/images/add-attachment.png
  114. BIN public/images/add-comment.png
  115. BIN public/images/add.png
  116. BIN public/images/avatar.gif
  117. BIN public/images/back-arrow.png
  118. BIN public/images/balloon.png
  119. BIN public/images/bullet_black.png
  120. BIN public/images/bullet_blue.png
  121. BIN public/images/bullet_red.png
  122. BIN public/images/bullet_yellow.png
  123. BIN public/images/button-overlay.png
  124. BIN public/images/calendar.png
  125. BIN public/images/delete-alert.png
  126. BIN public/images/delete.png
  127. BIN public/images/disable.png
  128. BIN public/images/document-excel.png
  129. BIN public/images/document-film.png
  130. BIN public/images/document-image.png
  131. BIN public/images/document-music.png
  132. BIN public/images/document-pdf.png
  133. BIN public/images/document-powerpoint.png
  134. BIN public/images/document-text.png
  135. BIN public/images/document-word.png
  136. BIN public/images/document-zipper.png
  137. BIN public/images/document.png
  138. BIN public/images/edit-contact.png
  139. BIN public/images/edit-ticket.png
  140. BIN public/images/edit-user.png
  141. BIN public/images/error.png
  142. BIN public/images/exclamation.png
  143. BIN public/images/head-bg.gif
  144. BIN public/images/key.png
  145. BIN public/images/loading.gif
  146. BIN public/images/minus.gif
  147. BIN public/images/plus.gif
  148. BIN public/images/rails.png
  149. BIN public/images/shadow-trans.png
  150. BIN public/images/shadow.png
  151. BIN public/images/tab-bg.jpg
  152. BIN public/images/tab-tl.gif
  153. BIN public/images/tab-tr.gif
  154. BIN public/images/throbber-off.gif
  155. BIN public/images/throbber-on.gif
  156. BIN public/images/trash.png
  157. +95 −0 public/javascripts/application.js
  158. +963 −0 public/javascripts/controls.js
  159. +891 −0 public/javascripts/datepicker.js
  160. +973 −0 public/javascripts/dragdrop.js
  161. +1,128 −0 public/javascripts/effects.js
  162. +19 −0 public/javascripts/jquery-1.3.2.min.js
  163. +20 −0 public/javascripts/jquery.tools.min.js
  164. +8 −0 public/javascripts/pagination.js
  165. +4,320 −0 public/javascripts/prototype.js
  166. +5 −0 public/robots.txt
  167. +3 −0 public/stylesheets/print.css
  168. +34 −0 public/stylesheets/reset.css
  169. +302 −0 public/stylesheets/screen.css
  170. +4 −0 script/about
  171. +3 −0 script/console
  172. +3 −0 script/dbconsole
  173. +3 −0 script/destroy
  174. +3 −0 script/generate
  175. +3 −0 script/performance/benchmarker
  176. +3 −0 script/performance/profiler
  177. +3 −0 script/performance/request
  178. +3 −0 script/plugin
  179. +3 −0 script/process/inspector
  180. +3 −0 script/process/reaper
  181. +3 −0 script/process/spawner
  182. +3 −0 script/runner
  183. +3 −0 script/server
  184. +7 −0 test/fixtures/alerts.yml
  185. +7 −0 test/fixtures/attachments.yml
  186. +7 −0 test/fixtures/comments.yml
  187. +19 −0 test/fixtures/contacts.yml
  188. +7 −0 test/fixtures/groups.yml
  189. +9 −0 test/fixtures/priorities.yml
  190. +7 −0 test/fixtures/statuses.yml
  191. +9 −0 test/fixtures/tickets.yml
  192. +25 −0 test/fixtures/users.yml
  193. +8 −0 test/functional/admin_controller_test.rb
  194. +8 −0 test/functional/alerts_controller_test.rb
  195. +8 −0 test/functional/attachments_controller_test.rb
  196. +45 −0 test/functional/comments_controller_test.rb
  197. +45 −0 test/functional/contacts_controller_test.rb
  198. +8 −0 test/functional/dashboard_controller_test.rb
  199. +8 −0 test/functional/password_resets_controller_test.rb
  200. +45 −0 test/functional/tickets_controller_test.rb
  201. +8 −0 test/functional/user_sessions_controller_test.rb
  202. +45 −0 test/functional/users_controller_test.rb
  203. +9 −0 test/performance/browsing_test.rb
  204. +38 −0 test/test_helper.rb
  205. +8 −0 test/unit/alert_test.rb
  206. +8 −0 test/unit/attachment_observer_test.rb
  207. +15 −0 test/unit/attachment_test.rb
  208. +8 −0 test/unit/comment_test.rb
  209. +11 −0 test/unit/contact_test.rb
  210. +10 −0 test/unit/group_test.rb
  211. +4 −0 test/unit/helpers/admin_helper_test.rb
  212. +4 −0 test/unit/helpers/alerts_helper_test.rb
  213. +4 −0 test/unit/helpers/attachments_helper_test.rb
  214. +4 −0 test/unit/helpers/contacts_helper_test.rb
  215. +4 −0 test/unit/helpers/password_resets_helper_test.rb
  216. +8 −0 test/unit/notifier_test.rb
  217. +11 −0 test/unit/priority_test.rb
  218. +10 −0 test/unit/status_test.rb
  219. +8 −0 test/unit/ticket_observer_test.rb
  220. +8 −0 test/unit/ticket_test.rb
  221. +8 −0 test/unit/user_test.rb
  222. +20 −0 vendor/plugins/prawnto/MIT-LICENSE
  223. +12 −0 vendor/plugins/prawnto/README
  224. +22 −0 vendor/plugins/prawnto/Rakefile
  225. +7 −0 vendor/plugins/prawnto/init.rb
  226. +32 −0 vendor/plugins/prawnto/lib/prawnto.rb
  227. +45 −0 vendor/plugins/prawnto/lib/prawnto/action_controller.rb
  228. +12 −0 vendor/plugins/prawnto/lib/prawnto/action_view.rb
  229. +72 −0 vendor/plugins/prawnto/lib/prawnto/template_handler/compile_support.rb
  230. +16 −0 vendor/plugins/prawnto/lib/prawnto/template_handlers/base.rb
  231. +16 −0 vendor/plugins/prawnto/lib/prawnto/template_handlers/dsl.rb
  232. +64 −0 vendor/plugins/prawnto/lib/prawnto/template_handlers/raw.rb
  233. +4 −0 vendor/plugins/prawnto/tasks/prawnto_tasks.rake
  234. +38 −0 vendor/plugins/prawnto/test/action_controller_test.rb
  235. +39 −0 vendor/plugins/prawnto/test/base_template_handler_test.rb
  236. +40 −0 vendor/plugins/prawnto/test/dsl_template_handler_test.rb
  237. +163 −0 vendor/plugins/prawnto/test/raw_template_handler_test.rb
  238. +77 −0 vendor/plugins/prawnto/test/template_handler_test_mocks.rb
@@ -0,0 +1,9 @@
+log/*.log
+tmp/*
+tmp/**/*
+doc/api
+doc/app
+db/*.sqlite3
+*.swp
+*~
+.DS_Store
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2009 J. Lee Smith
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,70 @@
+= TicketMule
+
+No frills, general use support ticket tracking. Easily document and communicate client relations within a support team.
+
+== Features
+
+* Clean interface that is compatible with modern web browsers
+* Add comments and file attachments to tickets
+* Subscribe to ticket updates via email (alerts)
+* Automatically sends an email to the user assigned as owner of a ticket
+* View recent ticket activity and timeline statistics from the dashboard
+* Export ticket in PDF format
+* No complicated permission system...only admins can perform negative actions
+* In-line admin controls to delete comments, attachments, and tickets
+
+== Required Gems
+
+* <em>will_paginate</em>
+* <em>authlogic</em>
+* <em>searchlogic</em>
+* <em>paperclip</em>
+* <em>prawn</em>
+
+To load fake data to test drive TicketMule, you will also need <em>populator</em> and <em>faker</em> gems.
+
+== Install
+
+Basic installation creates a fresh database with a single admin user. See +db/seeds.rb+ for admin user information.
+
+You can choose to test drive TicketMule with fake data as described below.
+
+Create database configuration file and modify as needed:
+
+ $ cp config/database.example.yml config/database.yml
+
+Configure TicketMule settings in the <em>production</em> block of +config/config.yml+. See comments for details.
+
+Modify +config/environment.rb+ settings such as default timezone and rails gem version.
+
+Modify +db/seeds.rb+ to create the seed data for your installation of TicketMule. This is where you create your organization's groups, statuses, and priorities.
+
+Install gems:
+
+ $ rake gems:install
+
+Choose between basic installation or installation with test data:
+
+<b>Basic installation</b> create database and schema, and initialize with seed data:
+
+ $ rake db:setup
+
+<b>Test drive</b> create database and schema, initialize with seed data, and load 150 contacts, 500 tickets, and 4 non-admin users (see +lib/tasks/faker.rake+ for details):
+
+ $ rake faker
+
+== Notes
+
+By default, users can create their own accounts by navigating to /users/new and creating their account. If this is not desired and you only want admins to create user accounts, a small change to +config/routes.rb+ is required. The users resource will need the exception added for the <em>new</em> action. See the comments for the users resource map for details.
+
+When you add an alert to a ticket, you will only receive an email alert when the ticket's attributes change. You will not receive an email alert when a comment or attachment is added.
+
+== License
+
+Copyright (c) 2009 by J. Lee Smith. All rights reserved.
+
+TicketMule is released under the MIT License. See the LICENSE file for details.
+
+== Icons
+
+Fugue icons copyright (c) 2009 by Yusuke Kamiyamane. {Pinvoke.com}[http://www.pinvoke.com]
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,154 @@
+class AdminController < ApplicationController
+ before_filter :require_admin, :set_current_tab, :get_lists
+
+ def index
+ end
+
+ def add_group
+ @group = Group.new(params[:group])
+ redirect_to('/admin') and return if @group.name.blank?
+
+ respond_to do |format|
+ if @group.save
+ flash[:success] = "Group #{@group.name} was successfully created!"
+ format.html { redirect_to('/admin') }
+ else
+ #set initial tab to display errors...must match tab position in index view
+ @initial_tab_index = 0
+ format.html { render :action => 'index' }
+ end
+ end
+ end
+
+ def add_status
+ @status = Status.new(params[:status])
+ redirect_to('/admin') and return if @status.name.blank?
+
+ respond_to do |format|
+ if @status.save
+ flash[:success] = "Status #{@status.name} was successfully created!"
+ format.html { redirect_to('/admin') }
+ else
+ #set initial tab to display errors...must match tab position in index view
+ @initial_tab_index = 1
+ format.html { render :action => 'index' }
+ end
+ end
+ end
+
+ def add_priority
+ @priority = Priority.new(params[:priority])
+ redirect_to('/admin') and return if @priority.name.blank?
+
+ respond_to do |format|
+ if @priority.save
+ flash[:success] = "Priority #{@priority.name} was successfully created!"
+ format.html { redirect_to('/admin') }
+ else
+ #set initial tab to display errors...must match tab position in index view
+ @initial_tab_index = 2
+ format.html { render :action => 'index' }
+ end
+ end
+ end
+
+ def add_user
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ flash[:success] = "User #{@user.username} was successfully created!"
+ format.html { redirect_to('/admin') }
+ else
+ #set initial tab to display errors...must match tab position in index view
+ @initial_tab_index = 3
+ format.html { render :action => 'index' }
+ end
+ end
+ end
+
+ def toggle_group
+ @group = Group.find(params[:id])
+
+ if @group.enabled?
+ @group.disabled_at = DateTime.now
+ flash_msg = "Group #{@group.name} was successfully disabled!"
+ else
+ @group.disabled_at = nil
+ flash_msg = "Group #{@group.name} was successfully enabled!"
+ end
+
+ respond_to do |format|
+ if @group.save
+ flash[:success] = flash_msg
+ format.html { redirect_to('/admin') }
+ format.xml { render :xml => @group, :status => :created, :location => @group }
+ else
+ format.html { render :action => 'index' }
+ format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ def toggle_status
+ @status = Status.find(params[:id])
+
+ if @status.enabled?
+ @status.disabled_at = DateTime.now
+ flash_msg = "Status #{@status.name} was successfully disabled!"
+ else
+ @status.disabled_at = nil
+ flash_msg = "Status #{@status.name} was successfully enabled!"
+ end
+
+ respond_to do |format|
+ if @status.save
+ flash[:success] = flash_msg
+ format.html { redirect_to('/admin') }
+ format.xml { render :xml => @status, :status => :created, :location => @status }
+ else
+ format.html { render :action => 'index' }
+ format.xml { render :xml => @status.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ def toggle_priority
+ @priority = Priority.find(params[:id])
+
+ if @priority.enabled?
+ @priority.disabled_at = DateTime.now
+ flash_msg = "Priority #{@priority.name} was successfully disabled!"
+ else
+ @priority.disabled_at = nil
+ flash_msg = "Priority #{@priority.name} was successfully enabled!"
+ end
+
+ respond_to do |format|
+ if @priority.save
+ flash[:success] = flash_msg
+ format.html { redirect_to('/admin') }
+ format.xml { render :xml => @priority, :status => :created, :location => @priority }
+ else
+ format.html { render :action => 'index' }
+ format.xml { render :xml => @priority.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ private
+
+ def set_current_tab
+ @current_tab = :admin
+ end
+
+ def get_lists
+ @groups_enabled = Group.enabled
+ @groups_disabled = Group.disabled
+ @statuses_enabled = Status.enabled
+ @statuses_disabled = Status.disabled
+ @priorities_enabled = Priority.enabled
+ @priorities_disabled = Priority.disabled
+ end
+
+end
@@ -0,0 +1,32 @@
+class AlertsController < ApplicationController
+ before_filter :require_user
+
+ def create
+ @ticket = Ticket.find(params[:id])
+ @alert = @current_user.alerts.build(:ticket_id => @ticket.id)
+
+ respond_to do |format|
+ if @current_user.has_ticket_alert?(@ticket.id) or @alert.save
+ flash[:success] = 'Your alert was added and you will now receive an email any time this ticket is updated!'
+ format.html { redirect_to(@ticket) }
+ format.xml { render :xml => @alert, :status => :created, :location => @alert }
+ else
+ format.html { render 'tickets/show' }
+ format.xml { render :xml => @alert.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ def destroy
+ # for the current_user, delete the alert with the incoming ticket id
+ alert = Alert.find_by_ticket_id_and_user_id(params[:id], @current_user.id)
+ alert.destroy
+
+ respond_to do |format|
+ flash[:success] = "Your alert for ticket ##{params[:id]} was removed!"
+ format.html { redirect_to :back }
+ format.xml { head :ok }
+ end
+ end
+
+end
@@ -0,0 +1,87 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+ helper_method :current_user_session, :current_user
+ before_filter :set_time_zone
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ protect_from_forgery # :secret => '038c2ea0534ce4156b1aa41d6332e06c'
+
+ # See ActionController::Base for details
+ # Uncomment this to filter the contents of submitted sensitive data parameters
+ # from your application log (in this case, all fields with names like "password").
+ filter_parameter_logging :password, :password_confirmation
+
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
+ if instance.error_message.kind_of?(Array)
+ %(#{html_tag}<span class="validation-error">&nbsp;#{instance.error_message.join(', ')}</span>)
+ else
+ %(#{html_tag}<span class="validation-error">&nbsp;#{instance.error_message}</span>)
+ end
+ end
+
+ # get the tickets per page user preference...10 by default
+ def tickets_per_page
+ cookies[:tickets_per_page] || '10'
+ end
+
+ def current_user
+ return @current_user if defined?(@current_user)
+ @current_user = current_user_session && current_user_session.record
+ end
+
+ private
+
+ def set_time_zone
+ Time.zone = @current_user.time_zone if @current_user
+ end
+
+ def current_user_session
+ return @current_user_session if defined?(@current_user_session)
+ @current_user_session = UserSession.find
+ end
+
+ def require_user
+ unless current_user
+ store_location
+ flash[:error] = "You must be logged in to access this page!"
+ redirect_to login_path
+ return false
+ end
+ end
+
+ def require_no_user
+ if current_user
+ store_location
+ flash[:error] = "You must be logged out to access this page!"
+ redirect_to root_url
+ return false
+ end
+ end
+
+ def require_admin
+ unless current_user && current_user.admin?
+ store_location
+ flash[:error] = "Unauthorized access!"
+ redirect_to root_url
+ return false
+ end
+ end
+
+ def store_location
+ session[:return_to] =
+ if request.get?
+ request.request_uri
+ else
+ request.referrer
+ end
+ end
+
+ def redirect_back_or_default(default)
+ redirect_to(session[:return_to] || default)
+ session[:return_to] = nil
+ end
+end
Oops, something went wrong.

0 comments on commit 50ddae8

Please sign in to comment.