fix some bug pick 2ea0c6e3 add: remove public key from api
This commit is contained in:
parent
0db334217e
commit
fcc7736c34
|
@ -18,11 +18,11 @@ class PublicKeysController < ApplicationController
|
||||||
if @gitea_response[0] == 201
|
if @gitea_response[0] == 201
|
||||||
@public_key = @gitea_response[2]
|
@public_key = @gitea_response[2]
|
||||||
else
|
else
|
||||||
return render_error("创建ssh key失败") if @gitea_response[2]["message"].nil?
|
return render_error("创建ssh key失败") if @gitea_response[2].blank?
|
||||||
return render_ok({status: 10002, message: "密钥格式不正确"}) if @gitea_response[2]["message"].starts_with?("Invalid key content")
|
return render_ok({status: 10002, message: "密钥格式不正确"}) if @gitea_response[2]["message"].starts_with?("Invalid key content")
|
||||||
exist_public_key = Gitea::PublicKey.find_by(content: public_key_params[:key])
|
exist_public_key = Gitea::PublicKey.find_by(content: public_key_params[:key])
|
||||||
return render_ok({status: 10002, message: "密钥已存在,请勿重复添加"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key") && exist_public_key.owner_id == current_user.gitea_uid
|
return render_ok({status: 10002, message: "密钥已被占用"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key") && exist_public_key.present? && exist_public_key&.owner_id != current_user.gitea_uid
|
||||||
return render_ok({status: 10002, message: "密钥已被占用"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key") && exist_public_key.present?
|
return render_ok({status: 10002, message: "密钥已存在,请勿重复添加"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key")
|
||||||
@public_key = nil
|
@public_key = nil
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
if @public_key.present?
|
||||||
|
json.status 0
|
||||||
json.id @public_key["id"]
|
json.id @public_key["id"]
|
||||||
json.name @public_key["title"]
|
json.name @public_key["title"]
|
||||||
json.content @public_key["key"]
|
json.content @public_key["key"]
|
||||||
json.fingerprint @public_key["fingerprint"]
|
json.fingerprint @public_key["fingerprint"]
|
||||||
json.created_time @public_key["created_at"].to_time.strftime("%Y/%m/%d %H:%M")
|
json.created_time @public_key["created_at"].to_time.strftime("%Y/%m/%d %H:%M")
|
||||||
|
end
|
Loading…
Reference in New Issue