Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#WIP Improvements to offspring_controller #47

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8668d71
WIP Addition of tests to enable admin to stop changes in users, as TO…
alexvkcr Jul 26, 2016
bf14d4f
Manual rebase
alexvkcr Aug 26, 2016
52ae215
Manual rebase
alexvkcr Aug 26, 2016
cc2e7fa
Manual rebase 2
alexvkcr Aug 26, 2016
3ffeca9
Manual rebase 3
alexvkcr Aug 26, 2016
0cfff12
Little fixes
alexvkcr Aug 24, 2016
6b11039
manual rebase
alexvkcr Aug 29, 2016
1cce4a1
Undo rubocop failure in spec helper
alexvkcr Aug 26, 2016
6d58665
Rubocop fixes
alexvkcr Aug 26, 2016
dfcf989
Rename of some methods
alexvkcr Aug 26, 2016
70142f3
Update back to split PR #14
alexvkcr Aug 29, 2016
7da0752
joined system lock view with functionality
katafira Aug 30, 2016
38e791e
small link fix in view
katafira Aug 30, 2016
e9ee880
normal users cannot assign shifts if system is locked
katafira Aug 30, 2016
580e406
fixed persistence problem
alexvkcr Aug 31, 2016
213ff7f
Fix for rubocop
alexvkcr Aug 31, 2016
c998932
Merge branch 'master' into admin_stop
alexvkcr Aug 31, 2016
28a02ff
WIP Addition of tests to enable admin to stop changes in users, as TO…
alexvkcr Jul 26, 2016
b7139c5
Manual rebase
alexvkcr Aug 26, 2016
653e596
Manual rebase
alexvkcr Aug 26, 2016
30397cb
Manual rebase 2
alexvkcr Aug 26, 2016
0aeef33
Manual rebase 3
alexvkcr Aug 26, 2016
82f8361
Little fixes
alexvkcr Aug 24, 2016
608b332
manual rebase
alexvkcr Aug 29, 2016
fc654a4
Undo rubocop failure in spec helper
alexvkcr Aug 26, 2016
599c608
Rubocop fixes
alexvkcr Aug 26, 2016
a62aaa2
Rename of some methods
alexvkcr Aug 26, 2016
9bebf64
Update back to split PR #14
alexvkcr Aug 29, 2016
c8a3f08
manual rebase
katafira Sep 1, 2016
609fa1c
manual rebase 2
katafira Sep 1, 2016
273a3f7
normal users cannot assign shifts if system is locked
katafira Aug 30, 2016
041c278
manual rebase 3
katafira Sep 1, 2016
4dd62ed
manual rebase 4
katafira Sep 1, 2016
db4b7ac
manual rebase 5
katafira Sep 1, 2016
47485e1
manual rebase 6
katafira Sep 1, 2016
e54c7de
Little fixes
alexvkcr Aug 24, 2016
52914cd
manual rebase
alexvkcr Aug 29, 2016
1f232d2
Undo rubocop failure in spec helper
alexvkcr Aug 26, 2016
5d123ad
manual rebase 9
katafira Sep 1, 2016
695bd58
manual rebase 10
katafira Sep 1, 2016
6522ca2
manual rebase 11
katafira Sep 1, 2016
8a8c88d
manual rebase 13
katafira Sep 1, 2016
e83f534
Fix for rubocop
alexvkcr Aug 31, 2016
ec5efc4
manual rebase 15
katafira Sep 1, 2016
b87eca3
updated rack gem to fix ddos vulnerability
katafira Sep 1, 2016
d96404f
Merge branch 'master' into admin_stop
Sep 1, 2016
b2aac19
Merge branch 'master' into admin_stop
Sep 1, 2016
03c344e
Little changes to controller alert msgs
Aug 31, 2016
58c2cee
Finished controller fixes
Aug 31, 2016
6af38f0
Fixed tiny error
Aug 31, 2016
e32f4c7
WIP1
Sep 1, 2016
bf54b7b
WIP1.1
Sep 1, 2016
4f981b5
Finish fixing bug
Sep 1, 2016
3298542
Finished and ready to upload
Sep 1, 2016
9dae3c8
Rebase con admin_stop
Sep 1, 2016
a1efb73
Manual Rebase 1
Sep 2, 2016
39f9183
Manual rebase 2
Sep 2, 2016
3d53e7f
Manual rebase 3
Sep 2, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end
# Add rack specific version to fix deployment error
# in OpenShift online

gem 'rack', '1.5.2'
gem 'rack'

# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
Expand Down
7 changes: 2 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rack (1.5.5)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.16)
Expand Down Expand Up @@ -277,7 +277,7 @@ DEPENDENCIES
minitest-reporters
patternfly-sass (~> 3.8.0)
pg
rack (= 1.5.2)
rack
rails (~> 4.1)
rake
rspec-rails (~> 3.4)
Expand All @@ -291,6 +291,3 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.12.5
5 changes: 5 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def rooms
@rooms = Room.all
end

def switch_lock_admin
ApplicationHelper.switch_lock
render nothing: true
end

private

def admin_user?
Expand Down
28 changes: 22 additions & 6 deletions app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
class AssignmentsController < ApplicationController
SCOPE = "activerecord.errors.controllers.assignment".freeze # Necessary to acces locales file
def new
@offspring = Offspring.find_by_id(params[:format])
@rooms = Room.all
end

def create
Offspring.transaction do
of = Offspring.lock.find_by_id(params["format"])
of.shift = Shift.find_by_id(params["shift"])
of.save
redirect_to root_url
end
access_control? ? create_assignment : flash[:alert] = I18n.t("admin_locked_create", scope: SCOPE)
redirect_to root_url
end

def destroy
Expand All @@ -19,4 +16,23 @@ def destroy
of.save
redirect_to new_assignment_path(of)
end

private

def access_control?
if current_user.admin?
true
else
!ApplicationHelper.status_lock?
end
end

def create_assignment
Offspring.transaction do
of = Offspring.lock.find_by_id(params["format"])
of.shift = Shift.find_by_id(params["shift"])
of.save
flash[:success] = I18n.t("assignment_create_success", scope: SCOPE)
end
end
end
48 changes: 37 additions & 11 deletions app/controllers/offsprings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
# Offsprings are dependent on users and are the ones that get assigned to shifts
# They can't be assigned themselves, and need the process to be done by the user
class OffspringsController < ApplicationController
SCOPE = "activerecord.errors.controllers.offspring".freeze # Necessary to acces locales file
def show
end

def index
end

def new
@offspring = current_user.offsprings.build
end

def create
@offspring = current_user.offsprings.build(offsprings_params)
if [email protected]_first?
flash[:warning] = "Sólo puede añadir a niños de 1º de Primaria"
redirect_to static_pages_intructions_path
return
elsif @offspring.save
flash[:success] = "Niño añadido"
if access_control?
@offspring = current_user.offsprings.build(offsprings_params)
return unless validate_create_offspring? @offspring
else
flash[:danger] = "No se pudo añadir al niño"
flash[:alert] = I18n.t("admin_locked_create", scope: SCOPE)
end
redirect_to root_path
end

def destroy
offspring = Offspring.find_by_id(params[:id])
offspring.destroy
flash[:success] = "Niño borrado"
if access_control?
offspring = Offspring.find_by_id(params[:id])
offspring.destroy
flash[:success] = I18n.t("offspring_deleted", scope: SCOPE)
else
flash[:alert] = I18n.t("admin_locked_destroy", scope: SCOPE)
end
redirect_to request.referer || root_url
end

Expand All @@ -34,4 +38,26 @@ def destroy
def offsprings_params
params.require(:offspring).permit(:first_name, :last_name, :grade)
end

def save_offspring(off)
if off.save
flash[:success] = I18n.t("add_offspring_success", scope: SCOPE)
else
flash[:danger] = I18n.t("add_offspring_failure", scope: SCOPE)
end
end

def access_control?
!ApplicationHelper.status_lock?
end

def validate_create_offspring?(off)
unless off.primary_first?
flash[:warning] = I18n.t("condition_primary_grade", scope: SCOPE)
redirect_to static_pages_intructions_path
return false
end
save_offspring(off)
true
end
end
10 changes: 6 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def destroy
private

def delete_possible?(user)
if user.nil?
return false
elsif user == current_user
if current_user.admin?
return true
elsif user.nil?
return false
elsif !current_user.admin?
elsif user != current_user
return false
elsif current_user.admin?
return true
else
return true
end
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ def week_day_convert(day)
week = {1 => 'Lunes', 2 => 'Martes', 3 => 'Miércoles', 4 => 'Jueves', 5 => 'Viernes', 6 => 'Sábado', 7 => 'Domingo'}
week[day] || 'Ninguno'
end

def self.status_lock?
Rails.application.config.lock.status
end

