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
de9d2687
Commit
de9d2687
authored
Jan 31, 2018
by
Chrysanthi Lagodimou
Committed by
Tugce Nur Tas
Feb 08, 2018
Browse files
acceptance available if one can terminate
parent
aea8c2e1
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/policies/volunteer_policy.rb
View file @
de9d2687
...
...
@@ -2,21 +2,20 @@ class VolunteerPolicy < ApplicationPolicy
class
Scope
<
ApplicationScope
def
resolve
return
all
if
superadmin?
return
scope
.
seeking_clients
.
distinct
if
department_manager?
return
scope
.
where
(
registrar_id:
user
)
if
department_manager?
none
end
alias
:seeking_clients
:resolve
end
def
volunteer_managing_or_volunteers_profile?
superadmin_or_department_manager
_or_social_worker
?
||
user_owns_record?
superadmin_or_department_manager
s_registration
?
||
user_owns_record?
end
# controller action policies
alias_method
:index?
,
:superadmin_or_department_manager
_or_social_worker
?
alias_method
:search?
,
:superadmin_or_department_manager
_or_social_worker
?
alias_method
:new?
,
:superadmin_or_department_manager
_or_social_worker
?
alias_method
:create?
,
:superadmin_or_department_manager
_or_social_worker
?
alias_method
:index?
,
:superadmin_or_department_manager?
alias_method
:search?
,
:superadmin_or_department_manager?
alias_method
:new?
,
:superadmin_or_department_manager?
alias_method
:create?
,
:superadmin_or_department_manager?
alias_method
:seeking_clients?
,
:superadmin_or_department_manager?
alias_method
:terminate?
,
:superadmin_or_department_managers_registration?
alias_method
:show?
,
:volunteer_managing_or_volunteers_profile?
...
...
@@ -25,4 +24,5 @@ class VolunteerPolicy < ApplicationPolicy
# supplementary policies
alias_method
:superadmin_privileges?
,
:superadmin?
alias_method
:show_acceptance?
,
:superadmin_or_department_manager?
end
app/views/volunteers/_columns.html.slim
View file @
de9d2687
...
...
@@ -18,7 +18,7 @@
th
=
sort_link
@q
,
:working_percent
th
=
sort_link
@q
,
:expectations
th
=
sort_link
@q
,
:interests
-
if
policy
(
Volunteer
).
s
uperadmin_privileges
?
-
if
policy
(
Volunteer
).
s
how_acceptance
?
th
=
sort_link
@q
,
:acceptance
th
=
sort_link
@q
,
:external
th
=
t_attr
(
:created_by
)
...
...
app/views/volunteers/_volunteer.html.slim
View file @
de9d2687
...
...
@@ -13,7 +13,7 @@ tr
td
=
"
#{
volunteer
.
working_percent
}
%"
if
volunteer
.
working_percent
.
present?
td
=
volunteer
.
expectations
td
=
volunteer
.
interests
-
if
policy
(
Volunteer
).
s
uperadmin_privileges
?
-
if
policy
(
Volunteer
).
s
how_acceptance
?
td
.button-acceptance
=
link_to
t
(
".acceptance.
#{
volunteer
.
acceptance
}
"
),
'#'
,
class
:
"btn
btn-xs
btn-acceptance-
#{
volunteer
.
acceptance
}
"
td
=
volunteer
.
external?
?
t_attr
(
:external
)
:
t_attr
(
:internal
)
...
...
app/views/volunteers/index.html.slim
View file @
de9d2687
...
...
@@ -19,7 +19,7 @@ nav.navbar.section-navigation
ul
.list-inline
li
=
button_link
t
(
'clear_filters'
),
volunteers_path
,
dimension:
'sm'
li
=
button_link
navigation_fa_icon
(
:xlsx
),
url_for
(
format: :xlsx
,
q:
search_parameters
),
dimension:
'sm'
-
if
policy
(
Volunteer
).
s
uperadmin_privileges
?
-
if
policy
(
Volunteer
).
s
how_acceptance
?
=
enum_filter_dropdown
(
:acceptance
,
Volunteer
.
acceptances
)
=
boolean_toggler_filter_dropdown
(
:active
,
'Einsatz'
,
'Aktiv'
,
'Inaktiv'
)
=
boolean_toggler_filter_dropdown
(
:external
,
'Intern/Extern'
,
'Extern'
,
'Intern'
)
...
...
app/views/volunteers/show.html.slim
View file @
de9d2687
...
...
@@ -10,10 +10,11 @@ nav.navbar.section-navigation
-
if
policy
(
Volunteer
).
superadmin_privileges?
li
=
button_link
'Journal'
,
polymorphic_path
([
@volunteer
,
Journal
]),
'primary'
ul
.list-inline
-
if
policy
(
V
olunteer
).
superadmin_privileges
?
-
if
policy
(
@v
olunteer
).
terminate
?
li
.button-acceptance
=
link_to
t
(
".acceptance.
#{
@volunteer
.
acceptance
}
"
),
'#'
,
class
:
"btn
btn-acceptance-
#{
@volunteer
.
acceptance
}
"
li
=
button_link
'Beenden'
,
terminate_volunteer_path
(
@volunteer
)
-
if
policy
(
Volunteer
).
superadmin_privileges?
ul
.list-inline
-
if
@volunteer
.
seeking_clients?
li
=
button_link
t_title
(
:new
,
Assignment
),
new_assignment_path
(
volunteer_id:
@volunteer
)
...
...
test/policies/volunteer_policy_test.rb
View file @
de9d2687
...
...
@@ -3,7 +3,7 @@ require 'test_helper'
class
VolunteerPolicyTest
<
PolicyAssertions
::
Test
def
setup
@actions
=
[
'index?'
,
'search?'
,
'new?'
,
'create?'
,
'seeking_clients?'
,
'terminate?'
,
'show?'
,
'edit?'
,
'update?'
,
'superadmin_privileges?'
]
'edit?'
,
'update?'
,
'show_acceptance?'
,
'superadmin_privileges?'
]
end
test
'superadmin_can_use_all_actions'
do
...
...
@@ -14,16 +14,15 @@ class VolunteerPolicyTest < PolicyAssertions::Test
department_manager
=
create
:department_manager
department_manager_volunteer
=
create
:volunteer_with_user
department_manager_volunteer
.
registrar
=
department_manager
assert_permit
(
department_manager
,
Volunteer
,
*
@actions
[
0
..
4
],
*
@actions
[
6
..
8
])
assert_permit
(
department_manager
,
department_manager_volunteer
,
*
@actions
[
5
])
refute_permit
(
department_manager
,
create
(
:volunteer
),
*
@actions
[
5
])
refute_permit
(
department_manager
,
Volunteer
,
*
@actions
[
-
2
..-
1
])
assert_permit
(
department_manager
,
Volunteer
,
*
@actions
[
0
..
4
],
*
@actions
[
-
2
])
assert_permit
(
department_manager
,
department_manager_volunteer
,
*
@actions
[
5
..
8
])
refute_permit
(
department_manager
,
create
(
:volunteer
),
*
@actions
[
5
..
8
])
refute_permit
(
department_manager
,
Volunteer
,
*
@actions
[
-
1
])
end
test
'social_worker_has_
limited
_access'
do
test
'social_worker_has_
no
_access'
do
social_worker
=
create
:social_worker
assert_permit
(
social_worker
,
Volunteer
,
*
@actions
[
0
..
3
],
*
@actions
[
6
..
8
])
refute_permit
(
social_worker
,
Volunteer
,
*
@actions
[
4
..
5
],
*
@actions
[
-
2
..-
1
])
refute_permit
(
social_worker
,
Volunteer
,
*
@actions
)
end
test
'volunteer_has_limited_access'
do
...
...
@@ -31,6 +30,6 @@ class VolunteerPolicyTest < PolicyAssertions::Test
volunteer_two
=
create
:volunteer_with_user
assert_permit
(
volunteer_one
.
user
,
volunteer_one
,
*
@actions
[
6
..
8
])
refute_permit
(
volunteer_one
.
user
,
volunteer_two
,
*
@actions
[
6
..
8
])
refute_permit
(
volunteer_one
.
user
,
Volunteer
,
*
@actions
[
0
..
5
],
*
@actions
[
-
2
..-
1
])
refute_permit
(
volunteer_one
.
user
,
Volunteer
,
*
@actions
[
0
..
5
],
*
@actions
[
9
..-
1
])
end
end
test/system/department_manager_test.rb
View file @
de9d2687
...
...
@@ -31,7 +31,7 @@ class DepartmentManagerTest < ApplicationSystemTestCase
end
test
'can see a group offer volunteer and return to the group offer'
do
volunteer
=
create
:volunteer
volunteer
=
create
:volunteer
,
registrar:
@department_manager
group_offer
=
create
:group_offer
,
volunteers:
[
volunteer
],
department:
@department_manager
.
department
.
first
visit
volunteer_path
(
volunteer
)
...
...
@@ -53,8 +53,8 @@ class DepartmentManagerTest < ApplicationSystemTestCase
assert
page
.
has_text?
'new title'
end
test
'department
manager
has
no
destroy
and
feedback
links
on
volunteer
show'
do
volunteer
=
create
:volunteer
test
'department
_
manager
_
has
_
no
_
destroy
_
and
_
feedback
_
links
_
on
_
volunteer
_
show'
do
volunteer
=
create
:volunteer
,
registrar:
@department_manager
group_offer
=
create
:group_offer
,
volunteers:
[
volunteer
],
department:
@department_manager
.
department
.
first
assignment
=
create
:assignment
,
volunteer:
volunteer
...
...
test/system/volunteers_test.rb
View file @
de9d2687
...
...
@@ -198,28 +198,23 @@ class VolunteersTest < ApplicationSystemTestCase
end
end
test
'department_manager_can_see_volunteer_index_and_only_
seeking_clients
_volunteers'
do
test
'department_manager_can_see_volunteer_index_and_only_
her_own
_volunteers'
do
department_manager
=
create
:department_manager
login_as
department_manager
volunteer_department_manager
=
create
:volunteer
,
registrar:
department_manager
other_volunteer
=
create
:volunteer
volunteer_seeks
=
create
:volunteer_with_user
create
:assignment
,
period_start:
500
.
days
.
ago
,
period_end:
200
.
days
.
ago
,
volunteer:
volunteer_seeks
volunteer_not_seeking
=
create
:volunteer_with_user
create
:assignment
,
period_start:
10
.
days
.
ago
,
period_end:
nil
,
volunteer:
volunteer_not_seeking
visit
volunteers_path
assert
page
.
has_text?
volunteer_
seeks
.
contact
.
full_name
refute
page
.
has_text?
volunteer
_not_seeking
.
contact
.
full_name
assert
page
.
has_text?
volunteer_
department_manager
.
contact
.
full_name
refute
page
.
has_text?
other_
volunteer
.
contact
.
full_name
end
test
'social_worker_can_see_volunteer_index'
do
social_worker
=
create
:social_worker
login_as
social_worker
test
'social_worker_cannot_see_volunteer_index'
do
login_as
create
(
:social_worker
)
visit
volunteers_path
assert
page
.
has_text?
'
Freiwillige
'
assert
page
.
has_text?
'
You are not authorized to perform this action.
'
end
test
'social_worker_cant_see_volunteer_seeking_clients'
do
...
...
@@ -259,9 +254,10 @@ class VolunteersTest < ApplicationSystemTestCase
end
test
'department manager has no link to group offer of not their own'
do
volunteer
=
create
:volunteer
department_manager
=
create
:department_manager
volunteer
=
create
:volunteer
,
registrar:
department_manager
group_offer
=
create
:group_offer
,
volunteers:
[
volunteer
]
login_as
create
:
department_manager
login_as
department_manager
visit
volunteer_path
(
volunteer
)
assert
page
.
has_text?
group_offer
.
title
refute
page
.
has_link?
group_offer
.
title
...
...
Write
Preview
Supports
Markdown
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