Skip to content

Commit

Permalink
Revert "Squashed commit of the following:"
Browse files Browse the repository at this point in the history
This reverts commit 7d2409b.
  • Loading branch information
rolfschmidt committed May 5, 2017
1 parent 7d2409b commit 7b1a379
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 360 deletions.
14 changes: 0 additions & 14 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,3 @@ Performance/Casecmp:
Description: 'Use `casecmp` rather than `downcase ==`.'
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code'
Enabled: false

# RSpec tests
Style/NumericPredicate:
Description: >-
Checks for the use of predicate- or comparison methods for
numeric comparisons.
StyleGuide: '#predicate-methods'
# This will change to a new method call which isn't guaranteed to be on the
# object. Switching these methods has to be done with knowledge of the types
# of the variables which rubocop doesn't have.
AutoCorrect: false
Enabled: true
Exclude:
- "**/*_spec.rb"
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ class App.UiElement.ticket_perform_action
config.operator = ['add', 'remove']
elements["#{groupKey}.#{config.name}"] = config

# add ticket deletion action
elements['ticket.action'] =
name: 'action'
display: 'Action'
tag: 'select'
null: false
translate: true
options:
delete: 'delete'

[defaults, groups, elements]

@render: (attribute, params = {}) ->
Expand Down
21 changes: 0 additions & 21 deletions app/models/concerns/has_karma_activity_log.rb

This file was deleted.

24 changes: 0 additions & 24 deletions app/models/concerns/has_links.rb

This file was deleted.

21 changes: 0 additions & 21 deletions app/models/concerns/has_online_notifications.rb

This file was deleted.

24 changes: 0 additions & 24 deletions app/models/karma/activity_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ class Karma::ActivityLog < ApplicationModel

self.table_name = 'karma_activity_logs'

=begin
add karma activity log of an object
Karma::ActivityLog.add('ticket create', User.find(1), 'Ticket', 123)
=end

def self.add(action, user, object, o_id, force = false)
activity = Karma::Activity.lookup(name: action)

Expand Down Expand Up @@ -55,22 +47,6 @@ def self.add(action, user, object, o_id, force = false)
true
end

=begin
remove whole karma activity log of an object
Karma::ActivityLog.remove('Ticket', 123)
=end

def self.remove(object_name, o_id)
object_id = ObjectLookup.by_name(object_name)
Karma::ActivityLog.where(
object_lookup_id: object_id,
o_id: o_id,
).destroy_all
end

def self.latest(user, limit = 12)
result = []
logs = Karma::ActivityLog.where(user_id: user.id).order(id: :desc).limit(limit)
Expand Down
73 changes: 29 additions & 44 deletions app/models/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class Link < ApplicationModel
belongs_to :link_type, class_name: 'Link::Type'
belongs_to :link_object, class_name: 'Link::Object'

after_destroy :touch_link_references