def self.switch_lock
Rails.application.config.lock.status = !Rails.application.config.lock.status
end
end
73 changes: 61 additions & 12 deletions app/views/admin/_system_admin_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
<div class="panel panel-default">
<<<<<<< HEAD


<div style="float:left; width: 50%;">
<div class="panel-heading">
<h3 id= "blocker_panel_title" class="panel-title"><%="Bloqueo de cambios"%></h3>
</div>
<div class="panel-body">
<div class="container-fluid">
<p>
<ul class="list-group">
<li> Ésta acción permite al administrador bloquear cambios que puedan hacer los usuarios.
<ol>
<li> No se podrán añadir usuarios nuevos. </li>
<li> No se podrán agregar hijos. </li>
<li> No podrán cambiar o reasignar aulas/turnos a no ser que seas administrador. </li>
<li> Cada usuario <b>SÍ</b> podrá borrar su cuenta. </li>
</ol>
</li>
<div>
<%if ApplicationHelper.status_lock?%>
<input class="bootstrap-switch" id="bootstrap-switch-state" type="checkbox" checked>
<%else%>
<input class="bootstrap-switch" id="bootstrap-switch-state" type="checkbox" unchecked>
<%end%>
<script>
jQuery(".bootstrap-switch").bootstrapSwitch().on('switchChange.bootstrapSwitch', function () {
$.ajax({
url: "/switch_lock_admin%22",
type: 'POST'
});
});
</script>

</div>
</p>
</div>
</div>
</div>

=======
>>>>>>> b2aac19f380a5af8fe393e0b2108ca56601ea8dc
<div style="float:left; width: 50%;">
<div class="panel-heading">
<h3 id= "blocker_panel_title" class="panel-title"><%="Bloqueo de cambios"%></h3>
</div>

<div class="panel-body">
<div class="container-fluid">
<p>
Expand All @@ -16,17 +57,25 @@
<li> Cada usuario <b>SÍ</b> podrá borrar su cuenta. </li>
</ol>
</li>
</ul>
<div>
<input class="bootstrap-switch" id="bootstrap-switch-state" type="checkbox" checked>
<script>
jQuery(".bootstrap-switch").bootstrapSwitch();
</script>
</div>
</p>
<div>
<%if ApplicationHelper.status_lock?%>
<input class="bootstrap-switch" id="bootstrap-switch-state" type="checkbox" checked>
<%else%>
<input class="bootstrap-switch" id="bootstrap-switch-state" type="checkbox" unchecked>
<%end%>
<script>
jQuery(".bootstrap-switch").bootstrapSwitch().on('switchChange.bootstrapSwitch', function () {
$.ajax({
url: "/switch_lock_admin%22",
type: 'POST'
});
});
</script>
</div>
</p>
</div>
</div>
</div>
</div>
</div>

<div style="float:left; width: 50%;">
<div class="panel-heading">
Expand All @@ -42,4 +91,4 @@
</div>
</div>
</div>
</div>
</div>
7 changes: 7 additions & 0 deletions config/initializers/lock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# lock_config = Rails.application.config_for(:lock)

Rails.application.configure do
config.lock = ActiveSupport::OrderedOptions.new
config.lock.status = false
end
15 changes: 15 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ es:

messages:
record_invalid: "no es válido"

controllers:
offspring:
admin_locked_create: "No se puedo añadir al niño en este momento, espere."
admin_locked_destroy: "No se puedo destruir al niño en este momento, espere."
offspring_deleted: "El niño ha sido elimidado con éxito."
condition_primary_grade: "Sólo puede añadir a niños de 1º de Primaria"
add_offspring_success: "El niño ha sido añadido con éxito"
add_offspring_failure: "No ha sido posible añadir al niño."
assignment:
admin_locked_create: "No se puedo añadir al niño en este momento, espere."
assignment_create_success: "Niño asignado correctamente"
attributes:
user:
first_name: "Nombre"
Expand All @@ -123,3 +135,6 @@ es:
first_name: "Nombre"
last_name: "Apellidos"
grade: "Curso"
controllers:
assignment:
admin_locked_create: "No se puedo añadir al niño en este momento, espere."
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
resources :assignments, only: [:new, :create, :destroy]
resources :shifts, only: [:show]
get 'admin' => 'admin#dashboard'
post 'switch_lock_admin"' => 'admin#switch_lock_admin'
get 'offsprings' => 'admin#offsprings'
get 'users' => 'admin#users'
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160404181436_add_admin_to_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ class AddAdminToUser < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, default: false
end
end
end
Loading