Moved to application model assets (for all models per default).
This commit is contained in:
parent
09a8278031
commit
3b8f6259b6
5 changed files with 52 additions and 37 deletions
|
@ -1,6 +1,7 @@
|
|||
# Copyright (C) 2013-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
class ApplicationModel < ActiveRecord::Base
|
||||
include ApplicationModel::Assets
|
||||
include ApplicationModel::HistoryLogBase
|
||||
include ApplicationModel::ActivityStreamBase
|
||||
|
||||
|
|
49
app/models/application_model/assets.rb
Normal file
49
app/models/application_model/assets.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module ApplicationModel::Assets
|
||||
|
||||
=begin
|
||||
|
||||
get all assets / related models for this user
|
||||
|
||||
user = User.find(123)
|
||||
result = user.assets( assets_if_exists )
|
||||
|
||||
returns
|
||||
|
||||
result = {
|
||||
:users => {
|
||||
123 => user_model_123,
|
||||
1234 => user_model_1234,
|
||||
}
|
||||
}
|
||||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
|
||||
if !data[ self.class.to_app_model ]
|
||||
data[ self.class.to_app_model ] = {}
|
||||
end
|
||||
if !data[ self.class.to_app_model ][ self.id ]
|
||||
data[ self.class.to_app_model ][ self.id ] = self.attributes
|
||||
end
|
||||
|
||||
return data if !self['created_by_id'] && !self['updated_by_id']
|
||||
if !data[ User.to_app_model ]
|
||||
data[ User.to_app_model ] = {}
|
||||
end
|
||||
if self['created_by_id']
|
||||
if !data[ User.to_app_model ][ self['created_by_id'] ]
|
||||
data[ User.to_app_model ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] )
|
||||
end
|
||||
end
|
||||
if self['updated_by_id']
|
||||
if !data[ User.to_app_model ][ self['updated_by_id'] ]
|
||||
data[ User.to_app_model ][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] )
|
||||
end
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
end
|
|
@ -1,8 +1,6 @@
|
|||
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
class Group < ApplicationModel
|
||||
include Group::Assets
|
||||
|
||||
has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update
|
||||
belongs_to :email_address
|
||||
belongs_to :signature
|
||||
|
@ -10,4 +8,4 @@ class Group < ApplicationModel
|
|||
|
||||
activity_stream_support :role => 'Admin'
|
||||
history_support
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module Group::Assets
|
||||
|
||||
=begin
|
||||
|
||||
get all assets / related models for this group
|
||||
|
||||
group = Group.find(123)
|
||||
result = group.assets( assets_if_exists )
|
||||
|
||||
returns
|
||||
|
||||
result = {
|
||||
:groups => {
|
||||
123 => group_model_123,
|
||||
1234 => group_model_1234,
|
||||
}
|
||||
}
|
||||
|
||||
=end
|
||||
|
||||
def assets (data)
|
||||
|
||||
if !data[ Group.to_app_model ]
|
||||
data[ Group.to_app_model ] = {}
|
||||
end
|
||||
if !data[ Group.to_app_model ][ self.id ]
|
||||
data[ Group.to_app_model ][ self.id ] = self.attributes
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
class Role < ApplicationModel
|
||||
|
||||
has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update
|
||||
validates :name, :presence => true
|
||||
activity_stream_support :role => 'Admin'
|
||||
|
|
Loading…
Reference in a new issue