[Git][noosfero/noosfero][master] 5 commits: api: accept parent_id=nil to search for top level articles
Victor Costa
gitlab at mg.gitlab.com
Wed Mar 15 19:56:42 BRT 2017
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
9a65d7e7 by Evandro Junior at 2017-03-15T09:12:28-03:00
api: accept parent_id=nil to search for top level articles
- - - - -
e3e96a97 by Evandro Junior at 2017-03-15T09:59:31-03:00
Set mime/type for folders
- - - - -
93e86931 by Evandro Junior at 2017-03-15T09:59:32-03:00
Exposing Article fields
- - - - -
ea626120 by Victor Costa at 2017-03-15T13:28:26-03:00
delivery_plugin: enable dependent plugin
- - - - -
df741d0d by Victor Costa at 2017-03-15T22:56:35+00:00
Merge branch 'ng2-filemanager' into 'master'
Improvements for articles endpoint
See merge request !1136
- - - - -
5 changed files:
- app/api/entities.rb
- app/api/helpers.rb
- app/models/folder.rb
- + plugins/delivery/install.rb
- test/api/helpers_test.rb
Changes:
=====================================
app/api/entities.rb
=====================================
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -228,6 +228,9 @@ module Api
expose :comments, using: CommentBase, :if => lambda{|comment,options| Entities.expose_optional_field?(:comments, options)}
expose :published
expose :accept_comments?, as: :accept_comments
+ expose :mime_type
+ expose :size, :if => lambda { |article, options| article.kind_of?(UploadedFile)}
+ expose :name
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
@@ -107,6 +107,11 @@ module Api
end
end
+ def parse_parent_id(parent_id)
+ return nil if parent_id.blank?
+ parent_id
+ end
+
def find_article(articles, params)
conditions = make_conditions_with_parameter(params, Article)
article = articles.find_by(conditions)
@@ -226,13 +231,18 @@ module Api
end
def make_conditions_with_parameter(params = {}, class_type = nil)
+
parsed_params = class_type.nil? ? parser_params(params) : parser_params_by_type(class_type, params)
conditions = {}
from_date = DateTime.parse(parsed_params.delete(:from)) if parsed_params[:from]
until_date = DateTime.parse(parsed_params.delete(:until)) if parsed_params[:until]
+
conditions[:type] = parse_content_type(parsed_params.delete(:content_type)) unless parsed_params[:content_type].nil?
conditions[:created_at] = period(from_date, until_date) if from_date || until_date
+
+ conditions[:parent_id] = parse_parent_id(parsed_params.delete(:parent_id)) if parsed_params.key? :parent_id
+
conditions.merge!(parsed_params)
conditions
=====================================
app/models/folder.rb
=====================================
--- a/app/models/folder.rb
+++ b/app/models/folder.rb
@@ -67,4 +67,8 @@ class Folder < Article
!self.has_posts? || self.gallery?
end
+ def mime_type
+ 'application/folder'
+ end
+
end
=====================================
plugins/delivery/install.rb
=====================================
--- /dev/null
+++ b/plugins/delivery/install.rb
@@ -0,0 +1,2 @@
+system "script/noosfero-plugins -q enable orders"
+exit $?.exitstatus
=====================================
test/api/helpers_test.rb
=====================================
--- a/test/api/helpers_test.rb
+++ b/test/api/helpers_test.rb
@@ -256,6 +256,14 @@ class Api::HelpersTest < ActiveSupport::TestCase
assert asset_params[:image_builder][:uploaded_data].is_a? ActionDispatch::Http::UploadedFile
end
+ should 'parse_parent_id return nil' do
+ assert_nil parse_parent_id("")
+ end
+
+ should 'parse_parent_id return number' do
+ assert 2, parse_parent_id(2)
+ end
+
protected
def error!(info, status)
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/b178c48bebc3f986078ea2be5efd22647a5c802d...df741d0d1cd86ff6ea12f07848ca9ed519e7c709
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170315/3d6cc28a/attachment-0001.html>
More information about the Noosfero-dev
mailing list