From eef8ad1b734806ebbfd80336744f7a07119c95b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Wed, 27 Sep 2017 10:41:48 +0200 Subject: [PATCH 1/3] Remove images single uploads --- app/assets/stylesheets/mixins.scss | 24 -- app/assets/stylesheets/participation.scss | 8 +- app/controllers/images_controller.rb | 37 --- app/helpers/imageables_helper.rb | 4 - app/models/abilities/administrator.rb | 2 +- app/models/abilities/common.rb | 2 +- .../investments/_investment_show.html.erb | 6 - app/views/images/_form.html.erb | 65 ----- app/views/images/_image.html.erb | 3 +- app/views/images/_image_fields.html.erb | 2 +- app/views/images/new.html.erb | 30 -- app/views/proposals/show.html.erb | 10 +- config/locales/en/images.yml | 24 +- config/locales/es/images.yml | 24 +- config/routes.rb | 9 +- spec/models/abilities/administrator_spec.rb | 5 - spec/models/abilities/common_spec.rb | 10 - spec/shared/features/imageable.rb | 261 +----------------- 18 files changed, 16 insertions(+), 510 deletions(-) delete mode 100644 app/views/images/_form.html.erb delete mode 100644 app/views/images/new.html.erb diff --git a/app/assets/stylesheets/mixins.scss b/app/assets/stylesheets/mixins.scss index 89f962eeb..cc8fe9360 100644 --- a/app/assets/stylesheets/mixins.scss +++ b/app/assets/stylesheets/mixins.scss @@ -44,28 +44,6 @@ margin-bottom: $line-height; } - .document-form, - .image-form { - - .title{ - margin-bottom: $line-height; - } - - .document, - .image-form { - .file-name { - margin-top: 0; - } - } - - .document, - .image { - .loading-bar.errors { - margin-top: $line-height * 2; - } - } - } - .document, .image { @@ -107,12 +85,10 @@ &.complete { background-color: $success-color; - width: 100%; } &.errors { background-color: $alert-color; - width: 100%; margin-top: $line-height / 2; } } diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 84e16ebe9..ac4246fe2 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -251,9 +251,7 @@ .spending-proposal-form, .document-form, .topic-new, -.topic-form, -.image-form, -.proposal .image-form { +.topic-form { .icon-debates, .icon-proposals, @@ -306,8 +304,7 @@ .proposal-form, .topic-form, .topic-new, -.document-form, -.image-form { +.document-form { .recommendations li::before { color: $proposals; @@ -317,7 +314,6 @@ .budget-investment-new, .proposal-form, .proposal-edit, -.image-form, .document-form, .new_poll_question, .edit_poll_question { diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 1bfe6e8cd..e273234f2 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -1,24 +1,8 @@ class ImagesController < ApplicationController before_action :authenticate_user! - before_filter :find_imageable, except: :destroy - before_filter :prepare_new_image, only: [:new] - before_filter :prepare_image_for_creation, only: :create load_and_authorize_resource - def new - end - - def create - if @image.save - flash[:notice] = t "images.actions.create.notice" - redirect_to params[:from] - else - flash[:alert] = t "images.actions.create.alert" - render :new - end - end - def destroy respond_to do |format| format.html do @@ -39,25 +23,4 @@ class ImagesController < ApplicationController end end - private - - def image_params - params.require(:image).permit(:title, :imageable_type, :imageable_id, - :attachment, :cached_attachment, :user_id) - end - - def find_imageable - @imageable = params[:imageable_type].constantize.find_or_initialize_by(id: params[:imageable_id]) - end - - def prepare_new_image - @image = Image.new(imageable: @imageable) - end - - def prepare_image_for_creation - @image = Image.new(image_params) - @image.imageable = @imageable - @image.user = current_user - end - end diff --git a/app/helpers/imageables_helper.rb b/app/helpers/imageables_helper.rb index e45302792..b1c8059ce 100644 --- a/app/helpers/imageables_helper.rb +++ b/app/helpers/imageables_helper.rb @@ -1,9 +1,5 @@ module ImageablesHelper - def can_create_image?(imageable) - can?(:create, Image.new(imageable: imageable)) - end - def can_destroy_image?(imageable) imageable.image.present? && can?(:destroy, imageable.image) end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 5f0c849e1..4278d4f8d 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -74,7 +74,7 @@ module Abilities cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation] can [:create, :destroy], Document - can [:create, :destroy], Image + can [:destroy], Image can [:create, :destroy], DirectUpload end end diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index b4248c3b6..64b4c5476 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -39,7 +39,7 @@ module Abilities can [:create, :destroy, :new], Document, documentable: { author_id: user.id } - can [:create, :destroy, :new], Image, imageable: { author_id: user.id } + can [:destroy], Image, imageable: { author_id: user.id } can [:create, :destroy], DirectUpload diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 2e9e24b4f..fbd1ad364 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -10,12 +10,6 @@ class: 'button hollow float-right' %> <% end %> - <% if can_create_image?(investment) %> - <%= link_to t("images.upload_image"), - new_image_path(imageable_id:investment, imageable_type: investment.class.name, from: request.url), - class: 'button hollow float-right' %> - <% end %> - <% if can_destroy_image?(investment) %> <%= link_to t("images.remove_image"), image_path(investment.image, from: request.url), diff --git a/app/views/images/_form.html.erb b/app/views/images/_form.html.erb deleted file mode 100644 index 8f8cd6995..000000000 --- a/app/views/images/_form.html.erb +++ /dev/null @@ -1,65 +0,0 @@ -<%= form_for @image, - url: images_path( - imageable_type: @image.imageable_type, - imageable_id: @image.imageable_id, - from: params[:from] - ), - html: { multipart: true, class: "imageable" } do |f| %> - - <%= render 'shared/errors', resource: @image %> - -
- - <%= f.hidden_field :cached_attachment %> - -
- <%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %> -
- - <%= render_image(@image, :thumb, false) if @image.attachment.exists? %> - -
-
- <%= f.label :attachment, t("images.form.attachment_label"), class: 'button hollow' %> - <%= f.file_field :attachment, - accept: imageable_accepted_content_types_extensions, - label: false, - class: 'js-image-attachment', - data: { - url: direct_uploads_url("direct_upload[resource_type]": @image.imageable_type, - "direct_upload[resource_id]": @image.imageable_id, - "direct_upload[resource_relation]": "image"), - cached_attachment_input_field: "image_cached_attachment", - title_input_field: "image_title" - } %> -
-
- <% if @image.cached_attachment.present? %> - <%= link_to t('images.form.delete_button'), - direct_upload_destroy_url("direct_upload[resource_type]": @image.imageable_type, - "direct_upload[resource_id]": @image.imageable_id, - "direct_upload[resource_relation]": "image", - "direct_upload[cached_attachment]": @image.cached_attachment), - method: :delete, - remote: true, - class: "delete remove-cached-attachment" %> - <% end %> -
-
- -
-

- <%= image_attachment_file_name(@image) %> -

-
- -
-
-
- -
- <%= f.submit(t("images.form.submit_button"), class: "button expanded") %> -
- -
-<% end %> diff --git a/app/views/images/_image.html.erb b/app/views/images/_image.html.erb index ca7a95867..1f2494c01 100644 --- a/app/views/images/_image.html.erb +++ b/app/views/images/_image.html.erb @@ -2,7 +2,8 @@
<%= image_tag image.attachment.url(version), class: image_class(image), - alt: image.title %> + alt: image.title, + title: image.title %> <% if show_caption %>
<%= image.title %> diff --git a/app/views/images/_image_fields.html.erb b/app/views/images/_image_fields.html.erb index d067961d7..10a4cf898 100644 --- a/app/views/images/_image_fields.html.erb +++ b/app/views/images/_image_fields.html.erb @@ -4,7 +4,7 @@ <%= f.hidden_field :cached_attachment %>
- <%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %> + <%= f.text_field :title, placeholder: t("images.form.title_placeholder") %>
<%= render_image(f.object, :thumb, false) if f.object.attachment.exists? %> diff --git a/app/views/images/new.html.erb b/app/views/images/new.html.erb deleted file mode 100644 index 8aef6a6ad..000000000 --- a/app/views/images/new.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -
- -
- -
- <%= back_link_to params[:from] %> -

<%= t("images.new.title") %>

-

<%= image_note(@image) %>

- <%= render "form", form_url: images_url %> -
- -
- -

<%= t("images.recommendations_title") %>

-
    -
  • - <%= image_first_recommendation(@image) %> -
  • -
  • - <%= t "images.recommendation_two_html", - accepted_content_types: imageable_humanized_accepted_content_types %> -
  • -
  • - <%= t "images.recommendation_three_html", - max_file_size: imageable_max_file_size %> -
  • -
-
-
-
diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index ee7ca6f45..f9f3cca7c 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -109,7 +109,7 @@