2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2016-11-01 16:16:04 +00:00
|
|
|
|
|
|
|
class ApplicationsController < ApplicationController
|
2020-03-19 09:39:51 +00:00
|
|
|
prepend_before_action { authentication_check && authorize! }
|
2016-11-01 16:16:04 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
all = Doorkeeper::Application.all
|
2017-12-14 13:19:24 +00:00
|
|
|
if response_full?
|
2016-11-01 16:16:04 +00:00
|
|
|
assets = {}
|
|
|
|
item_ids = []
|
2017-10-01 12:25:52 +00:00
|
|
|
all.each do |item|
|
2016-11-01 16:16:04 +00:00
|
|
|
item_ids.push item.id
|
|
|
|
if !assets[:Application]
|
|
|
|
assets[:Application] = {}
|
|
|
|
end
|
2016-11-13 21:16:17 +00:00
|
|
|
application = item.attributes
|
|
|
|
application[:clients] = Doorkeeper::AccessToken.where(application_id: item.id).count
|
|
|
|
assets[:Application][item.id] = application
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-11-01 16:16:04 +00:00
|
|
|
render json: {
|
|
|
|
record_ids: item_ids,
|
2018-12-19 17:31:51 +00:00
|
|
|
assets: assets,
|
2016-11-01 16:16:04 +00:00
|
|
|
}, status: :ok
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
render json: all, status: :ok
|
|
|
|
end
|
|
|
|
|
2016-11-13 21:16:17 +00:00
|
|
|
def token
|
|
|
|
access_token = Doorkeeper::AccessToken.create!(application_id: params[:id], resource_owner_id: current_user.id)
|
|
|
|
render json: { token: access_token.token }, status: :ok
|
|
|
|
end
|
|
|
|
|
2016-11-01 16:16:04 +00:00
|
|
|
def show
|
|
|
|
application = Doorkeeper::Application.find(params[:id])
|
|
|
|
render json: application, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
application = Doorkeeper::Application.new(clean_params)
|
|
|
|
application.save!
|
|
|
|
render json: application, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
application = Doorkeeper::Application.find(params[:id])
|
2017-09-11 11:16:08 +00:00
|
|
|
application.update!(clean_params)
|
2016-11-01 16:16:04 +00:00
|
|
|
render json: application, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
application = Doorkeeper::Application.find(params[:id])
|
|
|
|
application.destroy!
|
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def clean_params
|
2017-09-08 08:28:34 +00:00
|
|
|
params_data = params.permit!.to_h
|
2016-11-01 16:16:04 +00:00
|
|
|
params_data.delete('application')
|
|
|
|
params_data.delete('action')
|
|
|
|
params_data.delete('controller')
|
|
|
|
params_data.delete('id')
|
|
|
|
params_data.delete('uid')
|
|
|
|
params_data.delete('secret')
|
|
|
|
params_data.delete('created_at')
|
2016-11-13 21:16:17 +00:00
|
|
|
params_data.delete('updated_at')
|
2016-11-01 16:16:04 +00:00
|
|
|
params_data
|
|
|
|
end
|
|
|
|
end
|