Show also roles based groups in profile notification settings.

This commit is contained in:
Martin Edenhofer 2018-02-26 11:36:19 +01:00
parent 5aa0d5b184
commit 8d725040a9
4 changed files with 70 additions and 19 deletions

View file

@ -73,10 +73,9 @@ class Index extends App.ControllerSubContent
user_group_config = false
groups = []
group_ids = @Session.get('group_ids')
group_ids = App.User.find(@Session.get('id')).all_group_ids()
if group_ids
for group_id, access of group_ids
if _.contains(access, 'full')
for group_id in group_ids
group = App.Group.find(group_id)
groups.push group
if !user_group_config
@ -150,6 +149,8 @@ class Index extends App.ControllerSubContent
params.notification_sound = form_params.notification_sound
if !params.notification_sound.enabled
params.notification_sound.enabled = false
else
params.notification_sound.enabled = true
# get data
@ajax(

View file

@ -248,15 +248,10 @@ class App.Ticket extends App.Model
editable: (permission = 'change') ->
user_id = App.Session.get('id')
return true if user_id is @customer_id
group_ids = App.Session.get('group_ids')
if group_ids
return true if group_ids[@group_id] && (_.include(group_ids[@group_id], permission) || _.include(group_ids[@group_id], 'full'))
role_ids = App.Session.get('role_ids')
if role_ids
for role_id in role_ids
if App.Role.exists(role_id)
role = App.Role.find(role_id)
if role.group_ids
return true if role.group_ids[@group_id] && (_.include(role.group_ids[@group_id], permission) || _.include(role.group_ids[@group_id], 'full'))
return false if !App.User.exists(user_id)
group_ids = App.User.find(user_id).all_group_ids(permission)
for local_group_id in group_ids
if local_group_id.toString() is @group_id.toString()
return true
false

View file

@ -258,6 +258,25 @@ class App.User extends App.Model
return access if access
false
all_group_ids: (permission = 'full') ->
group_ids = []
user_group_ids = App.Session.get('group_ids')
if user_group_ids
for local_group_id, local_permission of user_group_ids
if _.include(local_permission, permission) || _.include(local_permission, 'full')
group_ids.push local_group_id
user_role_ids = App.Session.get('role_ids')
if user_role_ids
for role_id in user_role_ids
if App.Role.exists(role_id)
role = App.Role.find(role_id)
if role.group_ids
for local_group_id, local_permission of role.group_ids
if _.include(local_permission, permission) || _.include(local_permission, 'full')
group_ids.push local_group_id
_.uniq(group_ids)
@outOfOfficeTextPlaceholder: ->
today = new Date()
outOfOfficeText = 'Christmas holiday'

View file

@ -0,0 +1,36 @@
class CleanupUserPreferencesNotificationSound < ActiveRecord::Migration[5.1]
def up
User.with_permissions('ticket.agent').each do |user|
local_to_h!(user.preferences)
user.save!
end
User.with_permissions('ticket.agent').each do |user|
next if !user.preferences
next if !user.preferences[:notification_sound]
next if !user.preferences[:notification_sound][:enabled]
if user.preferences[:notification_sound][:enabled] == 'true'
user.preferences[:notification_sound][:enabled] = true
user.save!
next
end
next if user.preferences[:notification_sound][:enabled] != 'false'
user.preferences[:notification_sound][:enabled] = false
user.save!
next
end
end
def local_to_h!(value)
if value.class == ActionController::Parameters
value = value.permit!.to_h
end
if value.class == Hash || value.class == ActiveSupport::HashWithIndifferentAccess
value.each_key do |local_key|
value[local_key] = local_to_h!(value[local_key])
end
end
value
end
end