Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
32560ee4
Commit
32560ee4
authored
Aug 25, 2017
by
Chrysanthi Lagodimou
Browse files
nest hour routes to volunteer
parent
88816344
Changes
21
Hide whitespace changes
Inline
Side-by-side
app/controllers/hours_controller.rb
View file @
32560ee4
class
HoursController
<
ApplicationController
include
MakeNotice
before_action
:set_hour
,
only:
[
:show
,
:edit
,
:update
,
:destroy
]
before_action
:set_houred
def
index
authorize
Hour
@hours
=
Hour
.
all
hour
=
Hour
.
new
(
volunteer:
@houred
)
authorize
hour
@hours
=
Hour
.
where
(
volunteer:
@houred
)
end
def
show
;
end
def
new
@hour
=
Hour
.
new
(
volunteer
_id:
params
[
:volunteer_id
]
)
@hour
=
Hour
.
new
(
volunteer
:
@houred
)
@assignments_clients
=
select_clients
authorize
@hour
end
...
...
@@ -21,7 +24,7 @@ class HoursController < ApplicationController
@hour
=
Hour
.
new
(
hour_params
)
authorize
@hour
if
@hour
.
save
redirect_to
@hour
,
make_notice
redirect_to
@hour
ed
,
make_notice
else
render
:new
end
...
...
@@ -29,7 +32,7 @@ class HoursController < ApplicationController
def
update
if
@hour
.
update
(
hour_params
)
redirect_to
@hour
,
make_notice
redirect_to
@hour
ed
,
make_notice
else
render
:edit
end
...
...
@@ -37,25 +40,15 @@ class HoursController < ApplicationController
def
destroy
@hour
.
destroy
if
current_user
.
superadmin?
redirect_to
hours_url
,
make_notice
else
redirect_to
volunteer_hours_volunteer_path
(
@hour
.
volunteer
),
make_notice
end
redirect_to
@houred
,
make_notice
end
private
def
select_clients
if
params
[
:volunteer_id
]
assignments
=
Assignment
.
where
(
volunteer:
params
[
:volunteer_id
])
assignments
.
map
do
|
assignment
|
[
assignment
.
client
.
to_s
,
assignment
.
id
]
end
else
Client
.
having_volunteer
.
map
do
|
client
|
[
client
.
to_s
,
client
.
assignment
.
id
]
end
assignments
=
Assignment
.
where
(
volunteer:
params
[
:volunteer_id
])
assignments
.
map
do
|
assignment
|
[
assignment
.
client
.
to_s
,
assignment
.
id
]
end
end
...
...
@@ -64,6 +57,10 @@ class HoursController < ApplicationController
authorize
@hour
end
def
set_houred
@houred
=
Volunteer
.
find
(
params
[
:volunteer_id
])
if
params
[
:volunteer_id
]
end
def
hour_params
params
.
require
(
:hour
).
permit
(
:meeting_date
,
:hours
,
:minutes
,
:activity
,
:comments
,
:volunteer_id
,
:assignment_id
)
...
...
app/controllers/volunteers_controller.rb
View file @
32560ee4
...
...
@@ -5,7 +5,7 @@ class VolunteersController < ApplicationController
include
VolunteerAttributes
include
MakeNotice
before_action
:set_volunteer
,
only:
[
:show
,
:edit
,
:update
,
:destroy
,
:volunteer_hours
]
before_action
:set_volunteer
,
only:
[
:show
,
:edit
,
:update
,
:destroy
]
def
index
authorize
Volunteer
...
...
@@ -62,10 +62,6 @@ class VolunteersController < ApplicationController
@seeking_clients
=
@q
.
result
.
paginate
(
page:
params
[
:page
])
end
def
volunteer_hours
@volunteer_hours
=
Hour
.
where
(
volunteer_id:
@volunteer
)
end
private
def
invite_volunteer_user
...
...
app/models/client.rb
View file @
32560ee4
...
...
@@ -34,7 +34,6 @@ class Client < ApplicationRecord
scope
:need_accompanying
,
lambda
{
includes
(
:assignment
).
where
(
assignments:
{
client_id:
nil
}).
order
(
created_at: :asc
)
}
scope
:having_volunteer
,
(
->
{
where
(
state:
RESERVED
)
})
GENDER_REQUESTS
=
[
:no_matter
,
:same
].
freeze
AGE_REQUESTS
=
[
:age_no_matter
,
:age_young
,
:age_middle
,
:age_old
].
freeze
...
...
@@ -44,10 +43,6 @@ class Client < ApplicationRecord
"
#{
contact
.
first_name
}
#{
contact
.
last_name
}
"
end
def
self
.
having_volunteer
Client
.
where
(
state:
RESERVED
)
end
def
self
.
first_languages
[
[
I18nData
.
languages
(
I18n
.
locale
)[
'TI'
],
'TI'
],
...
...
app/models/volunteer.rb
View file @
32560ee4
...
...
@@ -22,7 +22,6 @@ class Volunteer < ApplicationRecord
].
freeze
SEEKING_CLIENTS
=
[
ACCEPTED
,
ACTIVE_FURTHER
,
INACTIVE
].
freeze
HAVING_CLIENTS
=
[
ACTIVE
,
ACTIVE_FURTHER
].
freeze
STATES
=
STATES_FOR_REVIEWED
.
dup
.
unshift
(
REGISTERED
).
freeze
...
...
@@ -54,16 +53,11 @@ class Volunteer < ApplicationRecord
default_scope
{
order
(
created_at: :desc
)
}
scope
:seeking_clients
,
(
->
{
where
(
state:
SEEKING_CLIENTS
)
})
scope
:having_clients
,
(
->
{
where
(
state:
HAVING_CLIENTS
)
})
def
seeking_clients?
SEEKING_CLIENTS
.
include?
(
state
)
end
def
self
.
having_clients
Volunteer
.
where
(
state:
HAVING_CLIENTS
)
end
def
registered?
state
==
REGISTERED
end
...
...
app/policies/application_policy.rb
View file @
32560ee4
...
...
@@ -55,14 +55,14 @@ class ApplicationPolicy
superadmin?
||
volunteer?
&&
user_owns_record?
end
def
superadmin_or_social_workers_record?
superadmin?
||
social_worker?
&&
user_owns_record?
end
def
superadmin_or_volunteer_related?
superadmin?
||
volunteer_related?
end
def
superadmin_or_social_workers_record?
superadmin?
||
social_worker?
&&
user_owns_record?
end
alias_method
:index?
,
:deny_all!
alias_method
:new?
,
:deny_all!
alias_method
:create?
,
:deny_all!
...
...
app/policies/hour_policy.rb
View file @
32560ee4
class
HourPolicy
<
ApplicationPolicy
alias_method
:index?
,
:superadmin?
alias_method
:index?
,
:superadmin
_or_volunteer_related
?
alias_method
:show?
,
:superadmin_or_volunteer_related?
alias_method
:new?
,
:superadmin_or_volunteer_related?
alias_method
:edit?
,
:superadmin_or_volunteer_related?
...
...
app/policies/volunteer_policy.rb
View file @
32560ee4
...
...
@@ -5,7 +5,6 @@ class VolunteerPolicy < ApplicationPolicy
alias_method
:destroy?
,
:superadmin?
alias_method
:seeking_clients?
,
:superadmin?
alias_method
:checklist?
,
:superadmin?
alias_method
:volunteer_hours?
,
:superadmin_or_volunteers_record?
alias_method
:show?
,
:superadmin_or_volunteers_record?
alias_method
:edit?
,
:superadmin_or_volunteers_record?
...
...
app/views/hours/_form.html.slim
View file @
32560ee4
=
simple_form_for
(
@hour
)
do
|
f
|
=
simple_form_for
[
@hour
ed
,
@hour
]
do
|
f
|
=
simple_error_notice
f
.row
...
...
@@ -10,9 +10,6 @@
.row
.col-xs-12
-
if
action_name
==
'new'
&&
current_user
.
superadmin?
=
f
.
association
:volunteer
,
collection:
Volunteer
.
having_clients
-
else
=
f
.
hidden_field
:volunteer_id
,
value:
params
[
:volunteer_id
]
||
@hour
.
volunteer
.
id
.row
...
...
app/views/hours/_hour.html.slim
deleted
100644 → 0
View file @
88816344
tr
-
if
policy
(
Hour
).
index?
td
=
hour
.
volunteer
.
contact
.
full_name
td
=
hour
.
assignment
.
client
.
contact
.
full_name
td
=
l
(
hour
.
meeting_date
)
td
=
"
#{
hour
.
hours
}
:
#{
hour
.
minutes
}
"
td
=
hour
.
activity
td
=
hour
.
comments
td
=
link_to
t_action
(
:show
),
hour_path
(
hour
)
td
=
link_to
t_action
(
:edit
),
edit_hour_path
(
hour
)
td
=
link_to
t_action
(
:destroy
),
hour_path
(
hour
),
confirm_deleting
(
hour
,
'hours'
)
app/views/hours/_hours_block.html.slim
deleted
100644 → 0
View file @
88816344
.row
.col-xs-12
table
.table.table-striped
thead
tr
-
if
policy
(
Hour
).
index?
th
=
t_model
(
Volunteer
)
th
=
t_model
(
Client
)
th
=
t_attr
(
:meeting_date
,
Hour
)
th
=
t_attr
(
:duration
,
Hour
)
th
=
t_attr
(
:activity
,
Hour
)
th
=
t_attr
(
:comments
,
Hour
)
th
colspan
=
'3'
tbody
=
render
hours
-
if
current_user
.
superadmin?
=
form_navigation_btn
:new
-
else
=
button_link
t_title
(
:new
,
Hour
),
new_hour_url
(
volunteer_id:
current_user
.
volunteer
.
id
)
app/views/hours/_navigation_back.html.slim
deleted
100644 → 0
View file @
88816344
-
if
policy
(
Hour
).
index?
=
form_navigation_btn
:back
-
else
=
button_link
t_action
(
:back
),
volunteer_hours_volunteer_path
(
@hour
.
volunteer
)
app/views/hours/edit.html.slim
View file @
32560ee4
...
...
@@ -4,4 +4,6 @@
==
render
'form'
=
render
'navigation_back'
.row
.col-xs-12
=
button_link
t
(
'back'
),
@houred
app/views/hours/index.html.slim
View file @
32560ee4
h1
=
@houred
.
contact
.
full_name
h1
=
t_title
(
:index
,
Hour
)
.table-responsive
table
.table
thead
tr
-
if
current_user
.
volunteer?
th
=
t_model
(
Volunteer
)
th
=
t_model
(
Client
)
th
=
t_attr
(
:meeting_date
)
th
=
t_attr
(
:duration
)
th
=
t_attr
(
:activity
)
th
=
t_attr
(
:comments
)
th
colspan
=
3
tbody
-
@houred
.
hours
.
each
do
|
record
|
tr
-
if
current_user
.
volunteer?
td
=
@houred
.
contact
.
full_name
td
=
record
.
assignment
.
client
.
contact
.
full_name
td
=
l
(
record
.
meeting_date
)
td
=
"
#{
record
.
hours
}
:
#{
record
.
minutes
}
"
td
=
record
.
activity
td
=
record
.
comments
td
=
link_to
t_action
(
:show
),
volunteer_hour_path
(
@houred
,
record
)
td
=
link_to
t_action
(
:edit
),
edit_volunteer_hour_path
(
@houred
,
record
)
td
=
link_to
t_action
(
:destroy
),
volunteer_hour_path
(
@houred
,
record
),
confirm_deleting
(
record
)
.row
.col-xs-12
h1
=
t_title
=
render
'hours_block'
,
hours:
@hours
=
form_navigation_btn
:new
.row
.col-xs-12
=
button_link
t
(
'back'
),
@houred
app/views/hours/new.html.slim
View file @
32560ee4
...
...
@@ -4,4 +4,6 @@
==
render
'form'
=
render
'navigation_back'
.row
.col-xs-12
=
button_link
t
(
'back'
),
@houred
app/views/hours/show.html.slim
View file @
32560ee4
...
...
@@ -3,8 +3,8 @@
.table-responsive
table
.table.table-no-border-top
tbody
-
if
policy
(
Hour
).
index?
tr
tr
-
if
current_user
.
volunteer?
td
=
t_model
(
Volunteer
)
td
=
@hour
.
volunteer
.
contact
.
full_name
tr
...
...
@@ -23,5 +23,6 @@
td
=
t_attr
(
:comments
)
td
=
@hour
.
comments
=
form_navigation_btn
:edit
=
render
'navigation_back'
.row
.col-xs-12
=
button_link
t_title
(
:edit
,
Hour
),
params
.
to_unsafe_h
.
merge
({
action:
'edit'
})
app/views/volunteers/index.html.slim
View file @
32560ee4
...
...
@@ -5,7 +5,6 @@ nav.navbar.section-navigation
li
=
button_link
t_title
(
:new
),
new_volunteer_path
,
'success'
,
dimension:
'sm'
-
if
policy
(
Volunteer
).
destroy?
li
=
button_link
t
(
'seeking_clients'
),
seeking_clients_volunteers_url
,
dimension:
'sm'
li
=
button_link
t_title
(
:index
,
Hour
),
hours_path
,
dimension:
'sm'
li
|
li
=
button_link
t_model
(
VolunteerEmail
),
volunteer_emails_path
,
dimension:
'sm'
...
...
app/views/volunteers/show.html.slim
View file @
32560ee4
...
...
@@ -12,9 +12,9 @@
=
button_link
t_title
(
:new
,
Assignment
),
new_assignment_path
(
volunteer_id:
@volunteer
)
-
if
@volunteer
.
assignments
.
any?
.col-xs-12.col-md-4
=
button_link
t_title
(
:index
,
Hour
),
volunteer_hours_
volunteer_
path
(
@volunteer
)
=
button_link
t_title
(
:index
,
Hour
),
volunteer_hours_path
(
@volunteer
)
.col-xs-12.col-md-4
=
button_link
t_title
(
:new
,
Hour
),
new_
hour_url
(
volunteer_
id:
@volunteer
)
=
button_link
t_title
(
:new
,
Hour
),
new_volunteer_
hour_url
(
@volunteer
)
-
if
policy
(
Volunteer
).
checklist?
h3
=
t
(
'checklist'
)
...
...
app/views/volunteers/volunteer_hours.html.slim
deleted
100644 → 0
View file @
88816344
.row
.col-xs-12
h1
=
t_title
(
:index
,
Hour
)
=
render
'hours/hours_block'
,
hours:
@volunteer_hours
config/routes.rb
View file @
32560ee4
...
...
@@ -17,12 +17,11 @@ Rails.application.routes.draw do
resources
:volunteers
do
get
:seeking_clients
,
on: :collection
get
:find_client
,
on: :member
,
to:
'assignments#find_client'
get
:volunteer_hours
,
on: :member
resources
:journals
resources
:hours
end
resources
:volunteer_emails
resources
:profiles
,
except:
[
:destroy
,
:index
]
resources
:hours
root
'application#home'
end
test/policies/volunteer_policy_test.rb
View file @
32560ee4
...
...
@@ -54,13 +54,4 @@ class VolunteerPolicyTest < PolicyAssertions::Test
test
"Checklist: department manager cannot see volunteer's checklist"
do
refute_permit
@department_manager
,
Volunteer
,
'checklist?'
end
test
'Volunteer hours: superadmin can see volunteer hours'
do
assert_permit
@superadmin
,
Volunteer
,
'volunteer_hours?'
end
test
'Volunteer hours: social worker and department manager cannot see volunteer hours'
do
refute_permit
@social_worker
,
Volunteer
,
'volunteer_hours?'
refute_permit
@department_manager
,
Volunteer
,
'volunteer_hours?'
end
end
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment