Added shared organization feature. Customers will be able to watch organization ticket.

This commit is contained in:
Martin Edenhofer 2012-11-13 11:34:45 +01:00
parent 0ecad4aaa8
commit 5b1c7d77c3
7 changed files with 111 additions and 35 deletions

View file

@ -19,6 +19,7 @@ class TicketArticlesController < ApplicationController
def create
@article = Ticket::Article.new(params[:ticket_article])
@article.created_by_id = current_user.id
@article.updated_by_id = current_user.id
# find attachments in upload cache
@article['attachments'] = Store.list(
@ -43,6 +44,7 @@ class TicketArticlesController < ApplicationController
# PUT /articles/1
def update
@article = Ticket::Article.find( params[:id] )
params[:ticket_article][:updated_by_id] = current_user.id
if @article.update_attributes(params[:ticket_article])
render :json => @article, :status => :ok

View file

@ -70,6 +70,8 @@ class TicketsController < ApplicationController
# permissin check
return if !ticket_permission(@ticket)
params[:ticket][:updated_by_id] = current_user.id
if @ticket.update_attributes( params[:ticket] )
render :json => @ticket, :status => :ok
else

View file

@ -1,9 +1,11 @@
class Ticket < ApplicationModel
before_create :number_generate, :check_defaults
before_update :check_defaults
before_destroy :destroy_dependencies
belongs_to :group
has_many :articles, :after_add => :cache_update, :after_remove => :cache_update
belongs_to :organization
belongs_to :ticket_state, :class_name => 'Ticket::State'
belongs_to :ticket_priority, :class_name => 'Ticket::Priority'
belongs_to :owner, :class_name => 'User'
@ -141,7 +143,16 @@ class Ticket < ApplicationModel
# check customer
if data[:current_user].is_role('Customer')
# access ok if its own ticket
return true if self.customer_id == data[:current_user].id
# access ok if its organization ticket
if data[:current_user].organization_id && self.organization_id
return true if self.organization_id == data[:current_user].organization_id
end
# no access
return false
end
@ -157,13 +168,22 @@ class Ticket < ApplicationModel
# :current_user => 123,
# )
def self.overview_list (data)
# get user role
# get customer overviews
if data[:current_user].is_role('Customer')
role = data[:current_user].is_role( 'Customer' )
if data[:current_user].organization_id && data[:current_user].organization.shared
overviews = Overview.where( :role_id => role.id )
else
role = data[:current_user].is_role( 'Agent' )
overviews = Overview.where( :role_id => role.id, :organization_shared => false )
end
Overview.where( :role_id => role.id )
return overviews
end
# get agent overviews
role = data[:current_user].is_role( 'Agent' )
overviews = Overview.where( :role_id => role.id )
return overviews
end
# Ticket.overview(
@ -172,25 +192,13 @@ class Ticket < ApplicationModel
# )
def self.overview (data)
# get user role
if data[:current_user].is_role('Customer')
role = data[:current_user].is_role( 'Customer' )
else
role = data[:current_user].is_role( 'Agent' )
end
overviews = self.overview_list(data)
# build up attributes hash
overview_selected = nil
overview_selected_raw = nil
overviews = Overview.where( :role_id => role.id )
overviews.each { |overview|
# for cleanup reasons, remove me later!
overview.condition.each { |item, value |
if item == 'owner_id' && overview.condition[item] != 1
overview.condition[item] = 'current_user.id'
end
}
overviews.each { |overview|
# remember selected view
if data[:view] && data[:view] == overview.meta[:url]
@ -198,10 +206,13 @@ class Ticket < ApplicationModel
overview_selected_raw = Marshal.load( Marshal.dump(overview.attributes) )
end
# replace 'current_user.id' with current_user.id
# replace e.g. 'current_user.id' with current_user.id
overview.condition.each { |item, value |
if value == 'current_user.id'
overview.condition[item] = data[:current_user].id
if value && value.class.to_s == 'String'
parts = value.split( '.', 2 )
if parts[0] && parts[1] && parts[0] == 'current_user'
overview.condition[item] = data[:current_user][parts[1].to_sym]
end
end
}
}
@ -383,9 +394,17 @@ class Ticket < ApplicationModel
end
end
def check_defaults
if !self.owner_id then
if !self.owner_id
self.owner_id = 1
end
# if self.customer_id && ( !self.organization_id || self.organization_id.empty? )
if self.customer_id
customer = User.find( self.customer_id )
if self.organization_id != customer.organization_id
self.organization_id = customer.organization_id
end
end
end
def destroy_dependencies

View file

@ -34,6 +34,7 @@ class CreateTicket < ActiveRecord::Migration
t.references :group, :null => false
t.references :ticket_priority, :null => false
t.references :ticket_state, :null => false
t.references :organization, :null => true
t.column :number, :string, :limit => 60, :null => false
t.column :title, :string, :limit => 250, :null => false
t.column :owner_id, :integer, :null => false
@ -153,6 +154,7 @@ class CreateTicket < ActiveRecord::Migration
t.column :condition, :string, :limit => 2500, :null => false
t.column :order, :string, :limit => 2500, :null => false
t.column :group_by, :string, :limit => 250, :null => true
t.column :organization_shared, :boolean, :null => false, :default => false
t.column :view, :string, :limit => 1000, :null => false
t.column :active, :boolean, :null => false, :default => true
t.column :updated_by_id, :integer, :null => false

View file

@ -1,5 +1,6 @@
class TicketOrganization < ActiveRecord::Migration
def up
add_column :tickets, :organization_id, :integer, :null => true
end
def down

View file

@ -0,0 +1,8 @@
class OrganizationShared < ActiveRecord::Migration
def up
add_column :overviews, :organization_shared, :boolean, :null => false, :default => false
end
def down
end
end

View file

@ -1436,7 +1436,7 @@ Overview.create(
},
:order => {
:by => 'created_at',
:direction => 'ASC',
:direction => 'DESC',
},
:meta => {
:url => 'my_tickets',
@ -1467,6 +1467,46 @@ Overview.create(
:updated_by_id => 1,
:created_by_id => 1
)
Overview.create(
:name => 'my_organization_tickets',
:role_id => overview_role.id,
:organization_shared => true,
:condition => {
:organization_id => 'current_user.organization_id',
},
:order => {
:by => 'created_at',
:direction => 'DESC',
},
:meta => {
:url => 'my_organization_tickets',
:name => 'My Organization Tickets',
:prio => 1100,
},
:view => {
:d => {
:overview => [
'title', 'customer', 'ticket_state', 'created_at'
],
:per_page => 5,
},
:s => {
:overview => [
'number', 'title', 'ticket_state', 'ticket_priority', 'created_at'
],
:per_page => 30,
},
:m => {
:overview => [
'number', 'title', 'ticket_state', 'ticket_priority', 'created_at'
],
:per_page => 20,
},
:view_mode_default => 's',
},
:updated_by_id => 1,
:created_by_id => 1
)
Channel.create(
:adapter => 'SMTP',
@ -1751,6 +1791,8 @@ Translation.create( :locale => 'de', :source => "Linked Objects", :target => "Ve
Translation.create( :locale => 'de', :source => "Links", :target => "Verknüpftungen", :updated_by_id => 1, :created_by_id => 1 )
Translation.create( :locale => 'de', :source => "Change Customer", :target => "Kunden ändern", :updated_by_id => 1, :created_by_id => 1 )
Translation.create( :locale => 'de', :source => "My Tickets", :target => "Meine Tickets", :updated_by_id => 1, :created_by_id => 1 )
Translation.create( :locale => 'de', :source => "My Organization Tickets", :target => "Meine Organisations Tickets", :updated_by_id => 1, :created_by_id => 1 )
Translation.create( :locale => 'de', :source => "My Organization", :target => "Meine Organisation", :updated_by_id => 1, :created_by_id => 1 )
Translation.create( :locale => 'de', :source => "Assignment Timout", :target => "Zeitliche Zuweisungsüberschritung", :updated_by_id => 1, :created_by_id => 1 )
Translation.create( :locale => 'de', :source => "We've sent password reset instructions to your email address.", :target => "Wir haben Ihnen die Anleitung zum zurücksetzesn Ihres Passworts an Ihre E-Mail-Adresse gesendet.", :updated_by_id => 1, :created_by_id => 1 )
Translation.create( :locale => 'de', :source => "Enter your username or email address", :target => "Bitte geben Sie Ihren Benutzernamen oder E-Mail-Adresse ein", :updated_by_id => 1, :created_by_id => 1 )