aldous 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.irbrc +3 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +591 -0
- data/Rakefile +1 -0
- data/aldous.gemspec +24 -0
- data/examples/basic_todo/.foreman +1 -0
- data/examples/basic_todo/.gitignore +16 -0
- data/examples/basic_todo/.rspec +3 -0
- data/examples/basic_todo/.ruby-version +2 -0
- data/examples/basic_todo/Gemfile +52 -0
- data/examples/basic_todo/Procfile +1 -0
- data/examples/basic_todo/README.rdoc +28 -0
- data/examples/basic_todo/Rakefile +6 -0
- data/examples/basic_todo/app/assets/images/.keep +0 -0
- data/examples/basic_todo/app/assets/javascripts/application.js +13 -0
- data/examples/basic_todo/app/assets/stylesheets/application.css +15 -0
- data/examples/basic_todo/app/controller_actions/base_action.rb +24 -0
- data/examples/basic_todo/app/controller_actions/base_precondition.rb +2 -0
- data/examples/basic_todo/app/controller_actions/home_controller/show.rb +8 -0
- data/examples/basic_todo/app/controller_actions/shared/ensure_user_not_disabled_precondition.rb +9 -0
- data/examples/basic_todo/app/controller_actions/sign_ins_controller/create.rb +24 -0
- data/examples/basic_todo/app/controller_actions/sign_ins_controller/destroy.rb +9 -0
- data/examples/basic_todo/app/controller_actions/sign_ins_controller/new.rb +7 -0
- data/examples/basic_todo/app/controller_actions/sign_ins_controller/user_params.rb +9 -0
- data/examples/basic_todo/app/controller_actions/sign_ups_controller/create.rb +23 -0
- data/examples/basic_todo/app/controller_actions/sign_ups_controller/new.rb +7 -0
- data/examples/basic_todo/app/controller_actions/sign_ups_controller/user_params.rb +9 -0
- data/examples/basic_todo/app/controller_actions/todos/all_completed_controller/destroy.rb +17 -0
- data/examples/basic_todo/app/controller_actions/todos/completed_controller/create.rb +29 -0
- data/examples/basic_todo/app/controller_actions/todos_controller/create.rb +26 -0
- data/examples/basic_todo/app/controller_actions/todos_controller/destroy.rb +21 -0
- data/examples/basic_todo/app/controller_actions/todos_controller/edit.rb +19 -0
- data/examples/basic_todo/app/controller_actions/todos_controller/index.rb +19 -0
- data/examples/basic_todo/app/controller_actions/todos_controller/new.rb +17 -0
- data/examples/basic_todo/app/controller_actions/todos_controller/todo_params.rb +9 -0
- data/examples/basic_todo/app/controller_actions/todos_controller/update.rb +28 -0
- data/examples/basic_todo/app/controller_actions/users_controller/index.rb +19 -0
- data/examples/basic_todo/app/controllers/application_controller.rb +9 -0
- data/examples/basic_todo/app/controllers/home_controller.rb +5 -0
- data/examples/basic_todo/app/controllers/sign_ins_controller.rb +5 -0
- data/examples/basic_todo/app/controllers/sign_ups_controller.rb +5 -0
- data/examples/basic_todo/app/controllers/todos/all_completed_controller.rb +5 -0
- data/examples/basic_todo/app/controllers/todos/completed_controller.rb +5 -0
- data/examples/basic_todo/app/controllers/todos_controller.rb +5 -0
- data/examples/basic_todo/app/controllers/users_controller.rb +5 -0
- data/examples/basic_todo/app/helpers/application_helper.rb +2 -0
- data/examples/basic_todo/app/mailers/.keep +0 -0
- data/examples/basic_todo/app/models/ability.rb +27 -0
- data/examples/basic_todo/app/models/role.rb +5 -0
- data/examples/basic_todo/app/models/todo.rb +5 -0
- data/examples/basic_todo/app/models/user.rb +12 -0
- data/examples/basic_todo/app/models/user_role.rb +5 -0
- data/examples/basic_todo/app/services/create_user_service.rb +26 -0
- data/examples/basic_todo/app/services/find_current_user_service.rb +29 -0
- data/examples/basic_todo/app/services/sign_in_service.rb +13 -0
- data/examples/basic_todo/app/services/sign_out_service.rb +12 -0
- data/examples/basic_todo/app/views/base_view.rb +18 -0
- data/examples/basic_todo/app/views/defaults/bad_request.html.slim +12 -0
- data/examples/basic_todo/app/views/defaults/bad_request_view.rb +15 -0
- data/examples/basic_todo/app/views/defaults/forbidden.html.slim +6 -0
- data/examples/basic_todo/app/views/defaults/forbidden_view.rb +14 -0
- data/examples/basic_todo/app/views/defaults/server_error.html.slim +12 -0
- data/examples/basic_todo/app/views/defaults/server_error_view.rb +14 -0
- data/examples/basic_todo/app/views/home/show.html.slim +5 -0
- data/examples/basic_todo/app/views/home/show_redirect.rb +5 -0
- data/examples/basic_todo/app/views/home/show_view.rb +7 -0
- data/examples/basic_todo/app/views/layouts/application.html.slim +18 -0
- data/examples/basic_todo/app/views/modules/_header.html.slim +13 -0
- data/examples/basic_todo/app/views/modules/header_view.rb +7 -0
- data/examples/basic_todo/app/views/sign_ins/new.html.slim +14 -0
- data/examples/basic_todo/app/views/sign_ins/new_view.rb +10 -0
- data/examples/basic_todo/app/views/sign_ups/new.html.slim +13 -0
- data/examples/basic_todo/app/views/sign_ups/new_view.rb +10 -0
- data/examples/basic_todo/app/views/todos/edit.html.slim +14 -0
- data/examples/basic_todo/app/views/todos/edit_view.rb +10 -0
- data/examples/basic_todo/app/views/todos/index.html.slim +12 -0
- data/examples/basic_todo/app/views/todos/index_redirect.rb +5 -0
- data/examples/basic_todo/app/views/todos/index_view/_todo.html.slim +8 -0
- data/examples/basic_todo/app/views/todos/index_view/todo_view.rb +28 -0
- data/examples/basic_todo/app/views/todos/index_view.rb +26 -0
- data/examples/basic_todo/app/views/todos/new.html.slim +14 -0
- data/examples/basic_todo/app/views/todos/new_view.rb +10 -0
- data/examples/basic_todo/app/views/todos/not_found.html.slim +6 -0
- data/examples/basic_todo/app/views/todos/not_found_view.rb +15 -0
- data/examples/basic_todo/app/views/users/index.html.slim +7 -0
- data/examples/basic_todo/app/views/users/index_redirect.rb +5 -0
- data/examples/basic_todo/app/views/users/index_view/_user.html.slim +2 -0
- data/examples/basic_todo/app/views/users/index_view/user_view.rb +22 -0
- data/examples/basic_todo/app/views/users/index_view.rb +26 -0
- data/examples/basic_todo/bin/bundle +3 -0
- data/examples/basic_todo/bin/rails +8 -0
- data/examples/basic_todo/bin/rake +8 -0
- data/examples/basic_todo/bin/rspec +7 -0
- data/examples/basic_todo/bin/spring +15 -0
- data/examples/basic_todo/config/application.rb +41 -0
- data/examples/basic_todo/config/boot.rb +4 -0
- data/examples/basic_todo/config/database.yml +25 -0
- data/examples/basic_todo/config/environment.rb +5 -0
- data/examples/basic_todo/config/environments/development.rb +37 -0
- data/examples/basic_todo/config/environments/production.rb +78 -0
- data/examples/basic_todo/config/environments/test.rb +39 -0
- data/examples/basic_todo/config/initializers/aldous.rb +3 -0
- data/examples/basic_todo/config/initializers/assets.rb +8 -0
- data/examples/basic_todo/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/basic_todo/config/initializers/cookies_serializer.rb +3 -0
- data/examples/basic_todo/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/basic_todo/config/initializers/inflections.rb +16 -0
- data/examples/basic_todo/config/initializers/mime_types.rb +4 -0
- data/examples/basic_todo/config/initializers/session_store.rb +3 -0
- data/examples/basic_todo/config/initializers/wrap_parameters.rb +14 -0
- data/examples/basic_todo/config/locales/en.yml +23 -0
- data/examples/basic_todo/config/routes.rb +18 -0
- data/examples/basic_todo/config/secrets.yml +22 -0
- data/examples/basic_todo/config.ru +4 -0
- data/examples/basic_todo/db/migrate/20150226035524_create_user.rb +10 -0
- data/examples/basic_todo/db/migrate/20150227004411_create_todo.rb +11 -0
- data/examples/basic_todo/db/migrate/20150301110126_roles.rb +22 -0
- data/examples/basic_todo/db/migrate/20150301121923_add_user_disabled_column.rb +5 -0
- data/examples/basic_todo/db/schema.rb +45 -0
- data/examples/basic_todo/db/seeds.rb +7 -0
- data/examples/basic_todo/lib/assets/.keep +0 -0
- data/examples/basic_todo/lib/tasks/.keep +0 -0
- data/examples/basic_todo/log/.keep +0 -0
- data/examples/basic_todo/public/404.html +67 -0
- data/examples/basic_todo/public/422.html +67 -0
- data/examples/basic_todo/public/500.html +66 -0
- data/examples/basic_todo/public/favicon.ico +0 -0
- data/examples/basic_todo/public/robots.txt +5 -0
- data/examples/basic_todo/test/controllers/.keep +0 -0
- data/examples/basic_todo/test/fixtures/.keep +0 -0
- data/examples/basic_todo/test/helpers/.keep +0 -0
- data/examples/basic_todo/test/integration/.keep +0 -0
- data/examples/basic_todo/test/mailers/.keep +0 -0
- data/examples/basic_todo/test/models/.keep +0 -0
- data/examples/basic_todo/test/test_helper.rb +10 -0
- data/examples/basic_todo/vendor/assets/javascripts/.keep +0 -0
- data/examples/basic_todo/vendor/assets/stylesheets/.keep +0 -0
- data/lib/aldous/build_respondable_service.rb +23 -0
- data/lib/aldous/configuration.rb +18 -0
- data/lib/aldous/controller/action/precondition/wrapper.rb +32 -0
- data/lib/aldous/controller/action/precondition.rb +52 -0
- data/lib/aldous/controller/action/result_execution_service.rb +27 -0
- data/lib/aldous/controller/action/wrapper.rb +34 -0
- data/lib/aldous/controller/action_execution_service.rb +42 -0
- data/lib/aldous/controller/preconditions_execution_service.rb +32 -0
- data/lib/aldous/controller.rb +21 -0
- data/lib/aldous/controller_action.rb +63 -0
- data/lib/aldous/dummy_error_reporter.rb +9 -0
- data/lib/aldous/dummy_logger.rb +8 -0
- data/lib/aldous/errors/user_error.rb +6 -0
- data/lib/aldous/logging_wrapper.rb +16 -0
- data/lib/aldous/params.rb +34 -0
- data/lib/aldous/respondable/base.rb +32 -0
- data/lib/aldous/respondable/headable.rb +30 -0
- data/lib/aldous/respondable/redirectable.rb +38 -0
- data/lib/aldous/respondable/renderable.rb +50 -0
- data/lib/aldous/respondable/request_http_basic_authentication.rb +23 -0
- data/lib/aldous/respondable/send_data.rb +36 -0
- data/lib/aldous/respondable/shared/flash.rb +24 -0
- data/lib/aldous/service/result/base/predicate_methods_for_inheritance.rb +44 -0
- data/lib/aldous/service/result/base.rb +13 -0
- data/lib/aldous/service/result/failure.rb +11 -0
- data/lib/aldous/service/result/success.rb +11 -0
- data/lib/aldous/service/wrapper.rb +48 -0
- data/lib/aldous/service.rb +34 -0
- data/lib/aldous/simple_dto.rb +47 -0
- data/lib/aldous/stdout_logger.rb +9 -0
- data/lib/aldous/version.rb +3 -0
- data/lib/aldous/view/blank/atom_view.rb +12 -0
- data/lib/aldous/view/blank/html_view.rb +16 -0
- data/lib/aldous/view/blank/json_view.rb +16 -0
- data/lib/aldous.rb +40 -0
- data/spec/aldous/build_respondable_service_spec.rb +48 -0
- data/spec/aldous/configuration_spec.rb +15 -0
- data/spec/aldous/controller/action/precondition/wrapper_spec.rb +48 -0
- data/spec/aldous/controller/action/precondition_spec.rb +81 -0
- data/spec/aldous/controller/action/result_execution_service_spec.rb +43 -0
- data/spec/aldous/controller/action/wrapper_spec.rb +46 -0
- data/spec/aldous/controller/action_execution_service_spec.rb +79 -0
- data/spec/aldous/controller/preconditions_execution_service_spec.rb +45 -0
- data/spec/aldous/controller_action_spec.rb +97 -0
- data/spec/aldous/controller_spec.rb +25 -0
- data/spec/aldous/dummy_error_reporter_spec.rb +10 -0
- data/spec/aldous/dummy_logger_spec.rb +7 -0
- data/spec/aldous/logging_wrapper_spec.rb +55 -0
- data/spec/aldous/params_spec.rb +39 -0
- data/spec/aldous/respondable/base_spec.rb +11 -0
- data/spec/aldous/respondable/headable/head_action_spec.rb +17 -0
- data/spec/aldous/respondable/headable_spec.rb +20 -0
- data/spec/aldous/respondable/redirectable/redirect_action_spec.rb +34 -0
- data/spec/aldous/respondable/redirectable_spec.rb +26 -0
- data/spec/aldous/respondable/renderable/render_action_spec.rb +34 -0
- data/spec/aldous/respondable/renderable_spec.rb +46 -0
- data/spec/aldous/respondable/request_http_basic_authentication_spec.rb +0 -0
- data/spec/aldous/respondable/send_data/send_data_action_spec.rb +15 -0
- data/spec/aldous/respondable/send_data_spec.rb +30 -0
- data/spec/aldous/respondable/shared/flash_spec.rb +30 -0
- data/spec/aldous/service/result/failure_spec.rb +11 -0
- data/spec/aldous/service/result/success_spec.rb +11 -0
- data/spec/aldous/service/wrapper_spec.rb +110 -0
- data/spec/aldous/service_spec.rb +101 -0
- data/spec/aldous/simple_dto_spec.rb +40 -0
- data/spec/aldous/view/blank/atom_view_spec.rb +15 -0
- data/spec/aldous/view/blank/html_view_spec.rb +15 -0
- data/spec/aldous/view/blank/json_view_spec.rb +15 -0
- data/spec/spec_helper.rb +26 -0
- metadata +330 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*.log
|
16
|
+
/tmp
|
@@ -0,0 +1,52 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
ruby '2.2.0'
|
4
|
+
|
5
|
+
gem 'aldous', path: '../../'
|
6
|
+
|
7
|
+
gem 'rails', '4.2.0'
|
8
|
+
gem 'sqlite3'
|
9
|
+
gem 'bcrypt', '~> 3.1.7'
|
10
|
+
|
11
|
+
gem 'slim-rails'
|
12
|
+
gem 'sass-rails', '~> 5.0'
|
13
|
+
gem 'coffee-rails', '~> 4.1.0'
|
14
|
+
gem 'uglifier', '>= 1.3.0'
|
15
|
+
gem 'autoprefixer-rails'
|
16
|
+
gem 'kaminari'
|
17
|
+
#gem 'handlebars_assets'
|
18
|
+
|
19
|
+
gem 'configatron'
|
20
|
+
gem 'yajl-ruby', require: 'yajl/json_gem'
|
21
|
+
|
22
|
+
gem 'dalli'
|
23
|
+
|
24
|
+
gem 'awesome_print'
|
25
|
+
gem 'cancancan', '~> 1.10'
|
26
|
+
|
27
|
+
group :development, :test do
|
28
|
+
gem 'pry-rails'
|
29
|
+
gem 'pry-byebug'
|
30
|
+
gem 'spring'
|
31
|
+
gem 'spring-commands-rspec'
|
32
|
+
gem 'rspec-rails'
|
33
|
+
gem 'annotate'
|
34
|
+
end
|
35
|
+
|
36
|
+
group :test do
|
37
|
+
gem 'capybara'
|
38
|
+
gem 'poltergeist'
|
39
|
+
gem 'timecop'
|
40
|
+
gem 'database_cleaner'
|
41
|
+
gem 'webmock'
|
42
|
+
end
|
43
|
+
|
44
|
+
group :development do
|
45
|
+
gem 'foreman'
|
46
|
+
gem 'quiet_assets'
|
47
|
+
gem 'thin'
|
48
|
+
end
|
49
|
+
|
50
|
+
group :development, :staging do
|
51
|
+
gem 'faker'
|
52
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
web: bin/rails server -p ${PORT}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class BaseAction < ::Aldous::ControllerAction
|
2
|
+
def default_view_data
|
3
|
+
{
|
4
|
+
current_user: current_user,
|
5
|
+
current_ability: current_ability,
|
6
|
+
}
|
7
|
+
end
|
8
|
+
|
9
|
+
def preconditions
|
10
|
+
[Shared::EnsureUserNotDisabledPrecondition]
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_error_respondable
|
14
|
+
Defaults::ServerErrorView
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_user
|
18
|
+
@current_user ||= FindCurrentUserService.perform(session).user
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_ability
|
22
|
+
@current_ability ||= Ability.new(current_user)
|
23
|
+
end
|
24
|
+
end
|
data/examples/basic_todo/app/controller_actions/shared/ensure_user_not_disabled_precondition.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
class Shared::EnsureUserNotDisabledPrecondition < BasePrecondition
|
2
|
+
delegate :current_user, :current_ability, to: :action
|
3
|
+
|
4
|
+
def perform
|
5
|
+
if current_user && current_user.disabled && !current_ability.can?(:manage, :all)
|
6
|
+
return build_view(Defaults::ForbiddenView, errors: ['Your account has been disabled'])
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class SignInsController::Create < BaseAction
|
2
|
+
def perform
|
3
|
+
return build_view(Todos::IndexRedirect) if current_user
|
4
|
+
return build_view(Defaults::BadRequestView, status: :bad_request, errors: [user_params.error_message]) unless user_params.fetch
|
5
|
+
return build_view(SignIns::NewView, status: :not_found) unless user
|
6
|
+
|
7
|
+
if user.authenticate(user_params.fetch[:password])
|
8
|
+
SignInService.perform!(session, user)
|
9
|
+
build_view(Todos::IndexRedirect)
|
10
|
+
else
|
11
|
+
build_view(SignIns::NewView, status: :unprocessable_entity, errors: ["Incorrect credentials"])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def user_params
|
18
|
+
@user_params ||= ::SignInsController::UserParams.build(params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def user
|
22
|
+
@user ||= User.where(email: user_params.fetch[:email]).first
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class SignUpsController::Create < BaseAction
|
2
|
+
def perform
|
3
|
+
return build_view(Todos::IndexRedirect) if current_user
|
4
|
+
return build_view(Defaults::BadRequestView, errors: [user_params.error_message]) unless user_params.fetch
|
5
|
+
|
6
|
+
if create_user_result.success?
|
7
|
+
SignInService.perform!(session, create_user_result.user)
|
8
|
+
build_view(Todos::IndexRedirect)
|
9
|
+
else
|
10
|
+
build_view(SignUps::NewView)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def create_user_result
|
17
|
+
@create_user_result ||= CreateUserService.perform(user_params.fetch)
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_params
|
21
|
+
@user_params ||= ::SignUpsController::UserParams.build(params)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Todos::AllCompletedController::Destroy < BaseAction
|
2
|
+
def perform
|
3
|
+
return build_view(Home::ShowRedirect) unless current_user
|
4
|
+
|
5
|
+
if todos.destroy_all
|
6
|
+
build_view(Todos::IndexRedirect)
|
7
|
+
else
|
8
|
+
build_view(Defaults::ServerErrorView, errors: ['Unable to delete completed todos'])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def todos
|
15
|
+
@todo ||= Todo.where(user_id: current_user.id).where(done: true)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Todos::CompletedController::Create < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({todo: todo})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Home::ShowRedirect) unless current_user
|
8
|
+
return build_view(Todos::NotFoundView, todo_id: todo_id) unless todo
|
9
|
+
return build_view(Defaults::ForbiddenView) unless current_ability.can?(:update, todo)
|
10
|
+
|
11
|
+
todo.done = true
|
12
|
+
|
13
|
+
if todo.save
|
14
|
+
build_view(Todos::IndexRedirect)
|
15
|
+
else
|
16
|
+
build_view(Defaults::ServerErrorView, errors: ["Unable to mark todo completed"])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def todo
|
23
|
+
@todo ||= Todo.where(id: todo_id).first
|
24
|
+
end
|
25
|
+
|
26
|
+
def todo_id
|
27
|
+
params[:todo_id]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class TodosController::Create < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({todo: todo})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Home::ShowRedirect) unless current_user
|
8
|
+
return build_view(Defaults::BadRequestView, errors: [todo_params.error_message]) unless todo_params.fetch
|
9
|
+
|
10
|
+
if todo.save
|
11
|
+
build_view(Todos::IndexRedirect)
|
12
|
+
else
|
13
|
+
build_view(Todos::NewView)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def todo
|
20
|
+
@todo ||= Todo.new(todo_params.fetch)
|
21
|
+
end
|
22
|
+
|
23
|
+
def todo_params
|
24
|
+
TodosController::TodoParams.build(params)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class TodosController::Destroy < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({todo: todo})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Home::ShowRedirect) unless current_user
|
8
|
+
return build_view(Todos::NotFoundView, todo_id: params[:id]) unless todo
|
9
|
+
return build_view(Defaults::ForbiddenView) unless current_ability.can?(:destroy, todo)
|
10
|
+
|
11
|
+
todo.destroy
|
12
|
+
|
13
|
+
build_view(Todos::IndexRedirect)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def todo
|
19
|
+
@todo ||= Todo.where(id: params[:id]).first
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class TodosController::Edit < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({todo: todo})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Home::ShowRedirect) unless current_user
|
8
|
+
return build_view(Todos::NotFoundView, todo_id: params[:id]) unless todo
|
9
|
+
return build_view(Defaults::ForbiddenView) unless current_ability.can?(:update, todo)
|
10
|
+
|
11
|
+
build_view(Todos::EditView)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def todo
|
17
|
+
@todo ||= Todo.where(id: params[:id]).first
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class TodosController::Index < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({todos: todos})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Home::ShowRedirect) unless current_user
|
8
|
+
|
9
|
+
build_view(Todos::IndexView)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def todos
|
15
|
+
Todo.where(user_id: current_user.id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class TodosController::New < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({todo: todo})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Home::ShowRedirect) unless current_user
|
8
|
+
|
9
|
+
build_view(Todos::NewView)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def todo
|
15
|
+
@todo ||= Todo.new(user_id: current_user.id)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class TodosController::Update < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({todo: todo})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Home::ShowRedirect) unless current_user
|
8
|
+
return build_view(Defaults::BadRequestView, errors: [todo_params.error_message]) unless todo_params.fetch
|
9
|
+
return build_view(Todos::NotFoundView, todo_id: params[:id]) unless todo
|
10
|
+
return build_view(Defaults::ForbiddenView) unless current_ability.can?(:update, todo)
|
11
|
+
|
12
|
+
if todo.update_attributes(todo_params.fetch)
|
13
|
+
build_view(Todos::IndexRedirect)
|
14
|
+
else
|
15
|
+
build_view(Todos::EditView)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def todo
|
22
|
+
@todo ||= Todo.where(id: params[:id]).first
|
23
|
+
end
|
24
|
+
|
25
|
+
def todo_params
|
26
|
+
TodosController::TodoParams.build(params)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class UsersController::Index < BaseAction
|
2
|
+
def default_view_data
|
3
|
+
super.merge({users: users})
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
return build_view(Defaults::ForbiddenView) unless current_ability.can?(:index, User)
|
8
|
+
|
9
|
+
build_view(Users::IndexView)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def users
|
15
|
+
User.all
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Ability
|
2
|
+
include CanCan::Ability
|
3
|
+
|
4
|
+
attr_reader :user
|
5
|
+
|
6
|
+
def initialize(user)
|
7
|
+
@user = user || User.new
|
8
|
+
@user.roles.each { |role| send(role.name.downcase) }
|
9
|
+
|
10
|
+
if @user.roles.size == 0
|
11
|
+
guest
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def guest
|
16
|
+
end
|
17
|
+
|
18
|
+
def account_holder
|
19
|
+
can :manage, Todo, user_id: user.id
|
20
|
+
can :create, User
|
21
|
+
can [:read, :update], user
|
22
|
+
end
|
23
|
+
|
24
|
+
def admin
|
25
|
+
can :manage, :all
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
has_many :todos
|
3
|
+
|
4
|
+
has_many :user_roles
|
5
|
+
has_many :roles, through: :user_roles
|
6
|
+
|
7
|
+
has_secure_password validations: false
|
8
|
+
|
9
|
+
validates :email, presence: true, uniqueness: true
|
10
|
+
validates :password, presence: true
|
11
|
+
end
|
12
|
+
|