Do not allow karma scores below 0.
This commit is contained in:
parent
61fd93ea78
commit
7efa4b0d29
3 changed files with 25 additions and 4 deletions
|
@ -42,7 +42,7 @@
|
|||
|
||||
<h2><%- @T('What affects your Zammad Karma?') %></h2>
|
||||
|
||||
<p><%- @T('You accumulate "positive Karma" when you regularly answer and close tickets on time and when you use advanced features such as text modules, ticket reminders or tagging tickets. Zammad Karma will decrease when you have re-opend tickets, escalated tickets or tickets that are two or more days overdue.') %></p>
|
||||
<p><%- @T('You |accumulate positive Karma| when you regularly answer and close tickets on time and when you use advanced features such as text modules, ticket reminders or tagging tickets. Zammad |Karma will decrease| when you have re-opend tickets, escalated tickets or tickets that are two or more days overdue.') %></p>
|
||||
|
||||
<!--
|
||||
<p><%- @T('You’re able to set goals regarding the number of tickets you want to answer or close you want to complete either daily or weekly. Reaching these self-set goals will result in bonus Karma. Zammad also tracks how many days/weeks you have attained your goals, and achieving ongoing "streaks" will similarly result in positive Karma.') %></p>
|
||||
|
|
|
@ -5,7 +5,7 @@ class Karma::ActivityLog < ApplicationModel
|
|||
|
||||
self.table_name = 'karma_activity_logs'
|
||||
|
||||
def self.add(action, user, object, o_id)
|
||||
def self.add(action, user, object, o_id, force = false)
|
||||
activity = Karma::Activity.lookup(name: action)
|
||||
|
||||
if object
|
||||
|
@ -20,19 +20,24 @@ class Karma::ActivityLog < ApplicationModel
|
|||
o_id: o_id,
|
||||
activity_id: activity.id,
|
||||
).find_by('created_at >= ?', Time.zone.now - activity.once_ttl.seconds)
|
||||
return false if latest_activity
|
||||
return false if !force && latest_activity
|
||||
score_total = 0
|
||||
if last_activity
|
||||
score_total = last_activity.score_total
|
||||
end
|
||||
|
||||
local_score_total = score_total + activity.score
|
||||
if local_score_total < 0
|
||||
local_score_total = 0
|
||||
end
|
||||
|
||||
Karma::ActivityLog.create(
|
||||
object_lookup_id: object_id,
|
||||
o_id: o_id,
|
||||
user_id: user.id,
|
||||
activity_id: activity.id,
|
||||
score: activity.score,
|
||||
score_total: score_total + activity.score,
|
||||
score_total: local_score_total,
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -498,6 +498,22 @@ class KarmaTest < ActiveSupport::TestCase
|
|||
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
||||
assert_equal(0, Karma.score_by_user(customer1))
|
||||
|
||||
# check min score
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
Karma::ActivityLog.add('ticket escalated', ticket2.owner, 'Ticket', ticket2.id, true)
|
||||
assert_equal(0, Karma.score_by_user(agent1), 'block - score, min is 0')
|
||||
assert_equal(5 + 10 + 4, Karma.score_by_user(agent2))
|
||||
assert_equal(0, Karma.score_by_user(customer1))
|
||||
|
||||
Ticket.destroy_all
|
||||
|
||||
# test score/level
|
||||
assert_equal('Beginner', Karma::User.level_by_score(0))
|
||||
assert_equal('Beginner', Karma::User.level_by_score(400))
|
||||
|
|
Loading…
Reference in a new issue