From 2244f55629572c764fb12f74cb69100e8e3e96a4 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Mon, 14 Jul 2014 15:16:32 +0300 Subject: [PATCH 1/3] add necessary validations for event_attachment --- app/models/event_attachment.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/event_attachment.rb b/app/models/event_attachment.rb index e90e0f23..4db6ea60 100644 --- a/app/models/event_attachment.rb +++ b/app/models/event_attachment.rb @@ -6,6 +6,7 @@ class EventAttachment < ActiveRecord::Base has_attached_file :attachment, :path => ":rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension" include Rails.application.routes.url_helpers + do_not_validate_attachment_file_type :attachment def to_jq_upload { From 1d4ec06bacaa9251d566d0ce411d85b5a7c19ac6 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Tue, 15 Jul 2014 10:23:56 +0300 Subject: [PATCH 2/3] fixes for event attachment --- app/controllers/event_attachments_controller.rb | 8 ++++---- app/views/proposal/_form.html.haml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index a7e63b47..93632c05 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -71,7 +71,7 @@ class EventAttachmentsController < ApplicationController :content_type => 'text/html', :layout => false } - format.json { render json: [@upload.to_jq_upload].to_json, status: :created, + format.json { render json: {files: [@upload.to_jq_upload]}, status: :created, location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload) } else format.html { render action: "new" } @@ -97,13 +97,13 @@ class EventAttachmentsController < ApplicationController def destroy @proposal = Event.find(params[:proposal_id]) - + if organizer_or_admin? || current_user == @proposal.submitter @upload = @proposal.event_attachments.find(params[:id]) end - + @upload.destroy if !@upload.nil? - + respond_to do |format| format.html { redirect_back_or_to conference_proposal_index_path(@conference.short_title), :notice => "Deleted successfully attachment '#{@upload.title}' for proposal '#{@proposal.title}'" } diff --git a/app/views/proposal/_form.html.haml b/app/views/proposal/_form.html.haml index e8c8d17d..0e88e38a 100644 --- a/app/views/proposal/_form.html.haml +++ b/app/views/proposal/_form.html.haml @@ -45,7 +45,7 @@ data.formData = inputs.serializeArray(); }); $.getJSON($('#fileupload').prop('action'), function (files) { - var fu = $('#fileupload').data('fileupload'), + var fu = $('#fileupload').data('blueimpFileupload'), template; fu._adjustMaxNumberOfFiles(-files.length); template = fu._renderDownload(files) From 48b9b496555e486c390a950795aa171da7707fd9 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Tue, 15 Jul 2014 10:40:51 +0300 Subject: [PATCH 3/3] style fixes --- .../event_attachments_controller.rb | 26 ++++++++++--------- app/models/event_attachment.rb | 23 +++++++--------- app/views/proposal/_form.html.haml | 6 ++--- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index 93632c05..27b592fb 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -1,15 +1,15 @@ class EventAttachmentsController < ApplicationController before_filter :verify_user - skip_before_filter :verify_user, :only => [:show] + skip_before_filter :verify_user, only: [:show] def index @proposal = Event.find(params[:proposal_id]) @uploads = @proposal.event_attachments - @uploads = @uploads.map{|upload| upload.to_jq_upload } + @uploads = @uploads.map { |upload| upload.to_jq_upload } respond_to do |format| format.html # index.html.erb - format.json { render json: @uploads.to_json} + format.json { render json: @uploads.to_json } end end @@ -53,7 +53,7 @@ class EventAttachmentsController < ApplicationController if !organizer_or_admin? begin event = current_user.events.find(params[:proposal_id]) - rescue Exception => e + rescue => e # They certainly aren't allowed to attach a file to someone else's proposal raise ActionController::RoutingError.new('Invalid proposal') end @@ -67,14 +67,15 @@ class EventAttachmentsController < ApplicationController respond_to do |format| if @upload.save format.html { - render :json => [@upload.to_jq_upload].to_json, - :content_type => 'text/html', - :layout => false + render json: [@upload.to_jq_upload].to_json, + content_type: 'text/html', + layout: false } - format.json { render json: {files: [@upload.to_jq_upload]}, status: :created, - location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload) } + format.json { render json: { files: [@upload.to_jq_upload] }, status: :created, + location: conference_proposal_event_attachment_path( + @upload.event.conference.short_title, @upload.event, @upload) } else - format.html { render action: "new" } + format.html { render action: 'new' } format.json { render json: @upload.errors, status: :unprocessable_entity } end end @@ -89,7 +90,7 @@ class EventAttachmentsController < ApplicationController format.html { redirect_to @upload, notice: 'Upload was successfully updated.' } format.json { head :no_content } else - format.html { render action: "edit" } + format.html { render action: 'edit' } format.json { render json: @upload.errors, status: :unprocessable_entity } end end @@ -106,7 +107,8 @@ class EventAttachmentsController < ApplicationController respond_to do |format| - format.html { redirect_back_or_to conference_proposal_index_path(@conference.short_title), :notice => "Deleted successfully attachment '#{@upload.title}' for proposal '#{@proposal.title}'" } + format.html { redirect_back_or_to conference_proposal_index_path(@conference.short_title), + notice: "Deleted successfully attachment '#{@upload.title}' for proposal '#{@proposal.title}'" } format.json { head :no_content } end diff --git a/app/models/event_attachment.rb b/app/models/event_attachment.rb index 4db6ea60..7a69ed44 100644 --- a/app/models/event_attachment.rb +++ b/app/models/event_attachment.rb @@ -4,27 +4,24 @@ class EventAttachment < ActiveRecord::Base belongs_to :event attr_accessible :public, :attachment, :event_id, :title - has_attached_file :attachment, :path => ":rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension" + has_attached_file :attachment, path: ':rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension' include Rails.application.routes.url_helpers do_not_validate_attachment_file_type :attachment def to_jq_upload { - "name" => read_attribute(:attachment_file_name), - "size" => read_attribute(:attachment_file_size), - "title" => read_attribute(:title), - "public" => read_attribute(:public), - #"url" => attachment.url(:original), - "url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id), - "delete_url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id), - "delete_type" => "DELETE" + 'name' => read_attribute(:attachment_file_name), + 'size' => read_attribute(:attachment_file_size), + 'title' => read_attribute(:title), + 'public' => read_attribute(:public), + # "url" => attachment.url(:original), + 'url' => conference_proposal_event_attachment_path(event.conference.short_title, event_id, id), + 'delete_url' => conference_proposal_event_attachment_path(event.conference.short_title, event_id, id), + 'delete_type' => 'DELETE' } - end #:path => ":rails_root/public/system/:attachment/:id/:style/:filename", # :url => "/system/:attachment/:id/:style/:filename" - #has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"} - - + # has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"} end diff --git a/app/views/proposal/_form.html.haml b/app/views/proposal/_form.html.haml index 0e88e38a..b4aad5bc 100644 --- a/app/views/proposal/_form.html.haml +++ b/app/views/proposal/_form.html.haml @@ -3,14 +3,14 @@ .tabbable %ul.nav.nav-tabs %li.active - = link_to "Proposal", "#proposal-content", "data-toggle"=>"tab" + = link_to 'Proposal', '#proposal-content', 'data-toggle'=>'tab' %li - = link_to "Attachments", "#attachment-content", "data-toggle"=>"tab" + = link_to 'Attachments', '#attachment-content', 'data-toggle'=>'tab' .tab-content #proposal-content.tab-pane.active = render 'proposal/proposal_form' #attachment-content.tab-pane - = form_for EventAttachment.new, :url => conference_proposal_event_attachment_index_path(@conference.short_title, @event), :html => { :multipart => true, :id => "fileupload" } do |f| + = form_for EventAttachment.new, url: conference_proposal_event_attachment_index_path(@conference.short_title, @event), html: { multipart: true, id: 'fileupload' } do |f| %table.table.table-striped %thead %th