Merge branch 'develop' into dev_trustie_server

This commit is contained in:
jasder 2021-04-22 16:38:58 +08:00
commit 39193324e9
32 changed files with 61 additions and 183 deletions

View File

@ -2,8 +2,8 @@ class UsersController < ApplicationController
include ApplicationHelper
include Ci::DbConnectable
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users]
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard]
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]
skip_before_action :check_sign, only: [:attachment_show]
@ -56,6 +56,9 @@ class UsersController < ApplicationController
@watchers = paginate(watchers)
end
def hovercard
end
def update
@user = User.find params[:id]
@user.update!(user_params)

View File

@ -35,12 +35,6 @@ module ApplicationHelper
course.course_modules.find_by(module_type: "graduation").try(:id)
end
# 是否关注
# from_user_id为被关注的用户
def follow?(from_user_id, user_id)
Watcher.where(watchable_type: 'Principal', watchable_id: from_user_id, user_id: user_id).exists?
end
# git用户
# git用户命名规则login+"@educoder.net"
def git_username(email)

View File

@ -6,6 +6,7 @@ module Watchable
has_many :watcher_users, through: :watchers, source: :user, validate: false
scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) }
scope :following, -> (user_id) { watched_by }
end
def watched?(watchable)
@ -21,6 +22,24 @@ module Watchable
obj.destroy! if obj.present?
end
# 我正在关注的、我追随的
def following
User.following(self.id)
end
def following_count
following.size
end
# 关注我的、我的粉丝、我的追随者
def followers
watcher_users
end
def followers_count
followers.size
end
module ClassMethods
end
end

View File

@ -138,10 +138,6 @@ class User < Owner
has_many :attachments,foreign_key: :author_id, :dependent => :destroy
# 关注
# has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
# has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
has_one :ci_cloud_account, class_name: 'Ci::CloudAccount', dependent: :destroy
# 认证

View File

@ -11,11 +11,17 @@ class User
end
def get_letter_avatar_url(size = :lg)
avatar_path(size).split('public/')&.last
avatar_path(self.username, size).split('public/')&.last
end
def avatar_path(size)
LetterAvatar.generate self.username, avatar_size(size)
def self.get_letter_avatar_url(name)
return "" if name.blank?
avatar = LetterAvatar.generate Pinyin.t(name), 120
avatar.split('public/')&.last
end
def avatar_path(username, size)
LetterAvatar.generate username, avatar_size(size)
end
# 返回头像尺寸

View File

@ -1,10 +1,10 @@
json.author do
author = User.find_by(login: commit['Author']['Name'])
author = User.find_by(mail: commit['Author']['Email'])
json.partial! 'repositories/commit_author', locals: { user: author, name: commit['Committer']['Name'] }
end
json.committer do
author = User.find_by(login: commit['Committer']['Name'])
author = User.find_by(mail: commit['Committer']['Email'])
json.partial! 'repositories/commit_author', locals: { user: author, name: commit['Committer']['Name'] }
end
json.timestamp render_unix_time(commit['Committer']['When'])

View File

@ -7,5 +7,5 @@ else
json.id nil
json.login name
json.name name
json.image_url File.join("avatars/User","b")
json.image_url User::Avatar.get_letter_avatar_url(name)
end

View File

@ -5,12 +5,15 @@ else
json.total_count @hash_commit[:total_count]
json.commits do
json.array! @hash_commit[:body] do |commit|
json.commit1 commit
commiter = commit['committer']
if commiter.present?
commit_user_id = commiter['id']
forge_user = User.simple_select.find_by(gitea_uid: commit_user_id)
end
forge_user =
if commiter.present?
User.simple_select.find_by(mail: commiter['email'])
else
User.simple_select.find_by(mail: commit['commit']['committer']['email'])
end
json.sha commit['sha']
json.message commit['commit']['message']
json.timestamp render_unix_time(commit['commit']['author']['date'])
@ -23,7 +26,7 @@ else
json.login commit['commit']['author']['name']
json.type nil
json.name commit['commit']['author']['name']
json.image_url File.join("avatars/User","b")
json.image_url User::Avatar.get_letter_avatar_url(commit['commit']['author']['name'])
end
end
end

View File

@ -1,3 +0,0 @@
json.count @count
json.courses @courses, partial: 'users/courses/shared/course', as: :course

View File

@ -1,18 +0,0 @@
json.id course.id
json.name course.name
# json.members_count course.members_count
json.members_count course.course_members_count
# json.homework_commons_count course.homework_commons_count
json.homework_commons_count get_tasks_count course
json.attachments_count course.attachments.count
json.visits course.visits
json.school course.school&.name
json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course)
json.is_public course.is_public
json.can_visited observed_logged_user? || course.can_visited?
json.teacher do
json.partial! 'users/shared/real_user', user: course.teacher
end

View File

@ -0,0 +1,15 @@
json.id @user.id
json.login @user.login
json.name @user.full_name
json.image_url url_to_avatar(@user)
json.url "#{request.base_url }/users/#{@user.login}"
json.followers_count @user.followers_count
json.following_count @user.following_count
json.projects_count @user.projects_count
json.is_watch current_user&.watched?(@user)
json.organizations @user.organizations do |organization|
json.login organization.login
json.name organization.full_name
json.image_url url_to_avatar(organization)
json.url "#{request.base_url }/organize/#{organization.login}"
end

View File

@ -1,3 +0,0 @@
json.count @count
json.shixuns @shixuns, partial: 'users/shixuns/shared/shixun', as: :shixun, locals: { user: observed_user }

