add cancan for authorization
This commit is contained in:
@@ -5,6 +5,15 @@ module Api
|
||||
include ActiveStorage::SetCurrent
|
||||
|
||||
before_action :authenticate_user!
|
||||
check_authorization
|
||||
|
||||
if Rails.env.production?
|
||||
rescue_from CanCan::AccessDenied do |e|
|
||||
Rollbar.error(e) if defined?(Rollbar)
|
||||
|
||||
render json: { error: e.message }, status: :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
module Api
|
||||
class AttachmentsController < ApiBaseController
|
||||
skip_before_action :authenticate_user!
|
||||
skip_authorization_check
|
||||
|
||||
def create
|
||||
submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
||||
|
||||
@@ -5,21 +5,25 @@ module Api
|
||||
UnknownFieldName = Class.new(StandardError)
|
||||
UnknownSubmitterName = Class.new(StandardError)
|
||||
|
||||
def create
|
||||
template = current_account.templates.find(params[:template_id])
|
||||
load_and_authorize_resource :template
|
||||
|
||||
before_action do
|
||||
authorize!(:create, Submission)
|
||||
end
|
||||
|
||||
def create
|
||||
submissions =
|
||||
if (emails = (params[:emails] || params[:email]).presence)
|
||||
Submissions.create_from_emails(template:,
|
||||
Submissions.create_from_emails(template: @template,
|
||||
user: current_user,
|
||||
source: :api,
|
||||
mark_as_sent: params[:send_email] != 'false',
|
||||
emails:)
|
||||
else
|
||||
submissions_attrs = normalize_submissions_params!(submissions_params[:submission], template)
|
||||
submissions_attrs = normalize_submissions_params!(submissions_params[:submission], @template)
|
||||
|
||||
Submissions.create_from_submitters(
|
||||
template:,
|
||||
template: @template,
|
||||
user: current_user,
|
||||
source: :api,
|
||||
mark_as_sent: params[:send_email] != 'false',
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
module Api
|
||||
class SubmitterEmailClicksController < ApiBaseController
|
||||
skip_before_action :authenticate_user!
|
||||
skip_authorization_check
|
||||
|
||||
def create
|
||||
submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
module Api
|
||||
class SubmitterFormViewsController < ApiBaseController
|
||||
skip_before_action :authenticate_user!
|
||||
skip_authorization_check
|
||||
|
||||
def create
|
||||
submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
module Api
|
||||
class TemplatesController < ApiBaseController
|
||||
before_action :load_template, only: %i[show update]
|
||||
load_and_authorize_resource :template
|
||||
|
||||
def index
|
||||
render json: current_account.templates
|
||||
render json: @templates
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -28,9 +28,5 @@ module Api
|
||||
fields: [[:uuid, :submitter_uuid, :name, :type, :required,
|
||||
{ options: [], areas: [%i[x y w h cell_w attachment_uuid page]] }]])
|
||||
end
|
||||
|
||||
def load_template
|
||||
@template = current_account.templates.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
module Api
|
||||
class TemplatesDocumentsController < ApiBaseController
|
||||
load_and_authorize_resource :template
|
||||
|
||||
def create
|
||||
return head :unprocessable_entity if params[:blobs].blank? && params[:files].blank?
|
||||
|
||||
@template = current_account.templates.find(params[:template_id])
|
||||
|
||||
documents = Templates::CreateAttachments.call(@template, params)
|
||||
|
||||
schema = documents.map do |doc|
|
||||
|
||||
Reference in New Issue
Block a user