Merge branch 'develop' into dev_trustie_server

This commit is contained in:
jasder
2021-06-04 18:51:47 +08:00
54 changed files with 2962 additions and 319 deletions
+19
View File
@@ -196,6 +196,25 @@ class AccountsController < ApplicationController
# session[:user_id] = @user.id
end
def change_password
@user = User.find_by(login: params[:login])
return render_error("未找到相关用户!") if @user.blank?
return render_error("旧密码不正确") unless @user.check_password?(params[:old_password])
sync_params = {
password: params[:password].to_s,
email: @user.mail
}
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
if interactor.success?
@user.update_attribute(:password, params[:password])
render_ok
else
render_error(interactor.error)
end
end
# 忘记密码
def reset_password
begin
+19
View File
@@ -772,7 +772,26 @@ class ApplicationController < ActionController::Base
def base_url
request.base_url
end
def convert_image!
@image = params[:image] || user_params[:image]
return unless @image.present?
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
if @image.class == ActionDispatch::Http::UploadedFile
render_error('请上传文件') if @image.size.zero?
render_error('文件大小超过限制') if @image.size > max_size.to_i
else
image = @image.to_s.strip
return render_error('请上传正确的图片') if image.blank?
@image = Util.convert_base64_image(image, max_size: max_size.to_i)
end
rescue Base64ImageConverter::Error => ex
render_error(ex.message)
end
def avatar_path(object)
ApplicationController.helpers.disk_filename(object.class, object.id)
end
private
def object_not_found
@@ -70,25 +70,6 @@ class Organizations::OrganizationsController < Organizations::BaseController
end
private
def convert_image!
return unless params[:image].present?
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
if params[:image].class == ActionDispatch::Http::UploadedFile
@image = params[:image]
render_error('请上传文件') if @image.size.zero?
render_error('文件大小超过限制') if @image.size > max_size.to_i
else
image = params[:image].to_s.strip
return render_error('请上传正确的图片') if image.blank?
@image = Util.convert_base64_image(image, max_size: max_size.to_i)
end
rescue Base64ImageConverter::Error => ex
render_error(ex.message)
end
def avatar_path(organization)
ApplicationController.helpers.disk_filename(organization.class, organization.id)
end
def organization_params
params.permit(:name, :description, :website, :location,
@@ -0,0 +1,26 @@
class Users::HeadmapsController < Users::BaseController
def index
result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp)
@headmaps = result[2]
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
private
def start_stamp
if params[:year].present?
Date.new(params[:year], 1).to_time.to_i
else
Date.today.to_time.to_i - 365*24*60*60
end
end
def end_stamp
if params[:year].present?
Date.new(params[:year], 1).to_time.to_i + 365*24*60*60
else
Date.today.to_time.to_i
end
end
end
@@ -0,0 +1,45 @@
class Users::IsPinnedProjectsController < Users::BaseController
before_action :private_user_resources!, only: [:pin]
def index
@is_pinned_projects = observed_user.pinned_projects.order(position: :desc, created_at: :asc).includes(project: [:project_category, :project_language, :repository]).order(position: :desc)
@is_pinned_projects = kaminari_paginate(@is_pinned_projects)
end
def pin
observed_user.is_pinned_project_ids = is_pinned_project_ids
render_ok
rescue ActiveRecord::RecordNotFound => e
render_not_found
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def update
@pinned_project = PinnedProject.find_by_id(params[:id])
@pinned_project.attributes = pinned_project_params
if @pinned_project.save
render_ok
else
render_error
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
private
def is_pinned_project_ids
if params[:is_pinned_project_ids].present?
return params[:is_pinned_project_ids].select{|id| observed_user.full_member_projects.visible.pluck(:id).include?(id.to_i) }
end
if params[:is_pinned_project_id].present?
return observed_user.is_pinned_project_ids unless observed_user.full_member_projects.visible.pluck(:id).include?(params[:is_pinned_project_id].to_i)
return observed_user.is_pinned_project_ids.include?(params[:is_pinned_project_id].to_i) ? observed_user.is_pinned_project_ids : observed_user.is_pinned_project_ids.push(params[:is_pinned_project_id].to_i)
end
end
def pinned_project_params
params.require(:pinned_project).permit(:position)
end
end
@@ -0,0 +1,11 @@
class Users::ProjectTrendsController < Users::BaseController
def index
if params[:date].present?
@project_trends = observed_user.project_trends.where("DATE(created_at) = ?", params[:date])
else
@project_trends = observed_user.project_trends
end
@project_trends = kaminari_paginate(@project_trends.includes(:trend, :project).order(created_at: :desc))
end
end
@@ -0,0 +1,190 @@
class Users::StatisticsController < Users::BaseController
before_action :preload_develop_data, only: [:develop]
# 近期活动统计
def activity
date_range = (1.week.ago.to_date..Date.today).to_a
commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.to_time.to_i)
commit_data = commit_request[2]
@date_data = []
@issue_data = []
@pull_request_data = []
@commit_data = []
date_range.each do |date|
@date_data << date.strftime("%Y.%m.%d")
@issue_data << observed_user.issues.where("DATE(created_on) = ?", date).size
@pull_request_data << observed_user.pull_requests.where("DATE(created_at) = ?", date).size
date_commit_data = commit_data.select{|item| item["timestamp"] == date.to_time.to_i}
@commit_data << (date_commit_data.blank? ? 0 : date_commit_data[0]["contributions"].to_i)
end
render :json => {dates: @date_data, issues_count: @issue_data, pull_requests_count: @pull_request_data, commits_count: @commit_data}
end
# 开发能力
def develop
if params[:start_time].present? && params[:end_time].present?
# 影响力
@influence = (60.0 + @follow_count / (@follow_count + 10.0) * 40.0).to_i
@platform_influence = (60.0 + @platform_follow_count / (@platform_follow_count + 10.0) * 40.0).to_i
# 贡献度
@contribution = (60.0 + @pullrequest_count / (@pullrequest_count + 10.0) * 40.0).to_i
@platform_contribution = (60.0 + @platform_pullrequest_count / (@platform_pullrequest_count + 10.0) * 40.0).to_i
# 活跃度
@activity = (60.0 + @issues_count / (@issues_count + 10.0) * 40.0).to_i
@platform_activity = (60.0 + @platform_issues_count / (@platform_issues_count + 10.0) * 40.0).to_i
# 项目经验
@experience = 10 * @project_count + 5 * @fork_count + @project_watchers_count + @project_praises_count
@experience = (60.0 + @experience / (@experience + 100.0) * 40.0).to_i
@platform_experience = 10 * @platform_project_count + 5 * @platform_fork_count + @platform_project_watchers_count + @platform_project_praises_count
@platform_experience = (60.0 + @platform_experience / (@platform_experience + 100.0) * 40.0).to_i
# 语言能力
@language = (60.0 + @project_languages_count.length / (@project_languages_count.length + 5.0) * 40.0).to_i
@platform_language = (60.0 + @platform_project_languages_count.length / (@platform_project_languages_count.length + 5.0) * 40.0).to_i
# 语言百分比
@languages_percent = Hash.new
for key in @project_languages_count.keys do
@languages_percent[key] = (@project_languages_count[key].to_f / @project_languages_count.values.sum).round(2)
end
@platform_languages_percent = Hash.new
for key in @platform_project_languages_count.keys do
@platform_languages_percent[key] = (@platform_project_languages_count[key].to_f / @platform_project_languages_count.values.sum).round(2)
end
# 各门语言分数
@each_language_score = Hash.new
for key in @project_languages_count.keys do
@each_language_score[key] = (60.0 + @project_languages_count[key] / (@project_languages_count[key] + 5.0) * 40.0).to_i
end
@platform_each_language_score = Hash.new
for key in @platform_project_languages_count.keys do
@platform_each_language_score[key] = (60.0 + @platform_project_languages_count[key] / (@platform_project_languages_count[key] + 5.0) * 40.0).to_i
end
else
# 影响力
@influence = (60.0 + @follow_count / (@follow_count + 20.0) * 40.0).to_i
@platform_influence = (60.0 + @platform_follow_count / (@platform_follow_count + 20.0) * 40.0).to_i
# 贡献度
@contribution = (60.0 + @pullrequest_count / (@pullrequest_count + 20.0) * 40.0).to_i
@platform_contribution = (60.0 + @platform_pullrequest_count / (@platform_pullrequest_count + 20.0) * 40.0).to_i
# 活跃度
@activity = (60.0 + @issues_count / (@issues_count + 80.0) * 40.0).to_i
@platform_activity = (60.0 + @platform_issues_count / (@platform_issues_count + 80.0) * 40.0).to_i
# 项目经验
@experience = 10 * @project_count + 5 * @fork_count + @project_watchers_count + @project_praises_count
@experience = (60.0 + @experience / (@experience + 100.0) * 40.0).to_i
@platform_experience = 10 * @platform_project_count + 5 * @platform_fork_count + @platform_project_watchers_count + @platform_project_praises_count
@platform_experience = (60.0 + @platform_experience / (@platform_experience + 100.0) * 40.0).to_i
# 语言能力
@language = (60.0 + @project_languages_count.length / (@project_languages_count.length + 5.0) * 40.0).to_i
@platform_language = (60.0 + @platform_project_languages_count.length / (@platform_project_languages_count.length + 5.0) * 40.0).to_i
# 语言百分比
@languages_percent = Hash.new
for key in @project_languages_count.keys do
@languages_percent[key] = (@project_languages_count[key].to_f / @project_languages_count.values.sum).round(2)
end
@platform_languages_percent = Hash.new
for key in @platform_project_languages_count.keys do
@platform_languages_percent[key] = (@platform_project_languages_count[key].to_f / @platform_project_languages_count.values.sum).round(2)
end
# 各门语言分数
@each_language_score = Hash.new
for key in @project_languages_count.keys do
@each_language_score[key] = (60.0 + @project_languages_count[key] / (@project_languages_count[key] + 5.0) * 40.0).to_i
end
@platform_each_language_score = Hash.new
for key in @platform_project_languages_count.keys do
@platform_each_language_score[key] = (60.0 + @platform_project_languages_count[key] / (@platform_project_languages_count[key] + 5.0) * 40.0).to_i
end
end
end
# 角色定位
def role
full_member_projects = observed_user.full_member_projects
owner_projects = filter_member_projects_by_role("Owner")
manager_projects = filter_member_projects_by_role("Manager").where.not(id: owner_projects.ids)
developer_projects = filter_member_projects_by_role("Developer").where.not(id: owner_projects.ids + manager_projects.ids)
reporter_projects = filter_member_projects_by_role("Reporter").where.not(id: owner_projects.ids + manager_projects.ids + developer_projects.ids)
@full_member_projects_count = full_member_projects.size
@owner_projects_count = owner_projects.size
@manager_projects_count = manager_projects.size
@developer_projects_count = developer_projects.size
@reporter_projects_count = reporter_projects.size
end
# 专业定位
def major
# 参与项目
join_normal_projects_sql = Project.members_projects(observed_user.id).to_sql
join_org_projects_sql = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: observed_user.id}).to_sql
# 关注项目
star_projects_sql = Project.joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observed_user.id}).to_sql
# fork项目
fork_projects_sql = Project.where(id: observed_user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id)).to_sql
major_projects = Project.from("( #{ join_normal_projects_sql} UNION #{ join_org_projects_sql } UNION #{ star_projects_sql } UNION #{fork_projects_sql}) AS projects").distinct
categories = ProjectCategory.joins(:projects).merge(Project.where(id: time_filter(major_projects, 'created_on'))).distinct.pluck(:name)
render :json => {categories: categories}
end
private
def time_filter(collection, time_field)
if params[:start_time].present? && params[:end_time].present?
return collection.where("#{time_field} > ? AND #{time_field} < ?", Time.at(params[:start_time].to_i).beginning_of_day, Time.at(params[:end_time].to_i).end_of_day)
else
return collection
end
rescue
return collection
end
def filter_member_projects_by_role(role)
case role
when 'Owner'
normal_projects_sql = Project.joins(members: :roles).where(user_id: observed_user.id).where(members: {user_id: observed_user.id}, roles: {name: 'Manager'}).to_sql
org_projects_sql = Project.joins(:owner, teams: :team_users).where(users: {type: 'Organization'}, teams: {authorize: "owner"}, team_users: {user_id: observed_user.id}).to_sql
when "Manager"
normal_projects_sql = Project.joins(members: :roles).where.not(user_id: observed_user.id).where(members: {user_id: observed_user.id}, roles: {name: 'Manager'}).to_sql
org_projects_sql = Project.joins(:owner, teams: :team_users).where(users: {type: 'Organization'}, teams: {authorize: "admin"}, team_users: {user_id: observed_user.id}).to_sql
when "Developer"
normal_projects_sql = Project.joins(members: :roles).where.not(user_id: observed_user.id).where(members: {user_id: observed_user.id}, roles: {name: 'Developer'}).to_sql
org_projects_sql = Project.joins(:owner, teams: :team_users).where(users: {type: 'Organization'}, teams: {authorize: "write"}, team_users: {user_id: observed_user.id}).to_sql
when "Reporter"
normal_projects_sql = Project.joins(members: :roles).where.not(user_id: observed_user.id).where(members: {user_id: observed_user.id}, roles: {name: 'Reporter'}).to_sql
org_projects_sql = Project.joins(:owner, teams: :team_users).where(users: {type: 'Organization'}, teams: {authorize: "read"}, team_users: {user_id: observed_user.id}).to_sql
end
return time_filter(Project.from("( #{normal_projects_sql} UNION #{org_projects_sql} ) AS projects").distinct, 'created_on')
end
def preload_develop_data
# 用户被follow数量
@follow_count = time_filter(Watcher.where(watchable: observed_user), 'created_at').count
@platform_follow_count = time_filter(Watcher.where(watchable_type: 'User'), 'created_at').count
# 用户pr数量
@pullrequest_count = time_filter(PullRequest.where(user_id: observed_user.id), 'created_at').count
@platform_pullrequest_count = time_filter(PullRequest, 'created_at').count
# 用户issue数量
@issues_count = time_filter(Issue.where(author_id: observed_user.id), 'created_on').count
@platform_issues_count = time_filter(Issue, 'created_on').count
# 用户总项目数 @fork_count + @project_watchers_count + @project_praises_count
@project_count = filter_member_projects_by_role("Owner").count
@platform_project_count = time_filter(Project, 'created_on').count
# 用户项目被fork数量
@fork_count = filter_member_projects_by_role("Owner").sum("forked_count")
@platform_fork_count = time_filter(Project, 'created_on').sum("forked_count")
# 用户项目关注数
@project_watchers_count = filter_member_projects_by_role("Owner").sum("watchers_count")
@platform_project_watchers_count = time_filter(Project, 'created_on').sum("watchers_count")
# 用户项目点赞数
@project_praises_count = filter_member_projects_by_role("Owner").sum("praises_count")
@platform_project_praises_count = time_filter(Project, 'created_on').sum("praises_count")
# 用户不同语言项目数量
@project_languages_count = filter_member_projects_by_role("Owner").joins(:project_language).group("project_languages.name").count
@platform_project_languages_count = time_filter(Project, 'created_on').joins(:project_language).group("project_languages.name").count
end
end
+12 -5
View File
@@ -6,6 +6,7 @@ class UsersController < ApplicationController
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
before_action :require_login, only: %i[me list sync_user_info]
before_action :connect_to_ci_db, only: [:get_user_info]
before_action :convert_image!, only: [:update]
skip_before_action :check_sign, only: [:attachment_show]
def connect_to_ci_db(options={})
@@ -72,9 +73,13 @@ class UsersController < ApplicationController
end
def update
@user = User.find params[:id]
@user.update!(user_params)
render_ok
return render_not_found unless @user = User.find_by_id(params[:id]) || User.find_by(login: params[:id])
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
@user.attributes = user_params.except(:image)
unless @user.save
render_error(@user.errors.full_messages.join(", "))
end
end
def me
@@ -274,11 +279,13 @@ class UsersController < ApplicationController
end
def user_params
params.require(:user).permit(:nickname, :lastname, :show_realname,:login,:mail,
params.require(:user).permit(:nickname, :image,
user_extension_attributes: [
:gender, :location, :location_city,
:occupation, :technical_title,
:school_id, :department_id,:identity, :student_id, :description]
:school_id, :department_id, :province, :city,
:custom_department, :identity, :student_id, :description,
:show_email, :show_location, :show_department]
)
end
+913 -1
View File
@@ -1,7 +1,7 @@
<!--
* @Date: 2021-03-01 10:35:21
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 10:47:30
* @LastEditTime: 2021-06-03 10:18:53
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
-->
# Users
@@ -47,6 +47,918 @@ await octokit.request('GET /api/users/me.json')
Success Data.
</aside>
## 更改用户信息
更改用户信息
> 示例:
```shell
curl -X PATCH/PUT http://localhost:3000/api/users/yystopf.json
```
```javascript
await octokit.request('PATCH/PUT /api/users/:login.json')
```
### HTTP 请求
`PATCH/PUT /api/users/:login.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|user.nickname |string |用户昵称 |
|user.image |base64/file |用户头像 |
|user.user_extension_attributes.gender |int |性别, 0男 1女 |
|user.user_extension_attributes.province |string |省份 |
|user.user_extension_attributes.city |string |城市 |
|user.user_extension_attributes.description |string |简介 |
|user.user_extension_attributes.custom_department|string |单位名称 |
|user.user_extension_attributes.technical_title |string |职业 |
|user.user_extension_attributes.show_email |bool |是否展示邮箱 |
|user.user_extension_attributes.show_location |bool |是否展示位置 |
|user.user_extension_attributes.show_department |bool |是否展示公司 |
> 请求的JSON示例:
```json
{
"user": {
"nickname": "xxx",
"user_extension_attributes": {
"gender": 0,
"province": "湖南",
"city": "长沙",
"description": "个性签名",
"custom_department": "湖南智擎科技有限公司",
}
}
}
```
> 返回的JSON示例:
```json
{
"status": 0,
"message": "success"
}
```
## 获取用户星标项目
获取用户星标项目
> 示例:
```shell
curl -X GET http://localhost:3000/api/users/yystopf/is_pinned_projects.json
```
```javascript
await octokit.request('GET /api/users/:login/is_pinned_projects.json')
```
### HTTP 请求
`GET api/users/:login/is_pinned_projects.json`
### 返回字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|total_count |int |星标项目数量 |
|identifier |string |项目标识 |
|name |string |项目名称 |
|description |string |项目描述 |
|visits |int |项目访问数量|
|praises_count |int |项目点赞数量|
|watchers_count |int |项目关注数量|
|issues_count |int |项目issue数量|
|pull_requests_count |int |项目合并请求数量|
|forked_count |int |项目复刻数量|
|is_public |bool |项目是否公开|
|mirror_url |string |镜像地址|
|type |int |项目类型 0 普通项目 1 普通镜像项目 2 同步镜像项目|
|time_ago |string |上次更新时间|
|open_devops |int |是否开启devops|
|forked_from_project_id |int |fork项目id|
|platform |string |项目平台|
|author.name |string |项目拥有者名称|
|author.type |string |项目拥有者类型|
|author.login |string |项目拥有者用户名|
|author.image_url |string |项目拥有者头像|
|category.name |string |项目分类名称|
|language.name |string |项目语言名称|
|position |int |项目排序|
> 返回的JSON示例:
```json
{
"total_count": 1,
"projects": [
{
"id": 89,
"repo_id": 89,
"identifier": "monkey",
"name": "boke",
"description": "dkkd",
"visits": 4,
"praises_count": 0,
"watchers_count": 0,
"issues_count": 0,
"pull_requests_count": 0,
"forked_count": 0,
"is_public": true,
"mirror_url": "https://github.com/viletyy/monkey.git",
"type": 1,
"last_update_time": 1619685144,
"time_ago": "27天前",
"forked_from_project_id": null,
"open_devops": false,
"platform": "forge",
"author": {
"name": "测试组织",
"type": "Organization",
"login": "ceshi_org",
"image_url": "images/avatars/Organization/9?t=1612706073"
},
"category": {
"id": 3,
"name": "深度学习"
},
"language": {
"id": 2,
"name": "C"
}
}
]
}
```
<aside class="success">
Success Data.
</aside>
## 用户添加星标项目
用户添加星标项目
> 示例:
```shell
curl -X POST http://localhost:3000/api/users/yystopf/is_pinned_projects/pin.json
```
```javascript
await octokit.request('GET /api/users/:login/is_pinned_projects/pin.json')
```
### HTTP 请求
`POST /api/users/:login/is_pinned_projects/pin.json`
### 请求字段说明:
#### 同时设定多个星标项目
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|is_pinned_project_ids |array |设定为星标项目的id |
#### 只设定一个星标项目
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|is_pinned_project_id |integer |设定为星标项目的id |
> 返回的JSON示例:
```json
{
"status": 0,
"message": "success"
}
```
## 星标项目展示排序
星标项目展示排序
> 示例:
```shell
curl -X PATCH http://localhost:3000/api/users/yystopf/is_pinned_projects/11.json
```
```javascript
await octokit.request('PATCH/PUT /api/users/:login/is_pinned_projects/:id.json')
```
### HTTP 请求
`PATCH/PUT /api/users/:login/is_pinned_projects/:id.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|pinned_projects.position |int |排序,数字越大排名越前 |
> 请求的JSON示例:
```json
{
"pinned_project": {
"position": 1
}
}
```
> 返回的JSON示例:
```json
{
"status": 0,
"message": "success"
}
```
## 用户近期活动统计
用户近期活动统计, 默认显示近一周的数据
> 示例:
```shell
curl -X GET http://localhost:3000/api/users/yystopf/statistics/activity.json
```
```javascript
await octokit.request('GET /api/users/:login/statistics/activity.json')
```
### HTTP 请求
`GET /api/users/:login/statistics/activity.json`
### 返回字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|dates |array |时间 |
|issues_count |array |易修数量|
|pull_requests_count |array |合并请求数量|
|commtis_count |array |贡献数量|
> 返回的JSON示例:
```json
{
"dates": [
"2021.05.21",
"2021.05.22",
"2021.05.23",
"2021.05.24",
"2021.05.25",
"2021.05.26",
"2021.05.27",
"2021.05.28"
],
"issues_count": [
0,
0,
0,
0,
0,
0,
0,
0
],
"pull_requests_count": [
0,
0,
0,
0,
0,
0,
0,
0
],
"commits_count": [
0,
0,
0,
0,
0,
0,
0,
0
]
}
```
<aside class="success">
Success Data.
</aside>
## 获取用户贡献度
获取用户贡献度
> 示例:
```shell
curl -X GET http://localhost:3000/api/users/yystopf/headmaps.json
```
```javascript
await octokit.request('GET /api/users/:login/headmaps.json')
```
### HTTP 请求
`GET api/users/:login/headmaps.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|year |string |年份 |
### 返回字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|total_contributions |int |所选时间内的总贡献度 |
|headmaps.date |string|时间|
|headmaps.contributions |int|贡献度|
> 返回的JSON示例:
```json
{
"total_contributions": 139,
"headmaps": [
{
"date": "2021-02-07",
"contributions": 1
},
{
"date": "2021-02-21",
"contributions": 13
},
{
"date": "2021-02-25",
"contributions": 5
},
{
"date": "2021-03-01",
"contributions": 2
},
{
"date": "2021-03-04",
"contributions": 1
},
{
"date": "2021-03-15",
"contributions": 9
},
{
"date": "2021-03-22",
"contributions": 14
},
{
"date": "2021-03-24",
"contributions": 1
},
{
"date": "2021-03-30",
"contributions": 11
},
{
"date": "2021-04-06",
"contributions": 1
},
{
"date": "2021-04-12",
"contributions": 1
},
{
"date": "2021-04-13",
"contributions": 2
},
{
"date": "2021-04-19",
"contributions": 3
},
{
"date": "2021-04-23",
"contributions": 37
},
{
"date": "2021-04-25",
"contributions": 2
},
{
"date": "2021-04-26",
"contributions": 6
},
{
"date": "2021-04-28",
"contributions": 1
},
{
"date": "2021-04-29",
"contributions": 18
},
{
"date": "2021-04-30",
"contributions": 9
},
{
"date": "2021-05-04",
"contributions": 1
},
{
"date": "2021-05-06",
"contributions": 1
}
]
}
```
<aside class="success">
Success Data.
</aside>
## 获取用户动态
获取用户动态
> 示例:
```shell
curl -X GET http://localhost:3000/api/users/yystopf/project_trends.json
```
```javascript
await octokit.request('GET /api/users/:login/project_trends.json')
```
### HTTP 请求
`GET api/users/:login/project_trends.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|date |string |日期,格式: 2021-05-28 |
### 返回字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|total_count |int |所选时间内的总动态数 |
|project_trends.trend_type |string|动态类型,Issue:易修,VersionRelease:版本发布,PullRequest:合并请求|
|project_trends.action_type |string|操作类型|
|project_trends.trend_id |integer|动态id|
|project_trends.user_name |string|用户名称|
|project_trends.user_login |string|用户用户名|
|project_trends.user_avatar |string|用户头像|
|project_trends.action_time |string|操作时间|
|project_trends.name |string|动态标题|
> 返回的JSON示例:
```json
{
"total_count": 16,
"project_trends": [
{
"id": 27,
"trend_type": "Issue",
"action_type": "创建了工单",
"trend_id": 18,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "21天前",
"name": "31213123123",
"issue_type": "1",
"status_id": 2,
"priority_id": 4,
"created_at": "2021-05-07 15:39",
"updated_at": "2021-05-27 15:42",
"assign_user_name": "yystopf",
"assign_user_login": "yystopf",
"issue_journal_size": 1,
"issue_journals": []
},
{
"id": 8,
"trend_type": "VersionRelease",
"action_type": "创建了版本发布",
"trend_id": 8,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "24天前",
"name": "heihei1",
"tag_name": "v1.0",
"target_commitish": "master",
"tarball_url": "http://localhost:10080/forgeceshiorg1/ceshi1/archive/v1.0.tar.gz",
"zipball_url": "http://localhost:10080/forgeceshiorg1/ceshi1/archive/v1.0.zip",
"url": "http://localhost:10080/api/v1/repos/forgeceshiorg1/ceshi1/releases/84",
"version_gid": "84",
"created_at": "2021-05-04 12:04"
},
{
"id": 25,
"trend_type": "PullRequest",
"action_type": "关闭了合并请求",
"trend_id": 14,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "28天前",
"name": "13",
"created_at": "2021-04-30 15:39"
},
{
"id": 24,
"trend_type": "PullRequest",
"action_type": "创建了合并请求",
"trend_id": 13,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "28天前",
"name": "211212",
"created_at": "2021-04-30 15:37"
},
{
"id": 23,
"trend_type": "PullRequest",
"action_type": "创建了合并请求",
"trend_id": 12,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "28天前",
"name": "奇偶哦iu",
"created_at": "2021-04-30 10:19"
},
{
"id": 22,
"trend_type": "PullRequest",
"action_type": "创建了合并请求",
"trend_id": 11,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "28天前",
"name": "2112123",
"created_at": "2021-04-29 18:46"
},
{
"id": 21,
"trend_type": "PullRequest",
"action_type": "关闭了合并请求",
"trend_id": 10,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "28天前",
"name": "23123",
"created_at": "2021-04-29 18:45"
},
{
"id": 20,
"trend_type": "PullRequest",
"action_type": "创建了合并请求",
"trend_id": 9,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "28天前",
"name": "33",
"created_at": "2021-04-29 18:37"
},
{
"id": 19,
"trend_type": "PullRequest",
"action_type": "关闭了合并请求",
"trend_id": 8,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "28天前",
"name": "gggg",
"created_at": "2021-04-29 17:51"
},
{
"id": 16,
"trend_type": "Issue",
"action_type": "创建了工单",
"trend_id": 8,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "1个月前",
"name": "hjhkj",
"issue_type": "1",
"status_id": 1,
"priority_id": 2,
"created_at": "2021-04-19 10:52",
"updated_at": "2021-04-19 10:52",
"assign_user_name": null,
"assign_user_login": null,
"issue_journal_size": 0,
"issue_journals": []
},
{
"id": 7,
"trend_type": "VersionRelease",
"action_type": "创建了版本发布",
"trend_id": 7,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "1个月前",
"name": "v3.0.1",
"tag_name": "v3.0.1",
"target_commitish": "master",
"tarball_url": "http://localhost:10080/yystopf/ceshirepo1/archive/v3.0.1.tar.gz",
"zipball_url": "http://localhost:10080/yystopf/ceshirepo1/archive/v3.0.1.zip",
"url": "http://localhost:10080/api/v1/repos/yystopf/ceshirepo1/releases/78",
"version_gid": "78",
"created_at": "2021-03-30 15:51"
},
{
"id": 6,
"trend_type": "VersionRelease",
"action_type": "创建了版本发布",
"trend_id": 6,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "1个月前",
"name": "v3.0.0",
"tag_name": "v3.0.0",
"target_commitish": "master",
"tarball_url": "http://localhost:10080/yystopf/ceshirepo1/archive/v3.0.0.tar.gz",
"zipball_url": "http://localhost:10080/yystopf/ceshirepo1/archive/v3.0.0.zip",
"url": "http://localhost:10080/api/v1/repos/yystopf/ceshirepo1/releases/77",
"version_gid": "77",
"created_at": "2021-03-30 15:33"
},
{
"id": 5,
"trend_type": "VersionRelease",
"action_type": "创建了版本发布",
"trend_id": 5,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "1个月前",
"name": "v1.0.0",
"tag_name": "v1.0.0",
"target_commitish": "master",
"tarball_url": "http://localhost:10080/yystopf/ceshirepo1/archive/v1.0.0.tar.gz",
"zipball_url": "http://localhost:10080/yystopf/ceshirepo1/archive/v1.0.0.zip",
"url": "http://localhost:10080/api/v1/repos/yystopf/ceshirepo1/releases/76",
"version_gid": "76",
"created_at": "2021-03-30 15:27"
},
{
"id": 2,
"trend_type": "VersionRelease",
"action_type": "创建了版本发布",
"trend_id": 2,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "2个月前",
"name": "vvvv",
"tag_name": "v1.1",
"target_commitish": "dev",
"tarball_url": "http://localhost:10080/yystopf/virus_blog/archive/v1.1.tar.gz",
"zipball_url": "http://localhost:10080/yystopf/virus_blog/archive/v1.1.zip",
"url": "http://localhost:10080/api/v1/repos/yystopf/virus_blog/releases/6",
"version_gid": "6",
"created_at": "2021-03-15 14:18"
},
{
"id": 2,
"trend_type": "PullRequest",
"action_type": "创建了合并请求",
"trend_id": 2,
"user_name": "yystopf",
"user_login": "yystopf",
"user_avatar": "system/lets/letter_avatars/2/Y/241_125_89/120.png",
"action_time": "3个月前",
"name": "444",
"created_at": "2021-02-25 17:31"
}
]
}
```
<aside class="success">
Success Data.
</aside>
## 用户开发能力
用户开发能力, 默认为所有时间下的开发能力
> 示例:
```shell
curl -X GET http://localhost:3000/api/users/yystopf/statistics/develop.json
```
```javascript
await octokit.request('GET /api/users/:login/statistics/develop.json')
```
### HTTP 请求
`GET /api/users/:login/statistics/develop.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|start_time |integer |时间戳,开始时间,格式:1621526400|
|end_time |integer |时间戳,结束时间,格式:1622131200|
### 返回字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|influence |int |影响力 |
|contribution |int |贡献度|
|activity |int |活跃度|
|experience |int |项目经验|
|language |int |语言能力|
|languages_percent |float |语言百分比|
|each_language_score |int |各门语言分数|
> 返回的JSON示例:
```json
{
"platform": {
"influence": 61,
"contribution": 75,
"activity": 66,
"experience": 95,
"language": 87,
"languages_percent": {
"CSS": 0.03,
"C#": 0.13,
"Ruby": 0.04,
"Go": 0.05,
"C": 0.19,
"Java": 0.34,
"Python": 0.09,
"C+": 0.01,
"C++": 0.11,
"Scala": 0.01,
"HTML": 0.01
},
"each_language_score": {
"CSS": 71,
"C#": 86,
"Ruby": 75,
"Go": 77,
"C": 90,
"Java": 93,
"Python": 83,
"C+": 66,
"C++": 85,
"Scala": 66,
"HTML": 66
}
},
"user": {
"influence": 60,
"contribution": 72,
"activity": 65,
"experience": 88,
"language": 84,
"languages_percent": {
"C": 0.25,
"C#": 0.33,
"C++": 0.13,
"CSS": 0.08,
"Go": 0.04,
"HTML": 0.04,
"Java": 0.04,
"Ruby": 0.08
},
"each_language_score": {
"C": 81,
"C#": 84,
"C++": 75,
"CSS": 71,
"Go": 66,
"HTML": 66,
"Java": 66,
"Ruby": 71
}
}
}
```
<aside class="success">
Success Data.
</aside>
## 用户角色定位
用户角色定位,默认显示所有时间下的角色定位数据
> 示例:
```shell
curl -X GET http://localhost:3000/api/users/yystopf/statistics/role.json
```
```javascript
await octokit.request('GET /api/users/:login/statistics/role.json')
```
### HTTP 请求
`GET /api/users/:login/statistics/role.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|start_time |integer |时间戳,开始时间,格式:1621526400|
|end_time |integer |时间戳,结束时间,格式:1622131200|
### 返回字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|total_projects_count |int |用户所有的项目数量 |
|role.object.count |int |用户该语言下的项目数量|
|role.object.percent |float |用户该语言下的项目占比|
> 返回的JSON示例:
```json
{
"total_projects_count": 27,
"role": {
"owner": {
"count": 24,
"percent": 0.89
},
"manager": {
"count": 1,
"percent": 0.04
},
"developer": {
"count": 2,
"percent": 0.07
},
"reporter": {
"count": 0,
"percent": 0.0
}
}
}
```
<aside class="success">
Success Data.
</aside>
## 用户专业定位
用户专业定位,默认显示所有时间下的专业定位数据
> 示例:
```shell
curl -X GET http://localhost:3000/api/users/yystopf/statistics/major.json
```
```javascript
await octokit.request('GET /api/users/:login/statistics/major.json')
```
### HTTP 请求
`GET /api/users/:login/statistics/major.json`
### 请求字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|start_time |integer |时间戳,开始时间,格式:1621526400|
|end_time |integer |时间戳,结束时间,格式:1622131200|
### 返回字段说明:
参数 | 类型 | 字段说明
--------- | ----------- | -----------
|categories |int |用户项目分类 |
> 返回的JSON示例:
```json
{
"categories": [
"大数据",
"机器学习",
"深度学习",
"人工智能",
"智慧医疗",
"云计算"
]
}
```
<aside class="success">
Success Data.
</aside>
## 待办事项-用户通知信息
待办事项-用户通知信息
+4 -4
View File
@@ -17,7 +17,7 @@
# disk_directory :string(255)
# attachtype :integer default("1")
# is_public :integer default("1")
# copy_from :string(255)
# copy_from :integer
# quotes :integer default("0")
# is_publish :integer default("1")
# publish_time :datetime
@@ -26,15 +26,15 @@
# cloud_url :string(255) default("")
# course_second_category_id :integer default("0")
# delay_publish :boolean default("0")
# link :string(255)
# clone_id :integer
#
# Indexes
#
# index_attachments_on_author_id (author_id)
# index_attachments_on_clone_id (clone_id)
# index_attachments_on_container_id_and_container_type (container_id,container_type)
# index_attachments_on_course_second_category_id (course_second_category_id)
# index_attachments_on_created_on (created_on)
# index_attachments_on_is_public (is_public)
# index_attachments_on_quotes (quotes)
#
class Attachment < ApplicationRecord
+5 -8
View File
@@ -39,15 +39,13 @@
# business :boolean default("0")
# profile_completed :boolean default("0")
# laboratory_id :integer
# is_shixun_marker :boolean default("0")
# admin_visitable :boolean default("0")
# collaborator :boolean default("0")
# platform :string(255) default("0")
# gitea_token :string(255)
# gitea_uid :integer
# is_shixun_marker :boolean default("0")
# is_sync_pwd :boolean default("1")
# watchers_count :integer default("0")
# devops_step :integer default("0")
# gitea_token :string(255)
# platform :string(255)
#
# Indexes
#
@@ -55,9 +53,8 @@
# index_users_on_homepage_engineer (homepage_engineer)
# index_users_on_homepage_teacher (homepage_teacher)
# index_users_on_laboratory_id (laboratory_id)
# index_users_on_login (login) UNIQUE
# index_users_on_mail (mail) UNIQUE
# index_users_on_phone (phone) UNIQUE
# index_users_on_login (login)
# index_users_on_mail (mail)
# index_users_on_type (type)
#
+1
View File
@@ -9,6 +9,7 @@ module ProjectOperable
has_many :reporters, -> { joins(:roles).where(roles: { name: 'Reporter' }) }, class_name: 'Member'
has_many :writable_members, -> { joins(:roles).where.not(roles: {name: 'Reporter'}) }, class_name: 'Member'
has_many :team_projects, dependent: :destroy
has_many :teams, through: :team_projects, source: :team
end
def set_owner_permission(creator)
+3 -2
View File
@@ -6,7 +6,7 @@
# tracker_id :integer not null
# project_id :integer not null
# subject :string(255) default(""), not null
# description :text(4294967295)
# description :text(65535)
# due_date :date
# category_id :integer
# status_id :integer not null
@@ -14,6 +14,7 @@
# priority_id :integer not null
# fixed_version_id :integer
# author_id :integer not null
# lock_version :integer default("0"), not null
# created_on :datetime
# updated_on :datetime
# start_date :date
@@ -27,7 +28,7 @@
# closed_on :datetime
# project_issues_index :integer
# issue_type :string(255)
# token :integer default("0")
# token :string(255)
# issue_tags_value :string(255)
# is_lock :boolean default("0")
# issue_classify :string(255)
-1
View File
@@ -10,7 +10,6 @@
# sync_course :boolean default("0")
# sync_subject :boolean default("0")
# sync_shixun :boolean default("0")
# is_local :boolean default("0")
#
# Indexes
#
+5 -8
View File
@@ -39,15 +39,13 @@
# business :boolean default("0")
# profile_completed :boolean default("0")
# laboratory_id :integer
# is_shixun_marker :boolean default("0")
# admin_visitable :boolean default("0")
# collaborator :boolean default("0")
# platform :string(255) default("0")
# gitea_token :string(255)
# gitea_uid :integer
# is_shixun_marker :boolean default("0")
# is_sync_pwd :boolean default("1")
# watchers_count :integer default("0")
# devops_step :integer default("0")
# gitea_token :string(255)
# platform :string(255)
#
# Indexes
#
@@ -55,9 +53,8 @@
# index_users_on_homepage_engineer (homepage_engineer)
# index_users_on_homepage_teacher (homepage_teacher)
# index_users_on_laboratory_id (laboratory_id)
# index_users_on_login (login) UNIQUE
# index_users_on_mail (mail) UNIQUE
# index_users_on_phone (phone) UNIQUE
# index_users_on_login (login)
# index_users_on_mail (mail)
# index_users_on_type (type)
#
+22
View File
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: pinned_projects
#
# id :integer not null, primary key
# user_id :integer
# project_id :integer
# position :integer default("0")
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_pinned_projects_on_project_id (project_id)
# index_pinned_projects_on_user_id (user_id)
#
class PinnedProject < ApplicationRecord
belongs_to :user
belongs_to :project
end
+64 -74
View File
@@ -1,76 +1,65 @@
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255) default(""), not null
# description :text(4294967295)
# homepage :string(255) default("")
# is_public :boolean default("1"), not null
# parent_id :integer
# created_on :datetime
# updated_on :datetime
# identifier :string(255)
# status :integer default("1"), not null
# lft :integer
# rgt :integer
# inherit_members :boolean default("0"), not null
# project_type :integer default("0")
# hidden_repo :boolean default("0"), not null
# attachmenttype :integer default("1")
# user_id :integer
# dts_test :integer default("0")
# enterprise_name :string(255)
# organization_id :integer
# project_new_type :integer
# gpid :integer
# forked_from_project_id :integer
# forked_count :integer default("0")
# publish_resource :integer default("0")
# visits :integer default("0")
# hot :integer default("0")
# invite_code :string(255)
# qrcode :string(255)
# qrcode_expiretime :integer default("0")
# script :text(65535)
# training_status :integer default("0")
# rep_identifier :string(255)
# project_category_id :integer
# project_language_id :integer
# praises_count :integer default("0")
# watchers_count :integer default("0")
# issues_count :integer default("0")
# pull_requests_count :integer default("0")
# language :string(255)
# versions_count :integer default("0")
# issue_tags_count :integer default("0")
# closed_issues_count :integer default("0")
# open_devops :boolean default("0")
# gitea_webhook_id :integer
# open_devops_count :integer default("0")
# recommend :boolean default("0")
# platform :integer default("0")
# license_id :integer
# ignore_id :integer
# default_branch :string(255) default("master")
# website :string(255)
# lesson_url :string(255)
#
# Indexes
#
# index_projects_on_forked_from_project_id (forked_from_project_id)
# index_projects_on_identifier (identifier)
# index_projects_on_is_public (is_public)
# index_projects_on_lft (lft)
# index_projects_on_name (name)
# index_projects_on_platform (platform)
# index_projects_on_project_type (project_type)
# index_projects_on_recommend (recommend)
# index_projects_on_rgt (rgt)
# index_projects_on_status (status)
# index_projects_on_updated_on (updated_on)
#
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255) default(""), not null
# description :text(65535)
# homepage :string(255) default("")
# is_public :boolean default("1"), not null
# parent_id :integer
# created_on :datetime
# updated_on :datetime
# identifier :string(255)
# status :integer default("1"), not null
# lft :integer
# rgt :integer
# inherit_members :boolean default("0"), not null
# project_type :integer default("0")
# hidden_repo :boolean default("0"), not null
# attachmenttype :integer default("1")
# user_id :integer
# dts_test :integer default("0")
# enterprise_name :string(255)
# organization_id :integer
# project_new_type :integer
# gpid :integer
# forked_from_project_id :integer
# forked_count :integer default("0")
# publish_resource :integer default("0")
# visits :integer default("0")
# hot :integer default("0")
# invite_code :string(255)
# qrcode :string(255)
# qrcode_expiretime :integer default("0")
# script :text(65535)
# training_status :integer default("0")
# rep_identifier :string(255)
# project_category_id :integer
# project_language_id :integer
# license_id :integer
# ignore_id :integer
# praises_count :integer default("0")
# watchers_count :integer default("0")
# issues_count :integer default("0")
# pull_requests_count :integer default("0")
#
# Indexes
#
# index_projects_on_forked_from_project_id (forked_from_project_id)
# index_projects_on_identifier (identifier)
# index_projects_on_is_public (is_public)
# index_projects_on_lft (lft)
# index_projects_on_name (name)
# index_projects_on_platform (platform)
# index_projects_on_project_type (project_type)
# index_projects_on_recommend (recommend)
# index_projects_on_rgt (rgt)
# index_projects_on_status (status)
# index_projects_on_updated_on (updated_on)
#
class Project < ApplicationRecord
include Matchable
@@ -111,9 +100,10 @@ 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 :team_projects, 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: :user
after_save :check_project_members
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
+5
View File
@@ -8,6 +8,11 @@
# projects_count :integer default("0")
# created_at :datetime not null
# updated_at :datetime not null
# ancestry :string(255)
#
# Indexes
#
# index_project_categories_on_ancestry (ancestry)
#
class ProjectCategory < ApplicationRecord
-5
View File
@@ -16,11 +16,6 @@
# head :string(255)
# base :string(255)
# issue_id :integer
# fork_project_id :integer
# is_original :boolean default("0")
# comments_count :integer default("0")
# commits_count :integer default("0")
# files_count :integer default("0")
#
class PullRequest < ApplicationRecord
+1
View File
@@ -27,6 +27,7 @@
#
# Indexes
#
# index_repositories_on_identifier (identifier)
# index_repositories_on_project_id (project_id)
# index_repositories_on_user_id (user_id)
#
+20 -9
View File
@@ -39,15 +39,13 @@
# business :boolean default("0")
# profile_completed :boolean default("0")
# laboratory_id :integer
# is_shixun_marker :boolean default("0")
# admin_visitable :boolean default("0")
# collaborator :boolean default("0")
# platform :string(255) default("0")
# gitea_token :string(255)
# gitea_uid :integer
# is_shixun_marker :boolean default("0")
# is_sync_pwd :boolean default("1")
# watchers_count :integer default("0")
# devops_step :integer default("0")
# gitea_token :string(255)
# platform :string(255)
#
# Indexes
#
@@ -55,9 +53,8 @@
# index_users_on_homepage_engineer (homepage_engineer)
# index_users_on_homepage_teacher (homepage_teacher)
# index_users_on_laboratory_id (laboratory_id)
# index_users_on_login (login) UNIQUE
# index_users_on_mail (mail) UNIQUE
# index_users_on_phone (phone) UNIQUE
# index_users_on_login (login)
# index_users_on_mail (mail)
# index_users_on_type (type)
#
@@ -165,6 +162,11 @@ class User < Owner
has_many :organization_users, dependent: :destroy
has_many :organizations, through: :organization_users
has_many :pinned_projects, dependent: :destroy
has_many :is_pinned_projects, through: :pinned_projects, source: :project
accepts_nested_attributes_for :is_pinned_projects
has_many :issues, dependent: :destroy, foreign_key: :author_id
has_many :pull_requests, dependent: :destroy
# Groups and active users
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
@@ -177,7 +179,9 @@ class User < Owner
attr_accessor :password, :password_confirmation
delegate :gender, :department_id, :school_id, :location, :location_city, :technical_title, to: :user_extension, allow_nil: true
delegate :description, :gender, :department_id, :school_id, :location, :location_city,
:show_email, :show_location, :show_department,
:technical_title, :province, :city, :custom_department, to: :user_extension, allow_nil: true
before_save :update_hashed_password
after_create do
@@ -196,6 +200,13 @@ class User < Owner
validate :validate_sensitive_string
validate :validate_password_length
# 用户参与的所有项目
def full_member_projects
normal_projects = Project.members_projects(self.id).to_sql
org_projects = Project.joins(teams: :team_users).where(team_users: {user_id: self.id}).to_sql
return Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
end
def name
login
end
+1 -3
View File
@@ -12,9 +12,7 @@
#
# Indexes
#
# index_user_actions_on_ip (ip)
# index_user_actions_on_user_id (user_id)
# index_user_actions_on_user_id_and_action_type (user_id,action_type)
# index_user_actions_on_ip (ip)
#
class UserAction < ApplicationRecord
+1 -4
View File
@@ -10,13 +10,10 @@
# updated_at :datetime not null
# register_status :integer default("0")
# action_status :integer default("0")
# is_delete :boolean default("0")
# user_id :integer
#
# Indexes
#
# index_user_agents_on_ip (ip)
# index_user_agents_on_user_id (user_id)
# index_user_agents_on_ip (ip) UNIQUE
#
class UserAgent < ApplicationRecord
+28 -25
View File
@@ -22,9 +22,12 @@
# school_id :integer
# description :string(255) default("")
# department_id :integer
# honor :text(65535)
# edu_background :integer
# edu_entry_year :integer
# province :string(255)
# city :string(255)
# custom_department :string(255)
# show_email :boolean default("0")
# show_location :boolean default("0")
# show_department :boolean default("0")
#
# Indexes
#
@@ -33,25 +36,25 @@
# index_user_extensions_on_user_id (user_id)
#
class UserExtension < ApplicationRecord
# identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者
enum identity: { teacher: 0, student: 1, professional: 2, developer: 3, enterprise: 4, unselect: -1 }
belongs_to :user, touch: true
belongs_to :school, optional: true
# belongs_to :department, optional: true
# before_save :set_laboratory_school
def identity_text
I18n.t("user.identity.#{identity}")
end
private
def set_laboratory_school
# return unless new_record?
# self.school_id = Laboratory.current.school_id if school_id.blank? && !Laboratory.current.main_site?
end
end
class UserExtension < ApplicationRecord
# identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者
enum identity: { teacher: 0, student: 1, professional: 2, developer: 3, enterprise: 4, unselect: -1 }
belongs_to :user, touch: true
belongs_to :school, optional: true
# belongs_to :department, optional: true
# before_save :set_laboratory_school
def identity_text
I18n.t("user.identity.#{identity}")
end
private
def set_laboratory_school
# return unless new_record?
# self.school_id = Laboratory.current.school_id if school_id.blank? && !Laboratory.current.main_site?
end
end
+7 -2
View File
@@ -53,10 +53,15 @@ class Projects::ListMyQuery < ApplicationQuery
q = projects.ransack(name_or_identifier_cont: params[:search])
scope = q.result.includes(:project_category, :project_language,:owner, :repository)
scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users)
sort = params[:sort_by] || "updated_on"
sort_direction = params[:sort_direction] || "desc"
scope.order("projects.#{sort} #{sort_direction}")
if params[:choosed].present? && params[:choosed].is_a?(Array)
scope.order("FIELD(id, #{params[:choosed].reverse.join(",")}) desc")
else
scope.order("projects.#{sort} #{sort_direction}")
end
end
end
@@ -0,0 +1,23 @@
class Gitea::User::HeadmapService < Gitea::ClientService
attr_reader :start_time, :end_time, :username
def initialize(username, start_time, end_time)
@username = username
@start_time = start_time
@end_time = end_time
end
def call
response = get(url, params)
render_response(response)
end
private
def params
Hash.new.merge(start: start_time, end: end_time)
end
def url
"/users/#{username}/heatmap".freeze
end
end
+1 -1
View File
@@ -34,7 +34,7 @@ class Projects::TransferService < ApplicationService
def update_visit_teams
if new_owner.is_a?(Organization)
# 为包含组织所有项目的团队创建项目访问权限
new_owner.build_permit_team_projects(project.id)
new_owner.build_permit_team_projects!(project.id)
else
project.team_projects.each(&:destroy!)
end
@@ -1,4 +1,10 @@
json.name issue.try(:subject)
json.issue_type issue.issue_type == "1" ? "普通" : "悬赏"
json.status_id issue.try(:status_id)
json.issue_status issue.issue_status.try(:name)
json.priority issue.priority.try(:name)
json.priority_id issue.try(:priority_id)
json.version issue.version.try(:name)
json.created_at format_time(issue.try(:created_on))
json.updated_at format_time(issue.try(:updated_on))
json.assign_user_name issue&.get_assign_user.try(:show_real_name)
@@ -0,0 +1,17 @@
json.id trend.id
json.trend_type trend.trend_type
json.action_type l("trend.#{trend.action_type}") + l("trend.#{trend.trend_type}")
json.trend_id trend.trend_id
json.user_name trend.user.try(:show_real_name)
json.user_login trend.user.login
json.user_avatar url_to_avatar(trend.user)
json.action_time time_from_now(trend.created_at)
if trend.trend_type == "Issue"
json.partial! "issues/simple_issue_item", locals: {issue: trend.trend}
elsif trend.trend_type == "VersionRelease"
json.partial! "version_releases/simple_version_release", locals: {version: trend.trend}
else
json.name trend.trend&.title
json.created_at format_time(trend.trend&.created_at)
end
+2 -18
View File
@@ -9,25 +9,9 @@ json.limit @limit
json.project_trends_size @project_trends_size
json.project_trends do
json.array! @project_trends.to_a.each do |trend|
json.id trend.id
json.trend_type trend.trend_type
json.action_type l("trend.#{trend.action_type}") + l("trend.#{trend.trend_type}")
json.trend_id trend.trend_id
json.user_name trend.user.try(:show_real_name)
json.user_login trend.user.login
json.user_avatar url_to_avatar(trend.user)
if trend.trend_type == "Issue"
json.partial! "issues/simple_issue_item", locals: {issue: trend.trend}
elsif trend.trend_type == "VersionRelease"
json.partial! "version_releases/simple_version_release", locals: {version: trend.trend}
else
json.name trend.trend.title
json.created_at format_time(trend.trend.created_at)
end
#后续需要天际pullrequest 和 版本的内容
json.partial! "detail", trend: trend
end
end
@@ -5,6 +5,9 @@ json.name project.name
json.description Nokogiri::HTML(project.description).text
json.visits project.visits
json.praises_count project.praises_count.to_i
json.watchers_count project.watchers_count.to_i
json.issues_count project.issues_count.to_i
json.pull_requests_count project.pull_requests_count.to_i
json.forked_count project.forked_count.to_i
json.is_public project.is_public
json.mirror_url project.repository&.mirror_url
@@ -14,6 +17,7 @@ json.time_ago time_from_now(project.updated_on)
json.forked_from_project_id project.forked_from_project_id
json.open_devops project.open_devops?
json.platform project.platform
json.is_pinned project.has_pinned_users.include?(current_user)
json.author do
if project.educoder?
project_educoder = project.project_educoder
+2 -1
View File
@@ -12,4 +12,5 @@ json.permission render_permission(current_user, @project)
json.is_transfering @project.is_transfering
json.transfer do
json.partial! "/users/user_simple", locals: {user: @project&.applied_transfer_project&.owner}
end
end
json.is_pinned @project.has_pinned_users.include?(current_user)
+17 -4
View File
@@ -1,7 +1,20 @@
json.user_id user.id
json.login user.login
json.name user.full_name
json.username @user.full_name
json.real_name @user.real_name
json.grade user.grade
json.identity user&.user_extension&.identity
# json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开
json.image_url url_to_avatar(user)
json.gender @user.gender
json.login @user.login
json.user_id @user.id
json.image_url url_to_avatar(@user)
json.admin @user.admin?
json.user_identity @user.identity
json.is_watch current_user&.watched?(@user)
json.watched_count @user.fan_count #粉丝
json.watching_count @user.follow_count #关注数
json.created_time format_time(@user.created_on)
json.email @user.show_email ? @user.mail : nil
json.province @user.show_location ? @user.province : nil
json.city @user.show_location ? @user.city : nil
json.custom_department @user.show_department ? @user.custom_department : nil
json.description @user.description
@@ -3,7 +3,7 @@ json.format_time target.created_at.strftime("%Y-%m-%d")
json.name user.try(:show_real_name)
json.login user.try(:login)
json.image_url url_to_avatar(user)
json.is_current_user current_user.try(:id) == target.user_id
json.is_current_user current_user.try(:id) == user.id
json.is_watch current_user&.watched?(user)
@@ -1,5 +1,6 @@
json.username @user.full_name
json.real_name @user.real_name
json.gender @user.gender
json.login @user.login
json.user_id @user.id
json.image_url url_to_avatar(@user)
@@ -15,3 +16,9 @@ json.profile_completed @user.profile_completed?
json.professional_certification @user.professional_certification
json.devops_step @user.devops_step
json.ci_certification @user.ci_certification?
json.email @user.mail
json.province @user.province
json.city @user.city
json.custom_department @user.custom_department
json.description @user.description
json.(@user, :show_email, :show_department, :show_location)
@@ -0,0 +1,5 @@
json.total_contributions @headmaps.collect{|map| map["contributions"]}.reduce(0, :+)
json.headmaps @headmaps.each do |map|
json.date Time.at(map["timestamp"].to_i).strftime("%Y-%m-%d")
json.contributions map["contributions"]
end
@@ -0,0 +1,7 @@
json.total_count @is_pinned_projects.total_count
json.projects @is_pinned_projects.each do |project|
json.partial! "projects/project_detail", project: project&.project
json.id project.id
json.position project.position
json.project_id project.project_id
end
@@ -0,0 +1,4 @@
json.total_count @project_trends.total_count
json.project_trends @project_trends.each do |trend|
json.partial! "project_trends/detail", trend: trend
end
+8 -13
View File
@@ -1,15 +1,4 @@
# json.partial! 'users/user', locals: { user: @user }
json.username @user.full_name
json.real_name @user.real_name
json.login @user.login
json.user_id @user.id
json.image_url url_to_avatar(@user)
json.admin @user.admin?
json.user_identity @user.identity
json.is_watch current_user&.watched?(@user)
json.watched_count @user.fan_count #粉丝
json.watching_count @user.follow_count #关注数
json.partial! 'users/user', locals: { user: @user }
json.undo_messages @waiting_applied_messages.size
json.undo_transfer_projects @common_applied_transfer_projects.size
json.undo_events @undo_events
@@ -17,4 +6,10 @@ json.user_composes_count @user_composes_count
json.user_org_count @user_org_count
json.common_projects_count @projects_common_count
json.mirror_projects_count @projects_mirrior_count
json.sync_mirror_projects_count @projects_sync_mirrior_count
json.sync_mirror_projects_count @projects_sync_mirrior_count
json.created_time format_time(@user.created_on)
json.email @user.show_email ? @user.mail : nil
json.province @user.show_location ? @user.province : nil
json.city @user.show_location ? @user.city : nil
json.custom_department @user.show_department ? @user.custom_department : nil
json.description @user.description
@@ -0,0 +1,19 @@
json.platform do
json.influence @platform_influence
json.contribution @platform_contribution
json.activity @platform_activity
json.experience @platform_experience
json.language @platform_language
json.languages_percent @platform_languages_percent
json.each_language_score @platform_each_language_score
end
json.user do
json.influence @influence
json.contribution @contribution
json.activity @activity
json.experience @experience
json.language @language
json.languages_percent @languages_percent
json.each_language_score @each_language_score
end
@@ -0,0 +1,19 @@
json.total_projects_count @full_member_projects_count
json.role do
json.owner do
json.count @owner_projects_count
json.percent (@owner_projects_count.to_f/@full_member_projects_count).round(2)
end
json.manager do
json.count @manager_projects_count
json.percent (@manager_projects_count.to_f/@full_member_projects_count).round(2)
end
json.developer do
json.count @developer_projects_count
json.percent (@developer_projects_count.to_f/@full_member_projects_count).round(2)
end
json.reporter do
json.count @reporter_projects_count
json.percent (@reporter_projects_count.to_f/@full_member_projects_count).round(2)
end
end
+1
View File
@@ -0,0 +1 @@
json.partial! 'users/user', locals: { user: @user }
+1 -1
View File
@@ -1,7 +1,7 @@
json.count @watchers_count
json.users do
json.array! @watchers do |watcher|
json.partial! "/users/watch_user_detail", locals: {target: watcher, user: watcher.watchable}
json.partial! "/users/watch_user_detail", target: watcher, user: watcher.watchable
end
# json.partial! "/users/watch_user_detail", collection: @watchers, as: :target
end