@map = {
'normal' => 'normal',
'parent' => 'child',
Expand Down Expand Up @@ -133,65 +131,52 @@ def self.remove(data)
linktype = link_type_get(name: data[:link_type])
data[:link_type_id] = linktype.id
end
Link.where(
links = Link.where(
link_type_id: data[:link_type_id],
link_object_source_id: data[:link_object_source_id],
link_object_source_value: data[:link_object_source_value],
link_object_target_id: data[:link_object_target_id],
link_object_target_value: data[:link_object_target_value]
).destroy_all
)

# touch references
links.each { |link|
link.destroy
touch_reference_by_params(
object: Link::Object.lookup(id: link.link_object_source_id).name,
o_id: link.link_object_source_value,
)
touch_reference_by_params(
object: Link::Object.lookup(id: link.link_object_target_id).name,
o_id: link.link_object_target_value,
)
}

# from the other site
if data.key?(:link_type)
linktype = link_type_get(name: @map[ data[:link_type] ])
data[:link_type_id] = linktype.id
end

Link.where(
links = Link.where(
link_type_id: data[:link_type_id],
link_object_target_id: data[:link_object_source_id],
link_object_target_value: data[:link_object_source_value],
link_object_source_id: data[:link_object_target_id],
link_object_source_value: data[:link_object_target_value]
).destroy_all
end

=begin
Link.remove_all(
link_object: 'Ticket',
link_object_value: 6,
)
=end

def self.remove_all(data)
if data.key?(:link_object)
linkobject = link_object_get(name: data[:link_object])
data[:link_object_id] = linkobject.id
end

Link.where(
link_object_target_id: data[:link_object_id],
link_object_target_value: data[:link_object_value],
).destroy_all
Link.where(
link_object_source_id: data[:link_object_id],
link_object_source_value: data[:link_object_value],
).destroy_all

true
end

def touch_link_references
Link.touch_reference_by_params(
object: Link::Object.lookup(id: link_object_source_id).name,
o_id: link_object_source_value,
)
Link.touch_reference_by_params(
object: Link::Object.lookup(id: link_object_target_id).name,
o_id: link_object_target_value,
)

# touch references
links.each { |link|
link.destroy
touch_reference_by_params(
object: Link::Object.lookup(id: link.link_object_source_id).name,
o_id: link.link_object_source_value,
)
touch_reference_by_params(
object: Link::Object.lookup(id: link.link_object_target_id).name,
o_id: link.link_object_target_value,
)
}
end

def self.link_type_get(data)
Expand Down
38 changes: 11 additions & 27 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class Ticket < ApplicationModel
include HasHistory
include HasTags
include HasSearchIndexBackend
include HasOnlineNotifications
include HasKarmaActivityLog
include HasLinks

include Ticket::Escalation
include Ticket::Subject
Expand All @@ -26,6 +23,7 @@ class Ticket < ApplicationModel
after_create :check_escalation_update
before_update :check_defaults, :check_title, :reset_pending_time
after_update :check_escalation_update
before_destroy :destroy_dependencies

validates :group_id, presence: true

Expand Down Expand Up @@ -57,7 +55,7 @@ class Ticket < ApplicationModel
:preferences

belongs_to :group, class_name: 'Group'
has_many :articles, class_name: 'Ticket::Article', after_add: :cache_update, after_remove: :cache_update, dependent: :destroy
has_many :articles, class_name: 'Ticket::Article', after_add: :cache_update, after_remove: :cache_update
has_many :ticket_time_accounting, class_name: 'Ticket::TimeAccounting', dependent: :destroy
belongs_to :organization, class_name: 'Organization'
belongs_to :state, class_name: 'Ticket::State'
Expand Down Expand Up @@ -750,19 +748,6 @@ def self.selector2sql(selectors, current_user = nil)

def perform_changes(perform, perform_origin, item = nil, current_user_id = nil)
logger.debug "Perform #{perform_origin} #{perform.inspect} on Ticket.find(#{id})"

# if the configuration contains the deletion of the ticket then
# we skip all other ticket changes because they does not matter
if perform['ticket.action'].present? && perform['ticket.action']['value'] == 'delete'
perform.each do |key, _value|
(object_name, attribute) = key.split('.', 2)
next if object_name != 'ticket'
next if attribute == 'action'

perform.delete(key)
end
end

changed = false
perform.each do |key, value|
(object_name, attribute) = key.split('.', 2)
Expand Down Expand Up @@ -921,16 +906,6 @@ def perform_changes(perform, perform_origin, item = nil, current_user_id = nil)
next
end

# delete ticket
if key == 'ticket.action'
next if value['value'].blank?
next if value['value'] != 'delete'

destroy

next
end

# lookup pre_condition
if value['pre_condition']
if value['pre_condition'] =~ /^not_set/
Expand Down Expand Up @@ -1071,6 +1046,15 @@ def check_escalation_update
true
end

def destroy_dependencies

# delete articles
articles.destroy_all

# destroy online notifications
OnlineNotification.remove(self.class.to_s, id)
end

def set_default_state
return if state_id

Expand Down
12 changes: 0 additions & 12 deletions spec/factories/online_notification.rb

This file was deleted.

7 changes: 0 additions & 7 deletions spec/factories/tag.rb

This file was deleted.

14 changes: 0 additions & 14 deletions spec/factories/ticket/article.rb

This file was deleted.

0 comments on commit 7b1a379

Please sign in to comment.