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
2b6b8c27
Verified
Commit
2b6b8c27
authored
Jan 31, 2018
by
Kaspar Vollenweider
👻
Browse files
initiate client beenden
parent
6adcbac7
Changes
13
Hide whitespace changes
Inline
Side-by-side
app/controllers/clients_controller.rb
View file @
2b6b8c27
...
...
@@ -3,7 +3,7 @@ class ClientsController < ApplicationController
include
NestedAttributes
include
ContactAttributes
before_action
:set_client
,
only:
[
:show
,
:edit
,
:update
,
:destroy
]
before_action
:set_client
,
only:
[
:show
,
:edit
,
:update
,
:destroy
,
:set_resigned
]
before_action
:set_social_worker_collection
def
index
...
...
@@ -65,6 +65,15 @@ class ClientsController < ApplicationController
end
end
def
set_resigned
if
@client
.
update
(
acceptance:
'resigned'
)
redirect_to
@client
,
notice:
'Der klient wurde erfolgreich beendet.'
else
redirect_back
(
fallback_location:
client_path
(
@client
),
notice:
'Der Klient konnte nicht beendet werden.'
)
end
end
def
destroy
@client
.
destroy
redirect_to
clients_url
,
make_notice
...
...
app/models/client.rb
View file @
2b6b8c27
...
...
@@ -5,6 +5,8 @@ class Client < ApplicationRecord
include
ZuerichScopes
include
ImportRelation
before_update
:record_acceptance_change
,
if: :going_to_change_to_resigned?
enum
acceptance:
{
accepted:
0
,
rejected:
1
,
resigned:
2
}
enum
cost_unit:
{
city:
0
,
municipality:
1
,
canton:
2
}
...
...
@@ -15,6 +17,7 @@ class Client < ApplicationRecord
belongs_to
:user
,
->
{
with_deleted
}
belongs_to
:involved_authority
,
class_name:
'User'
,
optional:
true
belongs_to
:resigned_by
,
class_name:
'User'
,
optional:
true
has_one
:assignment
,
dependent: :destroy
has_many
:assignment_logs
...
...
@@ -33,14 +36,17 @@ class Client < ApplicationRecord
validates
:salutation
,
presence:
true
scope
:need_accompanying
,
lambda
{
inactive
.
order
(
created_at: :asc
)
}
validates
:acceptance
,
exclusion:
{
in:
[
'resigned'
],
message:
'Klient kann nicht beendet werden, solange noch ein laufendes Tandem existiert.'
},
unless: :terminateable?
scope
:with_assignment
,
(
->
{
joins
(
:assignment
)
})
scope
:with_active_assignment
,
(
->
{
with_assignment
.
merge
(
Assignment
.
active
)
})
scope
:need_accompanying
,
lambda
{
inactive
.
order
(
created_at: :asc
)
}
scope
:with_active_assignment_between
,
lambda
{
|
start_date
,
end_date
|
with_assignment
.
merge
(
Assignment
.
active_between
(
start_date
,
end_date
))
}
...
...
@@ -62,6 +68,18 @@ class Client < ApplicationRecord
accepted
.
without_assignment
.
or
(
with_inactive_assignment
)
}
def
terminateable?
assignment
.
blank?
||
assignment
.
ending?
||
assignment
.
no_period?
end
def
self
.
acceptences_restricted
acceptances
.
except
(
'resigned'
)
end
def
self
.
acceptance_collection_restricted
acceptences_restricted
.
keys
.
map
(
&
:to_sym
)
end
def
self
.
acceptance_collection
acceptances
.
keys
.
map
(
&
:to_sym
)
end
...
...
@@ -88,4 +106,14 @@ class Client < ApplicationRecord
def
german_missing?
language_skills
.
german
.
blank?
end
private
def
going_to_change_to_resigned?
will_save_change_to_acceptance?
(
to:
'resigned'
)
end
def
record_acceptance_change
self
.
resigned_on
=
Time
.
zone
.
today
end
end
app/models/concerns/group_assignment_and_assignment_common.rb
View file @
2b6b8c27
...
...
@@ -103,6 +103,10 @@ module GroupAssignmentAndAssignmentCommon
period_start
.
present?
&&
period_start
<=
Time
.
zone
.
today
end
def
ending?
period_start
.
present?
&&
period_end
.
present?
end
def
ended?
ending?
&&
period_end
<=
Time
.
zone
.
today
end
...
...
app/models/user.rb
View file @
2b6b8c27
...
...
@@ -49,6 +49,8 @@ class User < ApplicationRecord
has_many
:group_offer_terminations_verified
,
class_name:
'GroupOffer'
,
foreign_key:
'termination_verified_by_id'
,
inverse_of:
'termination_verified_by'
has_many
:resigned_clients
,
class_name:
'Client'
,
foreign_key:
'resigned_by_id'
# Mailing process done relation
has_many
:process_submitted_by
,
class_name:
'ReminderMailingVolunteer'
...
...
app/policies/application_policy.rb
View file @
2b6b8c27
...
...
@@ -84,8 +84,12 @@ class ApplicationPolicy
superadmin?
||
user_owns_record?
end
def
department_managers_record?
department_manager?
&&
user_owns_record?
end
def
superadmin_or_department_managers_record?
superadmin?
||
department_manager
?
&&
user_own
s_record?
superadmin?
||
department_managers_record?
end
def
superadmin_or_department_managers_registration?
...
...
app/policies/client_policy.rb
View file @
2b6b8c27
...
...
@@ -16,8 +16,17 @@ class ClientPolicy < ApplicationPolicy
alias_method
:edit?
,
:superadmin_or_record_owner?
alias_method
:update?
,
:superadmin_or_record_owner?
alias_method
:termination?
,
:superadmin_or_department_managers_record?
alias_method
:set_resigned?
,
:superadmin_or_department_managers_record?
alias_method
:destroy?
,
:superadmin?
# suplementary policies
alias_method
:superadmin_privileges?
,
:superadmin?
def
acceptance_collection
if
superadmin?
Client
.
acceptance_collection
elsif
department_managers_record?
Client
.
acceptance_collection_restricted
end
end
end
app/views/application/_navigation.html.slim
View file @
2b6b8c27
...
...
@@ -15,7 +15,7 @@ nav.navbar.navbar-top.hidden-print
-
if
policy
(
User
).
index?
li
=
link_to
'Benutzer/innen'
,
users_path
-
if
policy
(
Client
).
index?
li
=
link_to
'Klienten/innen'
,
clients_path
li
=
link_to
'Klienten/innen'
,
clients_path
(
q:
{
acceptance_not_eq:
2
})
-
if
policy
(
Volunteer
).
index?
li
=
link_to
'Freiwillige'
,
volunteers_path
-
if
policy
(
Department
).
manager_with_department?
...
...
app/views/clients/_form.html.slim
View file @
2b6b8c27
...
...
@@ -47,8 +47,9 @@
fieldset
legend
Interne
Kriterien
-
if
policy
(
@client
).
set_resigned?
=
f
.
input
:acceptance
,
collection:
policy
(
@client
).
acceptance_collection
,
include_blank:
false
-
if
policy
(
Client
).
superadmin_privileges?
=
f
.
input
:acceptance
,
collection:
Client
.
acceptance_collection
,
include_blank:
false
=
f
.
association
:involved_authority
,
collection:
@social_workers
=
f
.
input
:competent_authority
...
...
app/views/clients/_show_navigation.html.slim
View file @
2b6b8c27
nav
.navbar.section-navigation
ul
.list-inline
-
if
policy
(
Client
).
superadmin_privileges?
li
.button-acceptance
=
link_to
t
(
".acceptance.
#{
@client
.
acceptance
}
"
),
'#'
,
li
.button-acceptance
=
link_to
t
_attr
(
@client
.
acceptance
,
Client
),
'#'
,
class
:
"btn
btn-acceptance-
#{
@client
.
acceptance
}
"
-
if
policy
(
@client
).
edit?
li
=
button_link
t_action
(
:edit
),
edit_client_path
(
@client
)
li
=
button_link
navigation_glyph
(
:print
),
client_path
(
@client
,
print:
true
)
-
if
policy
(
C
lient
).
destroy
?
li
=
link_to
navigation_glyph
(
:delete
),
@client
,
confirm_deleting
(
@client
,
'btn btn-default'
)
-
if
!
@client
.
resigned?
&&
policy
(
@c
lient
).
set_resigned
?
li
=
link_to
'Beenden'
,
set_resigned_client_path
(
@client
)
,
class:
'btn btn-default'
,
data:
{
method:
'PATCH'
}
li
=
button_link
navigation_glyph
(
:back
),
clients_path
-
if
policy
(
Journal
).
index?
ul
.list-inline.pull-right
...
...
config/routes.rb
View file @
2b6b8c27
...
...
@@ -58,6 +58,7 @@ Rails.application.routes.draw do
resources
:clients
,
concerns: :search
do
resources
:journals
,
except:
[
:show
]
patch
:set_resigned
,
on: :member
end
resources
:feedbacks
,
only:
[
:new
,
:create
]
...
...
db/migrate/20180130140401_add_termination_fields_to_client.rb
0 → 100644
View file @
2b6b8c27
class
AddTerminationFieldsToClient
<
ActiveRecord
::
Migration
[
5.1
]
def
change
change_table
:clients
do
|
t
|
t
.
date
:resigned_on
t
.
references
:resigned_by
,
references: :users
,
index:
true
end
end
end
db/schema.rb
View file @
2b6b8c27
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201801
26101119
)
do
ActiveRecord
::
Schema
.
define
(
version:
201801
30140401
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -166,8 +166,11 @@ ActiveRecord::Schema.define(version: 20180126101119) do
t
.
integer
"acceptance"
,
default:
0
t
.
integer
"cost_unit"
t
.
bigint
"involved_authority_id"
t
.
date
"resigned_on"
t
.
bigint
"resigned_by_id"
t
.
index
[
"deleted_at"
],
name:
"index_clients_on_deleted_at"
t
.
index
[
"involved_authority_id"
],
name:
"index_clients_on_involved_authority_id"
t
.
index
[
"resigned_by_id"
],
name:
"index_clients_on_resigned_by_id"
t
.
index
[
"user_id"
],
name:
"index_clients_on_user_id"
end
...
...
db/seeds.rb
View file @
2b6b8c27
...
...
@@ -82,7 +82,7 @@ end
puts_model_counts
(
'After Volunteer created'
,
User
,
Volunteer
,
Client
)
# Create clients for each acceptance type
Client
.
acceptance_collection
.
each
do
|
acceptance
|
Client
.
acceptance_collection
_restricted
.
each
do
|
acceptance
|
FactoryBot
.
create
(
:client
,
acceptance:
acceptance
,
user:
User
.
superadmins
.
first
)
end
puts_model_counts
(
'After Client created'
,
User
,
Volunteer
,
Client
)
...
...
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