From a86306b1acc9b945fb1c5c33015724a1487b9fac Mon Sep 17 00:00:00 2001 From: Michel Felipe de Oliveira Ferreira Date: Mon, 16 Nov 2015 16:48:41 -0300 Subject: [PATCH] New feature archive articles to avoid create comments, associate children articles and perform votes --- app/controllers/my_profile/cms_controller.rb | 1 + app/helpers/article_helper.rb | 20 +++++++++++++++++--- app/helpers/folder_helper.rb | 8 ++++++++ app/models/article.rb | 16 +++++++++++++++- app/models/comment.rb | 4 ++++ app/models/folder.rb | 4 ++++ app/views/cms/_archived_warning.html.erb | 8 ++++++++ app/views/cms/edit.html.erb | 4 ++++ app/views/content_viewer/_article_toolbar.html.erb | 7 ++++++- app/views/content_viewer/view_page.html.erb | 2 +- db/migrate/20151112135709_add_archived_to_articles.rb | 9 +++++++++ public/images/icons-app/article-archived-icon.png | Bin 0 -> 166 bytes public/images/icons-app/article-private-icon.png | Bin 0 -> 273 bytes public/images/icons-app/article-public-icon.png | Bin 0 -> 570 bytes public/images/icons-app/warning-icon.png | Bin 0 -> 509 bytes public/javascripts/article.js | 6 ++++++ public/stylesheets/cms.scss | 1 + public/stylesheets/cms/access-options.scss | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/functional/cms_controller_test.rb | 28 ++++++++++++++++++++++++++++ 19 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 app/views/cms/_archived_warning.html.erb create mode 100644 db/migrate/20151112135709_add_archived_to_articles.rb create mode 100644 public/images/icons-app/article-archived-icon.png create mode 100644 public/images/icons-app/article-private-icon.png create mode 100644 public/images/icons-app/article-public-icon.png create mode 100644 public/images/icons-app/warning-icon.png create mode 100644 public/stylesheets/cms/access-options.scss diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 701a2dd..334d872 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -99,6 +99,7 @@ class CmsController < MyProfileController @article.image.save! end @article.last_changed_by = user + @article.old_parent_id = @article.parent_id if @article.update_attributes(params[:article]) if !continue if @article.content_type.nil? || @article.image? diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index 4ec0477..9d9d3d0 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -15,6 +15,13 @@ module ArticleHelper topic_creation(@article) + content_tag('h4', _('Options')) + content_tag('div', + content_tag('div', + check_box(:article, :archived) + + content_tag('span', ' ', :class => 'access-archived-icon') + + content_tag('label', _('Read Only'), :for => 'article_archived_true') + + content_tag('span', _('Archive to avoid create comments, votes, actions in children articles...'), :class => 'access-note'), + :class => 'access-item' + ) + (article.profile.has_members? ? content_tag( 'div', @@ -63,13 +70,20 @@ module ArticleHelper content_tag('div', content_tag('div', radio_button(:article, :published, true) + - content_tag('label', _('Public (visible to other people)'), :for => 'article_published_true') + content_tag('span', ' ', :class => 'access-public-icon') + + content_tag('label', _('Public'), :for => 'article_published_true') + + content_tag('span', _('Visible to other people'), :class => 'access-note'), + :class => 'access-item' ) + content_tag('div', radio_button(:article, :published, false) + - content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") + content_tag('span', ' ', :class => 'access-private-icon') + + content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") + + content_tag('span', _('Limit visibility of this article'), :class => 'access-note'), + :class => 'access-item' ) + - privacity_exceptions(article, tokenized_children) + privacity_exceptions(article, tokenized_children), + :class => 'access-itens' ) end diff --git a/app/helpers/folder_helper.rb b/app/helpers/folder_helper.rb index a1b43d0..4587643 100644 --- a/app/helpers/folder_helper.rb +++ b/app/helpers/folder_helper.rb @@ -61,7 +61,15 @@ module FolderHelper @article = article visibility_options(article,tokenized_children) + + content_tag('h4', _('Options')) + content_tag('div', + content_tag('div', + check_box(:article, :archived) + + content_tag('span', ' ', :class => 'access-archived-icon') + + content_tag('label', _('Read Only'), :for => 'article_archived_true') + + content_tag('span', _('Archive to avoid votes and create new children articles'), :class => 'access-note'), + :class => 'access-item' + ) + hidden_field_tag('article[accept_comments]', 0) ) end diff --git a/app/models/article.rb b/app/models/article.rb index e9a25ea..da75d53 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -9,7 +9,9 @@ class Article < ActiveRecord::Base :highlighted, :notify_comments, :display_hits, :slug, :external_feed_builder, :display_versions, :external_link, :image_builder, :show_to_followers, - :author, :display_preview + :author, :display_preview, :archived + + attr_accessor :old_parent_id acts_as_having_image @@ -154,6 +156,8 @@ class Article < ActiveRecord::Base validate :no_self_reference validate :no_cyclical_reference, :if => 'parent_id.present?' + validate :parent_archived? + def no_self_reference errors.add(:parent_id, _('self-reference is not allowed.')) if id && parent_id == id end @@ -484,6 +488,10 @@ class Article < ActiveRecord::Base end end + def archived? + (self.parent && self.parent.archived) || self.archived + end + def self.folder_types ['Folder', 'Blog', 'Forum', 'Gallery'] end @@ -842,4 +850,10 @@ class Article < ActiveRecord::Base sanitizer.sanitize(text) end + def parent_archived? + if (self.old_parent_id != self.parent_id) && self.parent && self.parent.archived? + errors.add(:parent_folder, N_('is archived!!')) + end + end + end diff --git a/app/models/comment.rb b/app/models/comment.rb index 6fce6cd..487d861 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -210,4 +210,8 @@ class Comment < ActiveRecord::Base user.present? && user == author end + def archived? + self.article.archived? + end + end diff --git a/app/models/folder.rb b/app/models/folder.rb index 7640c12..3f9e7ab 100644 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -65,4 +65,8 @@ class Folder < Article !self.has_posts? || self.gallery? end + def archived? + self.archived + end + end diff --git a/app/views/cms/_archived_warning.html.erb b/app/views/cms/_archived_warning.html.erb new file mode 100644 index 0000000..62c48fc --- /dev/null +++ b/app/views/cms/_archived_warning.html.erb @@ -0,0 +1,8 @@ +<% if !article.errors.any? %> +
+

+ + <%= _("Archived article! It's read-only") %> +

+
+<% end %> diff --git a/app/views/cms/edit.html.erb b/app/views/cms/edit.html.erb index 2ad2960..2870ee0 100644 --- a/app/views/cms/edit.html.erb +++ b/app/views/cms/edit.html.erb @@ -1,5 +1,8 @@ <%= error_messages_for 'article' %> +<% if @article.archived? %> + <%= render :partial => 'archived_warning', :locals => {:article => @article} %> +<% end %>
'> <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> @@ -9,6 +12,7 @@ <%= hidden_field_tag('success_back_to', @success_back_to) %> + <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> <% if environment.is_portal_community?(profile) %> diff --git a/app/views/content_viewer/_article_toolbar.html.erb b/app/views/content_viewer/_article_toolbar.html.erb index 9e4583e..67276ee 100644 --- a/app/views/content_viewer/_article_toolbar.html.erb +++ b/app/views/content_viewer/_article_toolbar.html.erb @@ -29,7 +29,9 @@ <%= expirable_button @page, :locale, content, url %> <% end %> - <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : @page.parent))) unless remove_content_button(:new, @page) %> + <% if !@page.archived? %> + <%= modal_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : @page.parent))) unless remove_content_button(:new, @page) %> + <% end %> <% content = content_tag('span', label_for_clone_article(@page)) %> <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'new', :id => @page.id, :clone => true, :parent_id => (@page.folder? ? @page : @page.parent), :type => @page.class}) %> @@ -64,6 +66,9 @@ <% end %> <%= button_without_text(:feed, _('RSS feed'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> <%= @plugins.dispatch(:article_header_extra_contents, @page).collect { |content| instance_exec(&content) }.join("") %> + <% if @page.archived? %> + <%= render :partial => 'cms/archived_warning', :locals => {:article => @page} %> + <% end %> <%= render :partial => 'article_title', :locals => {:no_link => true} %> <%= article_translations(@page) %>
diff --git a/app/views/content_viewer/view_page.html.erb b/app/views/content_viewer/view_page.html.erb index f089768..7853674 100644 --- a/app/views/content_viewer/view_page.html.erb +++ b/app/views/content_viewer/view_page.html.erb @@ -85,7 +85,7 @@ <% end %> - <% if @page.accept_comments? %> + <% if !@page.archived? || @page.accept_comments? %>
<%= render :partial => 'comment/comment_form', :locals =>{:url => {:controller => :comment, :action => :create}, :display_link => true, :cancel_triggers_hide => true}%>
<% end %> diff --git a/db/migrate/20151112135709_add_archived_to_articles.rb b/db/migrate/20151112135709_add_archived_to_articles.rb new file mode 100644 index 0000000..55e31a3 --- /dev/null +++ b/db/migrate/20151112135709_add_archived_to_articles.rb @@ -0,0 +1,9 @@ +class AddArchivedToArticles < ActiveRecord::Migration + def up + add_column :articles, :archived, :boolean, :default => false + end + + def down + remove_column :articles, :archived + end +end diff --git a/public/images/icons-app/article-archived-icon.png b/public/images/icons-app/article-archived-icon.png new file mode 100644 index 0000000..8c63824 Binary files /dev/null and b/public/images/icons-app/article-archived-icon.png differ diff --git a/public/images/icons-app/article-private-icon.png b/public/images/icons-app/article-private-icon.png new file mode 100644 index 0000000..d91232e Binary files /dev/null and b/public/images/icons-app/article-private-icon.png differ diff --git a/public/images/icons-app/article-public-icon.png b/public/images/icons-app/article-public-icon.png new file mode 100644 index 0000000..d053ae2 Binary files /dev/null and b/public/images/icons-app/article-public-icon.png differ diff --git a/public/images/icons-app/warning-icon.png b/public/images/icons-app/warning-icon.png new file mode 100644 index 0000000..c13f43c Binary files /dev/null and b/public/images/icons-app/warning-icon.png differ diff --git a/public/javascripts/article.js b/public/javascripts/article.js index eda37e2..4e1cc00 100644 --- a/public/javascripts/article.js +++ b/public/javascripts/article.js @@ -212,4 +212,10 @@ jQuery(function($) { $("#article_published_true").click(show_hide_privacy_options); $(".custom_privacy_option").click(show_hide_token_input); + //Workaround to pointer-events:none CSS3 + $('a.disabled').click(function(e){ + e.preventDefault(); + return false; + }); + }); diff --git a/public/stylesheets/cms.scss b/public/stylesheets/cms.scss index 414e17c..c911cb6 100644 --- a/public/stylesheets/cms.scss +++ b/public/stylesheets/cms.scss @@ -1,5 +1,6 @@ @import 'cms/fetch-external-feed'; @import 'cms/media-panel'; +@import 'cms/access-options'; table.cms-articles { table-layout: fixed; diff --git a/public/stylesheets/cms/access-options.scss b/public/stylesheets/cms/access-options.scss new file mode 100644 index 0000000..3efcd08 --- /dev/null +++ b/public/stylesheets/cms/access-options.scss @@ -0,0 +1,67 @@ +//Variables +$icons-size: 24px; +$warning-color: #e75e40; +$description-color: #666; +$access-types: public, private, archived; + +.text-warning { + text-align: center; + color: $warning-color; + font: { + size: 15px; + weight: bold; + } + + p i.icon { + display: inline-block; + font-size: inherit; + text-rendering: auto; + background: url('images/icons-app/warning-icon.png'); + vertical-align: middle; + margin-top: -5px; + width: $icons-size; + height: $icons-size; + border: none; + } +} + +#edit-article-options { + + .access-itens .access-item { + input,label { + cursor: pointer; + } + } + + .access-item { + margin: 15px 0; + label { + font: { + size: 13px; + weight: bold; + } + } + } + + @each $access_type in $access-types { + .access-#{$access_type}-icon, .access-#{$access_type}-icon { + display: inline-block; + margin-right: 5px; + width: $icons-size; + height: $icons-size; + vertical-align: middle; + background-image: url('images/icons-app/article-#{$access_type}-icon.png'); + } + } + + .access-note { + display: block; + margin: 0; + color: $description-color; + margin-left: 50px; + font: { + size: 12px; + weight: normal; + } + } +} diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index a7a41e6..246f077 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -697,6 +697,34 @@ class CmsControllerTest < ActionController::TestCase end end + should "marks a article like archived" do + article = create(Article, :profile => profile, :name => 'test', :published => true, :archived => false) + + post :edit, :profile => profile.identifier, :id => article.id, :article => {:archived => true} + get :edit, :profile => profile.identifier, :id => article.id + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[archived]', :id => 'article_archived', :checked => 'checked' } + + end + + should "try add children into archived folders" do + folder = create(Folder, :profile => profile, :name => 'test', :published => true, :archived => false) + article_child = create(Article, :profile => profile, :name => 'test child', :parent_id => folder.id, :published => true, :archived => false) + + get :edit, :profile => profile.identifier, :id => folder.id + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[archived]', :id => 'article_archived' } + + post :edit, :profile => profile.identifier, :id => folder.id, :article => {:archived => true} + + get :edit, :profile => profile.identifier, :id => article_child.id + assert_tag :tag => 'div', :attributes => { :class => 'text-warning'} + + err = assert_raises ActiveRecord::RecordInvalid do + another_article_child = create(Article, :profile => profile, :name => 'other test child', :parent_id => folder.id, :published => true, :archived => false) + end + assert_match 'Parent folder is archived', err.message + + end + should 'be able to add image with alignment' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image right align..." } saved = TinyMceArticle.find_by_name('image-alignment') -- libgit2 0.21.2