[Git][noosfero/noosfero][master] 2 commits: api: accepts uploaded_data when create a new article
Victor Costa
gitlab at mg.gitlab.com
Fri Mar 17 18:11:52 BRT 2017
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
8a40c7d7 by Josafá Souza Jr at 2017-03-17T13:22:09-03:00
api: accepts uploaded_data when create a new article
- - - - -
bb2b9f3a by Victor Costa at 2017-03-17T21:11:44+00:00
Merge branch 'ng2-filemanager' into 'master'
accepts uploaded_data when create a new article
See merge request !1138
- - - - -
3 changed files:
- app/api/entities.rb
- app/api/helpers.rb
- test/api/articles_test.rb
Changes:
=====================================
app/api/entities.rb
=====================================
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -231,6 +231,7 @@ module Api
expose :mime_type
expose :size, :if => lambda { |article, options| article.kind_of?(UploadedFile)}
expose :name
+ expose :public_filename, :if => lambda { |article, options| article.kind_of?(UploadedFile)}
end
def self.permissions_for_entity(entity, current_person, *method_names)
=====================================
app/api/helpers.rb
=====================================
--- a/app/api/helpers.rb
+++ b/app/api/helpers.rb
@@ -124,6 +124,10 @@ module Api
klass_type = params[:content_type] || params[:article].delete(:type) || TextArticle.name
return forbidden! unless klass_type.constantize <= Article
+ if params[:article][:uploaded_data].present?
+ params[:article][:uploaded_data] = ActionDispatch::Http::UploadedFile.new(params[:article][:uploaded_data])
+ end
+
article = klass_type.constantize.new(params[:article])
article.last_changed_by = current_person
article.created_by= current_person
=====================================
test/api/articles_test.rb
=====================================
--- a/test/api/articles_test.rb
+++ b/test/api/articles_test.rb
@@ -18,6 +18,15 @@ class ArticlesTest < ActiveSupport::TestCase
assert !Article.exists?(article.id)
end
+ should 'create uploaded file type article' do
+ params['article'] = { name: 'UploadedFileArticle', type: 'UploadedFile', uploaded_data: {path: '/files/rails.png'} }
+ ActionDispatch::Http::UploadedFile.expects(:new).with({'path' => '/files/rails.png'}).returns(fixture_file_upload('/files/rails.png', 'image/png'))
+ post "/api/v1/profiles/#{person.id}/articles?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert json['public_filename'].present?
+ assert Article.find(json['id']).present?
+ end
+
should 'not remove article without permission' do
otherPerson = fast_create(Person, :name => "Other Person")
article = fast_create(Article, :profile_id => otherPerson.id, :name => "Some thing")
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/86acdf46cfc9d44d0d7daa512717cd70d42bd2ee...bb2b9f3a61f57bb94a883aa73628a2193725ded0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170317/83d2ccd3/attachment-0001.html>
More information about the Noosfero-dev
mailing list