区块确权项目查询token
This commit is contained in:
parent
a18bc247bb
commit
6a87765f3d
|
@ -125,20 +125,21 @@ class Project < ApplicationRecord
|
|||
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
|
||||
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
||||
has_one :project_detail, dependent: :destroy
|
||||
has_many :apply_signatures, dependent: :destroy
|
||||
has_many :project_units, dependent: :destroy
|
||||
has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy
|
||||
has_many :pinned_projects, dependent: :destroy
|
||||
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 :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_topic_ralates, dependent: :destroy
|
||||
has_many :project_topic_ralates, dependent: :destroy
|
||||
has_many :project_topics, through: :project_topic_ralates
|
||||
has_many :commit_logs, dependent: :destroy
|
||||
has_many :daily_project_statistics, dependent: :destroy
|
||||
has_one :project_dataset, 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_save :check_project_members
|
||||
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 :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 :name, to: :license, prefix: true, allow_nil: true
|
||||
|
||||
|
@ -245,11 +252,11 @@ class Project < ApplicationRecord
|
|||
def set_recommend_and_is_pinned
|
||||
self.recommend = self.recommend_index.zero? ? false : true
|
||||
# 私有项目不允许设置精选和推荐
|
||||
unless self.is_public
|
||||
self.recommend = false
|
||||
self.recommend_index = 0
|
||||
self.is_pinned = false
|
||||
end
|
||||
# unless self.is_public
|
||||
# self.recommend = false
|
||||
# self.recommend_index = 0
|
||||
# self.is_pinned = false
|
||||
# end
|
||||
end
|
||||
|
||||
def self.search_project(search)
|
||||
|
@ -393,11 +400,13 @@ class Project < ApplicationRecord
|
|||
|
||||
user = Owner.find_by_login namespace_path
|
||||
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')
|
||||
project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}")
|
||||
identifier = identifier.sub(/.*\K.json/, '')
|
||||
project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}")
|
||||
else
|
||||
else
|
||||
project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}")
|
||||
end
|
||||
return nil if project.blank?
|
||||
|
@ -444,36 +453,33 @@ class Project < ApplicationRecord
|
|||
end
|
||||
|
||||
def get_last_project_issues_index
|
||||
last_issue = self.issues.issue_issue.last
|
||||
last_issue = self.issues.issue_issue.last
|
||||
deleted_issue_count = ($redis_cache.hget("issue_cache_delete_count", self.id) || 0).to_i
|
||||
|
||||
last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 0
|
||||
end
|
||||
|
||||
def incre_project_issue_cache_delete_count(count=1)
|
||||
$redis_cache.hincrby("issue_cache_delete_count", self.id, count)
|
||||
$redis_cache.hincrby("issue_cache_delete_count", self.id, count)
|
||||
end
|
||||
|
||||
def del_project_issue_cache_delete_count
|
||||
$redis_cache.hdel("issue_cache_delete_count", self.id)
|
||||
$redis_cache.hdel("issue_cache_delete_count", self.id)
|
||||
end
|
||||
|
||||
def open_portrait
|
||||
EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false
|
||||
def actionable
|
||||
return false if EduSetting.get("project_user_actionable").nil?
|
||||
return EduSetting.get("project_user_actionable").split(",").include?(self.owner&.login)
|
||||
end
|
||||
|
||||
def has_pull_request(branch_name)
|
||||
return true if self.pull_requests.opening.where(head: branch_name).present? || self.pull_requests.opening.where(base: branch_name).present?
|
||||
if self.forked_from_project_id.present?
|
||||
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
|
||||
def is_need_apply
|
||||
return false if EduSetting.get("project_need_apply").nil?
|
||||
return EduSetting.get("project_need_apply").split(",").include?(self.id.to_s)
|
||||
end
|
||||
|
||||
def self.mindspore_contributors
|
||||
def self.mindspore_contributors
|
||||
cache_result = $redis_cache.get("ProjectMindsporeContributors")
|
||||
if cache_result.nil?
|
||||
if cache_result.nil?
|
||||
contributors = []
|
||||
file = File.open('public/mindspore_authors', 'r')
|
||||
file.each_line do |l|
|
||||
|
@ -481,12 +487,12 @@ class Project < ApplicationRecord
|
|||
email = itemArray[0]
|
||||
username = itemArray[1]
|
||||
commits = itemArray[2].to_i
|
||||
user = User.find_by(login: username, mail: email)
|
||||
user = User.find_by(login: username) if user.nil?
|
||||
user = User.find_by(login: username, mail: email)
|
||||
user = User.find_by(login: username) if user.nil?
|
||||
user = User.find_by(mail: email) if user.nil?
|
||||
# next if user.nil?
|
||||
search_contributor = contributors.select{|con| con["id"]==user.id}[0]
|
||||
if search_contributor.present?
|
||||
if search_contributor.present?
|
||||
search_contributor["contributions"] += commits
|
||||
else
|
||||
contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys
|
||||
|
@ -497,10 +503,15 @@ class Project < ApplicationRecord
|
|||
$redis_cache.set("ProjectMindsporeContributors", contributors.to_json)
|
||||
|
||||
return contributors
|
||||
else
|
||||
else
|
||||
return JSON.parse(cache_result)
|
||||
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
|
||||
Jbuilder.new do |project|
|
||||
project.id self.id
|
||||
|
@ -509,9 +520,9 @@ class Project < ApplicationRecord
|
|||
project.description Nokogiri::HTML(self.description).text
|
||||
project.visits self.visits
|
||||
project.praises_count self.praises_count.to_i
|
||||
project.watchers_count self.watchers_count.to_i
|
||||
project.issues_count self.issues_count.to_i
|
||||
project.pull_requests_count self.pull_requests_count.to_i
|
||||
project.watchers_count self.watchers_count.to_i
|
||||
project.issues_count self.issues_count.to_i
|
||||
project.pull_requests_count self.pull_requests_count.to_i
|
||||
project.forked_count self.forked_count.to_i
|
||||
project.is_public self.is_public
|
||||
project.mirror_url self.repository&.mirror_url
|
||||
|
|
|
@ -9,24 +9,39 @@ class Blockchain::BalanceQuery < ApplicationQuery
|
|||
|
||||
def call
|
||||
if is_current_admin_user
|
||||
token_list, total_count = find_repo_with_token(params["user_id"], (params["page"] || 1), (params["limit"] || 10))
|
||||
result_list = []
|
||||
token_list.each do |t|
|
||||
project = Project.find_by(id: t['token_name'].to_i)
|
||||
if project.nil?
|
||||
result_list << {project: nil, balance: t['balance']}
|
||||
next
|
||||
if params[:project_id].present? or params[:keyword].present?
|
||||
project_ids = params[:project_id].present? ? [params[:project_id]] : Project.where(user_id: params["user_id"]).like(params[:keyword]).ids
|
||||
project_ids.each do |project_id|
|
||||
project_balance = find_one_balance(params["user_id"], project_id)
|
||||
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
|
||||
owner = User.find_by(id: project.user_id)
|
||||
if owner.nil? || project.nil?
|
||||
else
|
||||
balance = t['balance']
|
||||
result_list << {project: project, balance: balance}
|
||||
{"status": 0, "projects": result_list, "total_count": result_list.size}
|
||||
else
|
||||
token_list, total_count = find_repo_with_token(params["user_id"], (params["page"] || 1), (params["limit"] || 10))
|
||||
token_list.each do |t|
|
||||
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
|
||||
{"status": 0, "projects": result_list, "total_count": total_count}
|
||||
end
|
||||
results = {"status": 0, "projects": result_list, "total_count": total_count}
|
||||
else
|
||||
results = {"status": 1} # query failed
|
||||
{"status": 1} # query failed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue