diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 199ccf7..d2b693b 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -74,8 +74,6 @@ class CmsController < MyProfileController record_coming if request.post? @article.image = nil if params[:remove_image] == 'true' - @article.users_with_agreement.clear if (@article.forum? and params[:article][:has_terms_of_use] == "0") - @article.users_with_agreement << user if (@article.forum? and params[:article][:has_terms_of_use] == "1" and !@article.users_with_agreement.include? user) @article.last_changed_by = user if @article.update_attributes(params[:article]) if !continue @@ -132,7 +130,6 @@ class CmsController < MyProfileController continue = params[:continue] if request.post? - @article.users_with_agreement << user if (@article.forum? and params[:article][:has_terms_of_use] == "1") if @article.save if continue redirect_to :action => 'edit', :id => @article diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 4ba0cb1..d845e77 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -56,8 +56,7 @@ class ContentViewerController < ApplicationController end elsif !@page.parent.nil? && @page.parent.forum? unless @page.parent.agrees_with_terms?(user) - params[:page].pop - redirect_to :profile => params[:profile], :page => params[:page], :action => 'view_page' + redirect_to @page.parent.url end end diff --git a/app/models/forum.rb b/app/models/forum.rb index a12cacc..0081452 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -7,6 +7,17 @@ class Forum < Folder settings_items :has_terms_of_use, :type => :boolean, :default => false has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people' + before_save do |forum| + if forum.has_terms_of_use + last_editor = forum.profile.environment.people.find_by_id(forum.last_changed_by_id) + if last_editor && !forum.users_with_agreement.exists?(last_editor) + forum.users_with_agreement << last_editor + end + else + forum.users_with_agreement.clear + end + end + def self.type_name _('Forum') end @@ -51,11 +62,8 @@ class Forum < Folder def agrees_with_terms?(user) return true unless self.has_terms_of_use - if user - self.users_with_agreement.find_by_id user.id - else - false - end + return false unless user + self.users_with_agreement.exists? user end end diff --git a/app/views/content_viewer/_terms_of_use.rhtml b/app/views/content_viewer/_terms_of_use.rhtml deleted file mode 100644 index ec01750..0000000 --- a/app/views/content_viewer/_terms_of_use.rhtml +++ /dev/null @@ -1 +0,0 @@ -

<%= page.terms_of_use %>

\ No newline at end of file diff --git a/app/views/content_viewer/forum_page.rhtml b/app/views/content_viewer/forum_page.rhtml index fb15107..63ed6e4 100644 --- a/app/views/content_viewer/forum_page.rhtml +++ b/app/views/content_viewer/forum_page.rhtml @@ -22,7 +22,7 @@ <% else %> <%= button :save, _("Accept"), login_url %> <% end %> - <%= button "cancel", _("Cancel"), profile.url %> + <%= button :cancel, _("Cancel"), profile.url %> <% end %> <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/db/schema.rb b/db/schema.rb index 97a5921..94c6269 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131121162641) do +ActiveRecord::Schema.define(:version => 20131128161159) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -566,6 +566,13 @@ ActiveRecord::Schema.define(:version => 20131121162641) do add_index "tasks", ["spam"], :name => "index_tasks_on_spam" + create_table "terms_forum_people", :id => false, :force => true do |t| + t.integer "forum_id" + t.integer "person_id" + end + + add_index "terms_forum_people", ["forum_id", "person_id"], :name => "index_terms_forum_people_on_forum_id_and_person_id" + create_table "thumbnails", :force => true do |t| t.integer "size" t.string "content_type" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index f5a52af..0e069fa 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -3338,6 +3338,9 @@ table.cms-articles .icon:hover { div.with_media_panel .formfield input { width: 100%; } +div.with_media_panel .formfield input[type="checkbox"] { + width: auto; +} .text-editor-sidebar { position: absolute; diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 7e3c948..edfcc97 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1698,6 +1698,16 @@ class CmsControllerTest < ActionController::TestCase :attributes => { :value => article.id.to_s }} end + should 'remove users that agreed with forum terms after removing terms' do + forum = Forum.create(:name => 'Forum test', :profile_id => profile.id, :has_terms_of_use => true) + person = fast_create(Person) + forum.users_with_agreement << person + + assert_difference Forum.find(forum.id).users_with_agreement, :count, -1 do + post :edit, :profile => profile.identifier, :id => forum.id, :article => { :has_terms_of_use => 'false' } + end + end + protected # FIXME this is to avoid adding an extra dependency for a proper JSON parser. diff --git a/test/unit/forum_test.rb b/test/unit/forum_test.rb index 496801f..0786530 100644 --- a/test/unit/forum_test.rb +++ b/test/unit/forum_test.rb @@ -133,4 +133,44 @@ class ForumTest < ActiveSupport::TestCase assert_equal '', f.first_paragraph end + should 'include user that changes a forum as agreed with terms' do + author = fast_create(Person) + editor = fast_create(Person) + forum = Forum.create(:profile => author, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true, :last_changed_by => author) + forum.last_changed_by = editor + forum.save + + assert_equivalent [author, editor], forum.users_with_agreement + end + + should 'not crash if forum has terms and last_changed does not exist' do + profile = fast_create(Person) + forum = Forum.create(:profile => profile, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true) + + assert_equal [], forum.users_with_agreement + end + + should 'agree with terms if forum doesn\'t have terms' do + person = fast_create(Person) + forum = fast_create(Forum) + + assert_equal true, forum.agrees_with_terms?(person) + end + + should 'not agree with terms if user is logged in but did not accept it' do + person = fast_create(Person) + forum = Forum.create(:profile => person, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true) + + assert_equal false, forum.agrees_with_terms?(person) + end + + should 'agree with terms if user is logged in and accept it' do + person = fast_create(Person) + forum = Forum.create(:profile => person, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true) + forum.users_with_agreement << person + forum.save + + assert_equal true, Forum.find(forum.id).agrees_with_terms?(person) + end + end -- libgit2 0.21.2