Commit 8f28228dfcaa8f166f5b7e0e0fe71bfd205acd98

Authored by Rodrigo Souto
1 parent 8e5fdb7f

[work-assignment] Removing author from database

app/controllers/my_profile/cms_controller.rb
@@ -123,7 +123,6 @@ class CmsController < MyProfileController @@ -123,7 +123,6 @@ class CmsController < MyProfileController
123 end 123 end
124 124
125 @article.profile = profile 125 @article.profile = profile
126 - @article.author = user  
127 @article.last_changed_by = user 126 @article.last_changed_by = user
128 127
129 translations if @article.translatable? 128 translations if @article.translatable?
@@ -161,7 +160,7 @@ class CmsController < MyProfileController @@ -161,7 +160,7 @@ class CmsController < MyProfileController
161 end 160 end
162 if request.post? && params[:uploaded_files] 161 if request.post? && params[:uploaded_files]
163 params[:uploaded_files].each do |file| 162 params[:uploaded_files].each do |file|
164 - @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent, :author => user) unless file == '' 163 + @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent, :last_changed_by => user) unless file == ''
165 end 164 end
166 @errors = @uploaded_files.select { |f| f.errors.any? } 165 @errors = @uploaded_files.select { |f| f.errors.any? }
167 if @errors.any? 166 if @errors.any?
app/models/approve_article.rb
@@ -48,7 +48,7 @@ class ApproveArticle &lt; Task @@ -48,7 +48,7 @@ class ApproveArticle &lt; Task
48 end 48 end
49 49
50 def perform 50 def perform
51 - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :author => article.author) 51 + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.author)
52 end 52 end
53 53
54 def title 54 def title
app/models/article.rb
@@ -502,7 +502,6 @@ class Article &lt; ActiveRecord::Base @@ -502,7 +502,6 @@ class Article &lt; ActiveRecord::Base
502 :slug, 502 :slug,
503 :updated_at, 503 :updated_at,
504 :created_at, 504 :created_at,
505 - :last_changed_by_id,  
506 :version, 505 :version,
507 :lock_version, 506 :lock_version,
508 :type, 507 :type,
@@ -545,7 +544,12 @@ class Article &lt; ActiveRecord::Base @@ -545,7 +544,12 @@ class Article &lt; ActiveRecord::Base
545 end 544 end
546 545
547 def author 546 def author
548 - versions.empty? ? last_changed_by : versions.first.last_changed_by 547 + if versions.empty?
  548 + last_changed_by
  549 + else
  550 + author_id = versions.first.last_changed_by_id
  551 + Person.exists?(author_id) ? Person.find(author_id) : nil
  552 + end
549 end 553 end
550 554
551 def author_name 555 def author_name
app/models/person.rb
@@ -54,8 +54,6 @@ class Person &lt; Profile @@ -54,8 +54,6 @@ class Person &lt; Profile
54 54
55 has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy 55 has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy
56 56
57 - has_many :creations, :class_name => 'Article', :foreign_key => :author_id  
58 -  
59 named_scope :more_popular, 57 named_scope :more_popular,
60 :select => "#{Profile.qualified_column_names}, count(friend_id) as total", 58 :select => "#{Profile.qualified_column_names}, count(friend_id) as total",
61 :group => Profile.qualified_column_names, 59 :group => Profile.qualified_column_names,
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
@@ -3,9 +3,9 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder @@ -3,9 +3,9 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
3 after_save do |work_assignment| 3 after_save do |work_assignment|
4 work_assignment.children.select {|child| child.kind_of?(UploadedFile)}.each do |submission| 4 work_assignment.children.select {|child| child.kind_of?(UploadedFile)}.each do |submission|
5 author_folder = work_assignment.find_or_create_author_folder(submission.author) 5 author_folder = work_assignment.find_or_create_author_folder(submission.author)
6 - submission.name = versioned_name(submission, author_folder) if !(submission.name =~ /\(V[0-9]*\)/) 6 + submission.name = versioned_name(submission, author_folder)
7 submission.parent = author_folder 7 submission.parent = author_folder
8 - submission.save! 8 + submission.save(false)
9 end 9 end
10 end 10 end
11 11
@@ -24,7 +24,9 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder @@ -24,7 +24,9 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
24 end 24 end
25 25
26 def self.versioned_name(submission, folder) 26 def self.versioned_name(submission, folder)
27 - "(V#{folder.children.count + 1}) #{submission.name}" 27 + return submission.name if submission.name =~ /\(V[0-9]*\)/
  28 + count = folder.children.include?(submission) ? folder.children.count : folder.children.count + 1
  29 + "(V#{count}) #{submission.name}"
