123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- class OrganizationsController < ApplicationController
- prepend_before_action -> { authorize! }, except: %i[index show]
- prepend_before_action { authentication_check }
- include CanPaginate
- def index
- model_index_render(policy_scope(Organization), params)
- end
- def show
- begin
- authorize!
- rescue Pundit::NotAuthorizedError
-
-
-
-
- raise if current_user.organization_id
- render json: {}
- return
- end
- if response_expand?
- organization = Organization.find(params[:id]).attributes_with_association_names
- render json: organization, status: :ok
- return
- end
- if response_full?
- full = Organization.full(params[:id])
- render json: full, status: :ok
- return
- end
- model_show_render(Organization, params)
- end
- def create
- model_create_render(Organization, params)
- end
- def update
- model_update_render(Organization, params)
- end
- def destroy
- model_references_check(Organization, params)
- model_destroy_render(Organization, params)
- end
-
- def search
- model_search_render(Organization, params)
- end
-
- def history
-
- organization = Organization.find(params[:id])
-
- render json: organization.history_get(true)
- end
-
-
-
-
-
-
-
-
- def import_example
- send_data(
- Organization.csv_example,
- filename: 'organization-example.csv',
- type: 'text/csv',
- disposition: 'attachment'
- )
- end
-
-
-
-
-
-
-
-
-
- def import_start
- string = params[:data]
- if string.blank? && params[:file].present?
- string = params[:file].read.force_encoding('utf-8')
- end
- raise Exceptions::UnprocessableEntity, __('No source data submitted!') if string.blank?
- result = Organization.csv_import(
- string: string,
- parse_params: {
- col_sep: params[:col_sep] || ',',
- },
- try: params[:try],
- delete: params[:delete],
- )
- render json: result, status: :ok
- end
- end
|