[Git][noosfero/noosfero][master] 2 commits: adding new endpoint uploaded file in api

Leandro Nunes gitlab at mg.gitlab.com
Mon Nov 11 11:05:15 BRST 2019



Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
2c7571b1 by Leandro Nunes dos Santos at 2019-11-11T11:56:41Z
adding new endpoint uploaded file in api

- - - - -
1d198d4d by Leandro Nunes at 2019-11-11T13:05:11Z
Merge branch 'add-upload-file-api' into 'master'

adding new endpoint uploaded file in api

See merge request noosfero/noosfero!1752
- - - - -


3 changed files:

- app/api/app.rb
- app/api/helpers.rb
- + app/api/v1/uploaded_files.rb


Changes:

=====================================
app/api/app.rb
=====================================
@@ -53,6 +53,7 @@ module Api
     mount V1::Domains
     mount V1::Settings
     mount V1::Scraps
+    mount V1::UploadedFiles
 
     # hook point which allow plugins to add Grape::API extensions to Api::App
     # finds for plugins which has api mount points classes defined (the class should extends Grape::API)


=====================================
app/api/helpers.rb
=====================================
@@ -37,7 +37,7 @@ module Api
     end
 
     def set_current_user
-      private_token = (params[PRIVATE_TOKEN_PARAM] || headers["Private-Token"]).to_s
+      private_token = (params[PRIVATE_TOKEN_PARAM] || headers["Private-Token"] || headers["Authorization"]).to_s
       @current_user ||= User.where(private_token: private_token).includes(:person).first unless private_token.blank?
       @current_user ||= plugins.dispatch("api_custom_login", request).first
       @current_user = session.user if @current_user.blank? && session.present?


=====================================
app/api/v1/uploaded_files.rb
=====================================
@@ -0,0 +1,32 @@
+module Api
+  module V1
+    class UploadedFiles < Grape::API::Instance
+      resource :profiles do
+        segment "/:id" do
+          resource :uploaded_files do
+            post do
+              authenticate!
+              profile = environment.profiles.visible.find(params[:id])
+
+              return forbidden! unless current_person.can_post_content?(profile)
+
+              data = {
+                uploaded_data: params[:file],
+                profile: profile,
+                author: current_person,
+              }
+
+              article = UploadedFile.new(data)
+              begin
+		article.save!
+                present_partial article, with: Entities::Article
+              rescue ActiveRecord::RecordInvalid
+                render_model_errors!(article.errors)
+              end
+            end
+          end
+        end
+      end
+    end
+  end
+end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/66f5326bc9566978fc4acb225262ff00952535fd...1d198d4d3feee2cce427648223913897b8930a99

-- 
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/66f5326bc9566978fc4acb225262ff00952535fd...1d198d4d3feee2cce427648223913897b8930a99
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20191111/d7841808/attachment-0001.html>


More information about the Noosfero-dev mailing list