View File

@ -1,10 +0,0 @@
json.id shixun.id
json.identifier shixun.identifier
json.tag shixun.first_tag_repertoire&.name
json.image_url url_to_avatar(shixun)
json.name shixun.name
json.status shixun.status
json.human_status shixun.human_status
json.challenges_count shixun.challenges_count
json.finished_challenges_count @finished_challenges_count_map&.fetch(shixun.id, 0) || shixun.finished_challenges_count(user)
json.is_jupyter shixun.is_jupyter

View File

@ -1,6 +0,0 @@
json.extract! video, :id, :title, :cover_url, :file_url, :play_url, :vv, :user_id
json.play_duration video.video_play_duration
json.published_at video.display_published_at
json.created_at video.display_created_at
json.updated_at video.display_updated_at

View File

@ -1,2 +0,0 @@
json.count @count
json.videos @videos, partial: 'video', as: :video

View File

@ -1,7 +0,0 @@
json.count @count
json.videos do
json.array! @videos.each do |video|
json.partial! 'video', video: video
json.file_url nil
end
end

View File

@ -1 +0,0 @@
json.partial! 'video', video: current_video

View File

@ -1,3 +0,0 @@
json.user do
json.partial! 'weapps/shared/user', locals: { user: current_user }
end

View File

@ -1,8 +0,0 @@
json.course do
json.(@course, :id, :name)
json.code_halt @course.invite_code_halt == 1
json.invite_code @course.invite_code_halt == 0 ? @course.generate_invite_code : ""
json.teacher_name @course.teacher.real_name
json.teacher_img url_to_avatar(@course.teacher)
json.teacher_school @course.school.try(:name)
end

View File

@ -1,12 +0,0 @@
json.activities @activities do |activity|
json.(activity, :course_act_id, :course_act_type)
json.author do
user = activity.user
json.name user.real_name
json.login user.login
json.img url_to_avatar(user)
end
json.created_at activity.created_at.strftime('%m-%d %H:%M:')
json.container_name activity.container_name
json.container_type activity.course_act_type == "HomeworkCommon" ? activity.course_act&.homework_type : ""
end

View File

@ -1,2 +0,0 @@
json.(@course, :id, :name, :credit, :end_date)
json.course_list_name @course.course_list&.name

View File

@ -1,3 +0,0 @@
json.categories @categories.each do |category|
json.(category, :id, :name)
end

View File

@ -1,4 +0,0 @@
json.(@course, :id, :name, :course_members_count, :credit, :invite_code_halt)
json.teachers_count @course.teachers.count
json.students_count @course.students.count
json.course_identity @current_user.course_identity(@course)

View File

@ -1,7 +0,0 @@
json.students student_list @students, @course.excellent, @user_course_identity
json.students_count @students_count
if @course_group
json.course_group do
json.(@course_group, :id, :name, :invite_code, :course_members_count)
end
end

View File

@ -1,3 +0,0 @@
json.teacher_list teacher_list(@teacher_list, @user_course_identity)
json.teacher_list_size @teacher_list_size
json.apply_size @applications_size

View File

@ -1,30 +0,0 @@
json.carousels do
json.array! @carousels do |carousel|
json.extract! carousel, :id, :link, :position
json.path carousel.link
json.image_url Util::FileManage.source_disk_file_url(carousel)
end
end
if @advert.present?
json.advert do
json.extract! @advert, :id, :link
json.image_url Util::FileManage.source_disk_file_url(@advert)
end
else
json.advert nil
end
json.course_count @course_count
json.courses @courses.each do |course|
json.(course, :id, :name, :visits, :course_members_count, :is_end, :invite_code_halt)
json.creator course.teacher.real_name
json.avatar_url url_to_avatar(course.teacher)
json.invite_code course.invite_code_halt == 0 ? course.generate_invite_code : ""
json.school course.school&.name
course_member = @category == "study" ? course.students.where(user_id: @user.id).first : course.teachers.where(user_id: @user.id).first
json.sticky course_member.sticky
json.course_identity current_user.course_identity(course)
end

View File

@ -1,4 +0,0 @@
json.status 0
json.user do
json.partial! 'weapps/shared/user', locals: { user: @user }
end

View File

@ -1,14 +0,0 @@
json.count @results.total_count
json.results do
json.array! @results.with_highlights(multiple: true) do |obj, highlights|
json.merge! obj.to_searchable_json
json.type obj.class.name.downcase
json.title highlights.delete(:name)&.join('...') || obj.searchable_title
json.cover url_to_avatar(obj)
if obj.is_a?(Course)
json.author_avatar_url url_to_avatar(obj.teacher)
end
end
end

View File

@ -1,3 +0,0 @@
json.user do
json.partial! 'weapps/shared/user', locals: { user: current_user }
end

View File

@ -1,15 +0,0 @@
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.business user.business?
json.is_teacher user.user_extension&.teacher?
json.user_identity user.identity
json.identity user.user_extension&.identity
json.tidding_count 0
json.user_phone_binded user.phone.present?
json.phone user.phone
json.profile_completed user.profile_completed?
json.professional_certification user.professional_certification

View File

@ -1 +0,0 @@
json.user_account @user.phone.present? ? @user.phone : (@user.mail.present? ? @user.mail : @user.login)

View File

@ -198,6 +198,7 @@ Rails.application.routes.draw do
get :projects
get :watch_users
get :fan_users
get :hovercard
end
collection do
post :following