区块确权项目查询token

This commit is contained in:
xxq250 2024-09-12 11:51:09 +08:00
parent a18bc247bb
commit 6a87765f3d
2 changed files with 69 additions and 43 deletions

View File

@ -125,11 +125,13 @@ class Project < ApplicationRecord
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
has_one :project_detail, dependent: :destroy has_one :project_detail, dependent: :destroy
has_many :apply_signatures, dependent: :destroy
has_many :project_units, dependent: :destroy has_many :project_units, dependent: :destroy
has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy
has_many :pinned_projects, dependent: :destroy has_many :pinned_projects, dependent: :destroy
has_many :has_pinned_users, through: :pinned_projects, source: :owner has_many :has_pinned_users, through: :pinned_projects, source: :owner
has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id
#has_many :user_trace_tasks, dependent: :destroy
has_many :user_trace_tasks, dependent: :destroy has_many :user_trace_tasks, dependent: :destroy
has_many :project_invite_links, dependent: :destroy has_many :project_invite_links, dependent: :destroy
has_many :project_topic_ralates, dependent: :destroy has_many :project_topic_ralates, dependent: :destroy
@ -138,7 +140,6 @@ class Project < ApplicationRecord
has_many :daily_project_statistics, dependent: :destroy has_many :daily_project_statistics, dependent: :destroy
has_one :project_dataset, dependent: :destroy has_one :project_dataset, dependent: :destroy
has_many :sync_repositories, dependent: :destroy has_many :sync_repositories, dependent: :destroy
has_many :home_top_settings, as: :top, dependent: :destroy
after_create :incre_user_statistic, :incre_platform_statistic after_create :incre_user_statistic, :incre_platform_statistic
after_save :check_project_members after_save :check_project_members
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data
@ -149,6 +150,12 @@ class Project < ApplicationRecord
scope :recommend, -> { visible.project_statics_select.where(recommend: true) } scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
scope :pinned, -> {where(is_pinned: true)} scope :pinned, -> {where(is_pinned: true)}
scope :like, lambda { |keywords|
# 表情处理
keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
sql = "name LIKE :search OR identifier LIKE :search"
where(sql, :search => "%#{keywords.strip}%") unless keywords.blank?
}
delegate :content, to: :project_detail, allow_nil: true delegate :content, to: :project_detail, allow_nil: true
delegate :name, to: :license, prefix: true, allow_nil: true delegate :name, to: :license, prefix: true, allow_nil: true
@ -245,11 +252,11 @@ class Project < ApplicationRecord
def set_recommend_and_is_pinned def set_recommend_and_is_pinned
self.recommend = self.recommend_index.zero? ? false : true self.recommend = self.recommend_index.zero? ? false : true
# 私有项目不允许设置精选和推荐 # 私有项目不允许设置精选和推荐
unless self.is_public # unless self.is_public
self.recommend = false # self.recommend = false
self.recommend_index = 0 # self.recommend_index = 0
self.is_pinned = false # self.is_pinned = false
end # end
end end
def self.search_project(search) def self.search_project(search)
@ -393,6 +400,8 @@ class Project < ApplicationRecord
user = Owner.find_by_login namespace_path user = Owner.find_by_login namespace_path
user = User.new(login: namespace_path) if user.nil? user = User.new(login: namespace_path) if user.nil?
project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}")
user = User.new(login: namespace_path) if user.nil?
if identifier.end_with?('.json') if identifier.end_with?('.json')
project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}")
identifier = identifier.sub(/.*\K.json/, '') identifier = identifier.sub(/.*\K.json/, '')
@ -458,17 +467,14 @@ class Project < ApplicationRecord
$redis_cache.hdel("issue_cache_delete_count", self.id) $redis_cache.hdel("issue_cache_delete_count", self.id)
end end
def open_portrait def actionable
EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false return false if EduSetting.get("project_user_actionable").nil?
return EduSetting.get("project_user_actionable").split(",").include?(self.owner&.login)
end end
def has_pull_request(branch_name) def is_need_apply
return true if self.pull_requests.opening.where(head: branch_name).present? || self.pull_requests.opening.where(base: branch_name).present? return false if EduSetting.get("project_need_apply").nil?
if self.forked_from_project_id.present? return EduSetting.get("project_need_apply").split(",").include?(self.id.to_s)
return true if self.fork_project.pull_requests.opening.where(head: branch_name).present? || self.fork_project.pull_requests.opening.where(base: branch_name).present?
end
return false
end end
def self.mindspore_contributors def self.mindspore_contributors
@ -501,6 +507,11 @@ class Project < ApplicationRecord
return JSON.parse(cache_result) return JSON.parse(cache_result)
end end
end end
def full_url
Rails.application.config_for(:configuration)['platform_url'].to_s + '/' + self.owner&.try(:login).to_s + '/' + self.identifier.to_s
end
def to_builder def to_builder
Jbuilder.new do |project| Jbuilder.new do |project|
project.id self.id project.id self.id

View File

@ -9,24 +9,39 @@ class Blockchain::BalanceQuery < ApplicationQuery
def call def call
if is_current_admin_user if is_current_admin_user
token_list, total_count = find_repo_with_token(params["user_id"], (params["page"] || 1), (params["limit"] || 10))
result_list = [] result_list = []
token_list.each do |t| if params[:project_id].present? or params[:keyword].present?
project = Project.find_by(id: t['token_name'].to_i) project_ids = params[:project_id].present? ? [params[:project_id]] : Project.where(user_id: params["user_id"]).like(params[:keyword]).ids
if project.nil? project_ids.each do |project_id|
result_list << {project: nil, balance: t['balance']} project_balance = find_one_balance(params["user_id"], project_id)
next project = Project.find_by(id: project_balance['token_name'].to_i)
if project.present?
owner = User.find_by(id: project.user_id)
if owner.present?
result_list << {project: project, balance: project_balance['balance']}
end
end
end end
owner = User.find_by(id: project.user_id) {"status": 0, "projects": result_list, "total_count": result_list.size}
if owner.nil? || project.nil? else
else token_list, total_count = find_repo_with_token(params["user_id"], (params["page"] || 1), (params["limit"] || 10))
balance = t['balance'] token_list.each do |t|
result_list << {project: project, balance: balance} project = Project.find_by(id: t['token_name'].to_i)
if project.nil?
result_list << {project: nil, balance: t['balance']}
next
end
owner = User.find_by(id: project.user_id)
if owner.nil? || project.nil?
else
balance = t['balance']
result_list << {project: project, balance: balance}
end
end end
{"status": 0, "projects": result_list, "total_count": total_count}
end end
results = {"status": 0, "projects": result_list, "total_count": total_count}
else else
results = {"status": 1} # query failed {"status": 1} # query failed
end end
end end
end end