Commit 8f28228dfcaa8f166f5b7e0e0fe71bfd205acd98
1 parent
8e5fdb7f
Exists in
staging
and in
42 other branches
[work-assignment] Removing author from database
Showing
12 changed files
with
27 additions
and
39 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -123,7 +123,6 @@ class CmsController < MyProfileController |
123 | 123 | end |
124 | 124 | |
125 | 125 | @article.profile = profile |
126 | - @article.author = user | |
127 | 126 | @article.last_changed_by = user |
128 | 127 | |
129 | 128 | translations if @article.translatable? |
... | ... | @@ -161,7 +160,7 @@ class CmsController < MyProfileController |
161 | 160 | end |
162 | 161 | if request.post? && params[:uploaded_files] |
163 | 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 | 164 | end |
166 | 165 | @errors = @uploaded_files.select { |f| f.errors.any? } |
167 | 166 | if @errors.any? | ... | ... |
app/models/approve_article.rb
... | ... | @@ -48,7 +48,7 @@ class ApproveArticle < Task |
48 | 48 | end |
49 | 49 | |
50 | 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 | 52 | end |
53 | 53 | |
54 | 54 | def title | ... | ... |
app/models/article.rb
... | ... | @@ -502,7 +502,6 @@ class Article < ActiveRecord::Base |
502 | 502 | :slug, |
503 | 503 | :updated_at, |
504 | 504 | :created_at, |
505 | - :last_changed_by_id, | |
506 | 505 | :version, |
507 | 506 | :lock_version, |
508 | 507 | :type, |
... | ... | @@ -545,7 +544,12 @@ class Article < ActiveRecord::Base |
545 | 544 | end |
546 | 545 | |
547 | 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 | 553 | end |
550 | 554 | |
551 | 555 | def author_name | ... | ... |
app/models/person.rb
... | ... | @@ -54,8 +54,6 @@ class Person < Profile |
54 | 54 | |
55 | 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 | 57 | named_scope :more_popular, |
60 | 58 | :select => "#{Profile.qualified_column_names}, count(friend_id) as total", |
61 | 59 | :group => Profile.qualified_column_names, | ... | ... |
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
... | ... | @@ -3,9 +3,9 @@ class WorkAssignmentPlugin::WorkAssignment < Folder |
3 | 3 | after_save do |work_assignment| |
4 | 4 | work_assignment.children.select {|child| child.kind_of?(UploadedFile)}.each do |submission| |
5 | 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 | 7 | submission.parent = author_folder |
8 | - submission.save! | |
8 | + submission.save(false) | |
9 | 9 | end |
10 | 10 | end |
11 | 11 | |
... | ... | @@ -24,7 +24,9 @@ class WorkAssignmentPlugin::WorkAssignment < Folder |
24 | 24 | end |
25 | 25 | |
26 | 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 | 30 | end |
29 | 31 | |
30 | 32 | def accept_comments? | ... | ... |
plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
... | ... | @@ -13,8 +13,8 @@ class WorkAssignmentTest < ActiveSupport::TestCase |
13 | 13 | end |
14 | 14 | |
15 | 15 | should 'return versioned name' do |
16 | - folder = fast_create(Folder) | |
17 | 16 | profile = fast_create(Profile) |
17 | + folder = fast_create(Folder, :profile_id => profile) | |
18 | 18 | a1 = Article.create!(:name => "Article 1", :profile => profile) |
19 | 19 | a2 = Article.create!(:name => "Article 2", :profile => profile) |
20 | 20 | a3 = Article.create!(:name => "Article 3", :profile => profile) |
... | ... | @@ -35,7 +35,7 @@ class WorkAssignmentTest < ActiveSupport::TestCase |
35 | 35 | organization = fast_create(Organization) |
36 | 36 | author = fast_create(Person) |
37 | 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 | 40 | author_folder = work_assignment.find_or_create_author_folder(author) |
41 | 41 | assert author_folder, submission.parent | ... | ... |
plugins/work_assignment/test/unit/work_assingment_plugin_test.rb
... | ... | @@ -3,7 +3,7 @@ require 'test_helper' |
3 | 3 | class WorkAssignmentPluginTest < ActiveSupport::TestCase |
4 | 4 | should 'verify if a content is a work_assignment submission' do |
5 | 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 | 7 | assert !WorkAssignmentPlugin.is_submission?(content) |
8 | 8 | |
9 | 9 | work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) |
... | ... | @@ -32,8 +32,7 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase |
32 | 32 | submission = create_submission |
33 | 33 | assert !WorkAssignmentPlugin.can_download_submission?(person, submission) |
34 | 34 | |
35 | - submission.author = person | |
36 | - submission.save! | |
35 | + submission = create_submission(person) | |
37 | 36 | assert WorkAssignmentPlugin.can_download_submission?(person, submission) |
38 | 37 | end |
39 | 38 | |
... | ... | @@ -48,10 +47,10 @@ class WorkAssignmentPluginTest < ActiveSupport::TestCase |
48 | 47 | |
49 | 48 | private |
50 | 49 | |
51 | - def create_submission | |
50 | + def create_submission(author=nil) | |
52 | 51 | organization = fast_create(Organization) |
53 | 52 | work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Work Assignment', :profile => organization) |
54 | 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 | 55 | end |
57 | 56 | end | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -1125,7 +1125,7 @@ class CmsControllerTest < ActionController::TestCase |
1125 | 1125 | should 'not allow user edit article if he is owner but has no publish permission' do |
1126 | 1126 | c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') |
1127 | 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 | 1129 | login_as :test_user |
1130 | 1130 | |
1131 | 1131 | get :edit, :profile => c.identifier, :id => a.id |
... | ... | @@ -1136,7 +1136,7 @@ class CmsControllerTest < ActionController::TestCase |
1136 | 1136 | should 'allow user edit article if he is owner and has publish permission' do |
1137 | 1137 | c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') |
1138 | 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 | 1140 | login_as :test_user |
1141 | 1141 | @controller.stubs(:user).returns(u) |
1142 | 1142 | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -850,7 +850,7 @@ end |
850 | 850 | c = Community.create!(:name => 'test_com') |
851 | 851 | u = create_user_with_permission('test_user', 'publish_content', c) |
852 | 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 | 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 < ActiveSupport::TestCase |
210 | 210 | end |
211 | 211 | |
212 | 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 | 214 | a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) |
217 | 215 | a.finish |
218 | 216 | |
... | ... | @@ -220,8 +218,7 @@ class ApproveArticleTest < ActiveSupport::TestCase |
220 | 218 | end |
221 | 219 | |
222 | 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 | 222 | a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) |
226 | 223 | a.finish |
227 | 224 | ... | ... |
test/unit/forum_helper_test.rb
... | ... | @@ -29,16 +29,16 @@ class ForumHelperTest < ActiveSupport::TestCase |
29 | 29 | end |
30 | 30 | |
31 | 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 | 33 | one_month_later = Time.now + 1.month |
34 | 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 | 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 | 37 | end |
38 | 38 | |
39 | 39 | should 'return post update if it has no comments' do |
40 | 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 | 42 | assert some_post.comments.empty? |
43 | 43 | out = last_topic_update(some_post) |
44 | 44 | assert_match some_post.updated_at.to_s, out | ... | ... |
test/unit/person_test.rb
... | ... | @@ -1262,15 +1262,4 @@ class PersonTest < ActiveSupport::TestCase |
1262 | 1262 | |
1263 | 1263 | assert person.has_permission?('bli', Profile.new) |
1264 | 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 | 1265 | end | ... | ... |