28 end 30 end
29 31
30 def accept_comments? 32 def accept_comments?
plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
@@ -13,8 +13,8 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase @@ -13,8 +13,8 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase
13 end 13 end
14 14
15 should 'return versioned name' do 15 should 'return versioned name' do
16 - folder = fast_create(Folder)  
17 profile = fast_create(Profile) 16 profile = fast_create(Profile)
  17 + folder = fast_create(Folder, :profile_id => profile)
18 a1 = Article.create!(:name => "Article 1", :profile => profile) 18 a1 = Article.create!(:name => "Article 1", :profile => profile)
19 a2 = Article.create!(:name => "Article 2", :profile => profile) 19 a2 = Article.create!(:name => "Article 2", :profile => profile)
20 a3 = Article.create!(:name => "Article 3", :profile => profile) 20 a3 = Article.create!(:name => "Article 3", :profile => profile)
@@ -35,7 +35,7 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase @@ -35,7 +35,7 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase
35 organization = fast_create(Organization) 35 organization = fast_create(Organization)
36 author = fast_create(Person) 36 author = fast_create(Person)
37 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Sample Work Assignment', :profile => organization) 37 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Sample Work Assignment', :profile => organization)
38 - submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => work_assignment, :author => author) 38 + submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => work_assignment, :last_changed_by => author)
39 39
40 author_folder = work_assignment.find_or_create_author_folder(author) 40 author_folder = work_assignment.find_or_create_author_folder(author)
41 assert author_folder, submission.parent 41 assert author_folder, submission.parent
plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
@@ -3,7 +3,7 @@ require &#39;test_helper&#39; @@ -3,7 +3,7 @@ require &#39;test_helper&#39;
3 class WorkAssignmentPluginTest < ActiveSupport::TestCase 3 class WorkAssignmentPluginTest < ActiveSupport::TestCase
4 should 'verify if a content is a work_assignment submission' do 4 should 'verify if a content is a work_assignment submission' do
5 organization = fast_create(Organization) 5 organization = fast_create(Organization)
6 - content = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization) 6 + content = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :last_changed_by => fast_create(Person))
7 assert !WorkAssignmentPlugin.is_submission?(content) 7 assert !WorkAssignmentPlugin.is_submission?(content)
8 8
9 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) 9 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
@@ -32,8 +32,7 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase @@ -32,8 +32,7 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase
32 submission = create_submission 32 submission = create_submission
33 assert !WorkAssignmentPlugin.can_download_submission?(person, submission) 33 assert !WorkAssignmentPlugin.can_download_submission?(person, submission)
34 34
35 - submission.author = person  
36 - submission.save! 35 + submission = create_submission(person)
37 assert WorkAssignmentPlugin.can_download_submission?(person, submission) 36 assert WorkAssignmentPlugin.can_download_submission?(person, submission)
38 end 37 end
39 38
@@ -48,10 +47,10 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase @@ -48,10 +47,10 @@ class WorkAssignmentPluginTest &lt; ActiveSupport::TestCase
48 47
49 private 48 private
50 49
51 - def create_submission 50 + def create_submission(author=nil)
52 organization = fast_create(Organization) 51 organization = fast_create(Organization)
53 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) 52 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization)
54 author_folder = work_assignment.find_or_create_author_folder(fast_create(Person)) 53 author_folder = work_assignment.find_or_create_author_folder(fast_create(Person))
55 - UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => author_folder) 54 + UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => author_folder, :last_changed_by => author)
56 end 55 end
57 end 56 end
test/functional/cms_controller_test.rb
@@ -1125,7 +1125,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1125,7 +1125,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1125 should 'not allow user edit article if he is owner but has no publish permission' do 1125 should 'not allow user edit article if he is owner but has no publish permission' do
1126 c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') 1126 c = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
1127 u = create_user_with_permission('test_user', 'bogus_permission', c) 1127 u = create_user_with_permission('test_user', 'bogus_permission', c)
1128 - a = c.articles.create!(:name => 'test_article', :author => u) 1128 + a = c.articles.create!(:name => 'test_article', :last_changed_by => u)
1129 login_as :test_user 1129 login_as :test_user
1130 1130
1131 get :edit, :profile => c.identifier, :id => a.id 1131 get :edit, :profile => c.identifier, :id => a.id
@@ -1136,7 +1136,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1136,7 +1136,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1136 should 'allow user edit article if he is owner and has publish permission' do 1136 should 'allow user edit article if he is owner and has publish permission' do
1137 c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') 1137 c = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
1138 u = create_user_with_permission('test_user', 'publish_content', c) 1138 u = create_user_with_permission('test_user', 'publish_content', c)
1139 - a = c.articles.create!(:name => 'test_article', :author => u) 1139 + a = c.articles.create!(:name => 'test_article', :last_changed_by => u)
1140 login_as :test_user 1140 login_as :test_user
1141 @controller.stubs(:user).returns(u) 1141 @controller.stubs(:user).returns(u)
1142 1142
test/functional/content_viewer_controller_test.rb
@@ -850,7 +850,7 @@ end @@ -850,7 +850,7 @@ end
850 c = Community.create!(:name => 'test_com') 850 c = Community.create!(:name => 'test_com')
851 u = create_user_with_permission('test_user', 'publish_content', c) 851 u = create_user_with_permission('test_user', 'publish_content', c)
852 login_as u.identifier 852 login_as u.identifier
853 - a = c.articles.create!(:name => 'test-article', :author => u, :published => false) 853 + a = c.articles.create!(:name => 'test-article', :last_changed_by => u, :published => false)
854 854
855 get :view_page, :profile => c.identifier, :page => a.explode_path 855 get :view_page, :profile => c.identifier, :page => a.explode_path
856 856
test/unit/approve_article_test.rb
@@ -210,9 +210,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -210,9 +210,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
210 end 210 end
211 211
212 should 'use author from original article on published' do 212 should 'use author from original article on published' do
213 - article.author = profile  
214 - article.save!  
215 - 213 + article.class.any_instance.stubs(:author).returns(profile)
216 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 214 a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
217 a.finish 215 a.finish
218 216
@@ -220,8 +218,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -220,8 +218,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
220 end 218 end
221 219
222 should 'use original article author even if article is destroyed' do 220 should 'use original article author even if article is destroyed' do
223 - article.author = profile  
224 - article.save! 221 + article.class.any_instance.stubs(:author).returns(profile)
225 a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 222 a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
226 a.finish 223 a.finish
227 224
test/unit/forum_helper_test.rb
@@ -29,16 +29,16 @@ class ForumHelperTest &lt; ActiveSupport::TestCase @@ -29,16 +29,16 @@ class ForumHelperTest &lt; ActiveSupport::TestCase
29 end 29 end
30 30
31 should 'list posts with different classes' do 31 should 'list posts with different classes' do
32 - forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false, :author => profile) 32 + forum.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => false, :last_changed_by => profile)
33 one_month_later = Time.now + 1.month 33 one_month_later = Time.now + 1.month
34 Time.stubs(:now).returns(one_month_later) 34 Time.stubs(:now).returns(one_month_later)
35 - forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true, :author => profile) 35 + forum.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => forum, :published => true, :last_changed_by => profile)
36 assert_match /forum-post position-1 first odd-post.*forum-post position-2 last not-published even-post/, list_forum_posts(forum.posts) 36 assert_match /forum-post position-1 first odd-post.*forum-post position-2 last not-published even-post/, list_forum_posts(forum.posts)
37 end 37 end
38 38
39 should 'return post update if it has no comments' do 39 should 'return post update if it has no comments' do
40 author = create_user('forum test author').person 40 author = create_user('forum test author').person
41 - some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author) 41 + some_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => forum, :published => true, :last_changed_by => author)
42 assert some_post.comments.empty? 42 assert some_post.comments.empty?
43 out = last_topic_update(some_post) 43 out = last_topic_update(some_post)
44 assert_match some_post.updated_at.to_s, out 44 assert_match some_post.updated_at.to_s, out
test/unit/person_test.rb
@@ -1262,15 +1262,4 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1262,15 +1262,4 @@ class PersonTest &lt; ActiveSupport::TestCase
1262 1262
1263 assert person.has_permission?('bli', Profile.new) 1263 assert person.has_permission?('bli', Profile.new)
1264 end 1264 end
1265 -  
1266 - should 'have creations' do  
1267 - person = create_user('some-user').person  
1268 - a1 = fast_create(Article, :author_id => person.id)  
1269 - a2 = fast_create(Article, :author_id => person.id)  
1270 - a3 = fast_create(Article)  
1271 -  
1272 - assert_includes person.creations, a1  
1273 - assert_includes person.creations, a2  
1274 - assert_not_includes person.creations, a3  
1275 - end  
1276 end 1265 end