aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <a3li@gentoo.org>2011-10-24 20:35:58 +0200
committerAlex Legler <a3li@gentoo.org>2011-10-24 20:35:58 +0200
commit99c7133ef729c3b5eba937498620213dc2f371d9 (patch)
tree4c80fee14ecd1779cb174349194be54dd941a2b5
parentAdd spell-checking using runspell/hunspell. (diff)
downloadglsamaker-99c7133ef729c3b5eba937498620213dc2f371d9.tar.gz
glsamaker-99c7133ef729c3b5eba937498620213dc2f371d9.tar.bz2
glsamaker-99c7133ef729c3b5eba937498620213dc2f371d9.zip
Implement better approval/rejection logic
TODO: write tests
-rw-r--r--app/models/glsa.rb27
-rw-r--r--app/views/glsa/_comments.html.erb2
2 files changed, 27 insertions, 2 deletions
diff --git a/app/models/glsa.rb b/app/models/glsa.rb
index 65493c5..900577c 100644
--- a/app/models/glsa.rb
+++ b/app/models/glsa.rb
@@ -70,7 +70,32 @@ class Glsa < ActiveRecord::Base
# Returns true if the draft is ready for sending
def is_approved?
- (approvals.count - rejections.count) >= 2
+ count = 0
+ users_who_approved = approvals.map { |a| a.user_id }
+ users_who_rejected = rejections.map { |a| a.user_id }
+
+ common_users = (users_who_approved & users_who_rejected)
+ common_users.each do |user|
+ approval = approvals.where(:user_id => user).order('created_at DESC').first
+ rejection = rejections.where(:user_id => user).order('created_at DESC').first
+
+ # if the approval was before a rejection => 0
+ if approval.created_at < rejection.created_at
+ count += 0
+ elsif approval.created_at > rejection.created_at
+ count += 1
+ end
+ end
+
+ (users_who_approved - common_users).each do |user|
+ count += 1
+ end
+
+ (users_who_rejected - common_users).each do |user|
+ count -= 1
+ end
+
+ (count >= 2)
end
# Returns true if it has comments
diff --git a/app/views/glsa/_comments.html.erb b/app/views/glsa/_comments.html.erb
index 5a58af9..0d92f5d 100644
--- a/app/views/glsa/_comments.html.erb
+++ b/app/views/glsa/_comments.html.erb
@@ -6,6 +6,6 @@
]
) %>
<ul id="commentslist">
- <%= render :partial => "comment", :collection => @glsa.comments %>
+ <%= render :partial => "comment", :collection => @glsa.comments.order("created_at DESC") %>
</ul>
</div>