fix some bug pick 2ea0c6e3 add: remove public key from api

This commit is contained in:
yystopf 2021-07-23 09:56:45 +08:00
parent 0db334217e
commit fcc7736c34
2 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -1,5 +1,8 @@
json.id @public_key["id"] if @public_key.present?
json.name @public_key["title"] json.status 0
json.content @public_key["key"] json.id @public_key["id"]
json.fingerprint @public_key["fingerprint"] json.name @public_key["title"]
json.created_time @public_key["created_at"].to_time.strftime("%Y/%m/%d %H:%M") json.content @public_key["key"]
json.fingerprint @public_key["fingerprint"]
json.created_time @public_key["created_at"].to_time.strftime("%Y/%m/%d %H:%M")
end