forked from Gitlink/forgeplus
Merge pull request '论坛头像处理' (#6) from dev_forum into dev_trustie_forum
This commit is contained in:
commit
4e3ddffefc
|
@ -11,7 +11,7 @@ module ApiIndexHelper
|
|||
{username: current_user.show_real_name,
|
||||
login: current_user.login,
|
||||
user_id: current_user.id,
|
||||
image_url: "/images/#{url_to_avatar(current_user)}?#{Time.now.to_i}",
|
||||
image_url: "#{url_to_avatar(current_user, true)}?#{Time.now.to_i}",
|
||||
admin: current_user.admin?,
|
||||
user_url: "/users/#{current_user.try(:login)}",
|
||||
is_banned: user_is_banned?(current_user),
|
||||
|
@ -26,7 +26,7 @@ module ApiIndexHelper
|
|||
{username: user.show_real_name,
|
||||
user_id: user.id,
|
||||
login: user.login,
|
||||
image_url: "/images/#{url_to_avatar(user)}?#{Time.now.to_i}",
|
||||
image_url: "#{url_to_avatar(user, true)}?#{Time.now.to_i}",
|
||||
admin: user.admin?,
|
||||
user_url: "/users/#{user.try(:login)}"
|
||||
}
|
||||
|
|
|
@ -140,7 +140,20 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
# 用户图像url,如果不存在的话,source为匿名用户,即默认使用匿名用户图像
|
||||
def url_to_avatar(source)
|
||||
def url_to_avatar(source, with_image=false)
|
||||
platform_url = Rails.application.config_for(:configuration)['forge_platform_url']
|
||||
if platform_url && source.class.to_s == 'User'
|
||||
return platform_url + "/api/users/#{source&.login}/get_image"
|
||||
else
|
||||
if with_image
|
||||
return "/images/" + get_disk_avatar_url(source)
|
||||
else
|
||||
return get_disk_avatar_url(source)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_disk_avatar_url(source)
|
||||
return "" if source&.id.blank?
|
||||
if File.exist?(disk_filename(source&.class, source&.id))
|
||||
ctime = File.ctime(disk_filename(source.class, source.id)).to_i
|
||||
|
@ -158,7 +171,7 @@ module ApplicationHelper
|
|||
File.join("images","educoder", "index", "shixun", "shixun#{rand(23)}.jpg")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# 主页banner图
|
||||
def banner_img(source_type)
|
||||
if File.exist?(disk_filename(source_type, "banner"))
|
||||
|
|
|
@ -151,7 +151,7 @@ class MemosService
|
|||
watched: watched,
|
||||
is_blocked: current_user&.blocked_for(memo_author.id),
|
||||
is_blocked_by: memo_author&.blocked_for(current_user.id),
|
||||
image_url: "/images/#{url_to_avatar(memo_author)}?#{Time.now.to_i}",
|
||||
image_url: "#{url_to_avatar(memo_author, true)}",
|
||||
identity: memo_author.identity,
|
||||
login: memo_author.login,
|
||||
user_id: memo_author.id,
|
||||
|
@ -160,7 +160,7 @@ class MemosService
|
|||
replies_count: memo_author_memos.total_replies.size,
|
||||
watchers_count: memo_author.fan_count,
|
||||
current_login: current_user.try(:login),
|
||||
current_image_url: current_user.try(:login).present? ? "/images/#{url_to_avatar(current_user)}?#{Time.now.to_i}" : "/images/avatars/User/b",
|
||||
current_image_url: current_user.try(:login).present? ? "#{url_to_avatar(current_user, true)}" : "/images/avatars/User/b",
|
||||
is_current_user: memo.author_id == current_user.try(:id)
|
||||
}
|
||||
recent_memos = memo_author_memos.posts.where("id != ?", params[:id].to_i).order_index("published_at").select([:id,:subject]).limit(3).as_json
|
||||
|
@ -414,7 +414,7 @@ class MemosService
|
|||
memo.children << reply
|
||||
create_user_tidings(reply, "forum_comment")
|
||||
replies = {:id => reply.id, :content => reply.content, :time => time_from_now(reply.created_at), :user_id => reply.author_id,
|
||||
:image_url => "/images/#{url_to_avatar(reply.author)}?#{Time.now.to_i}", :username => reply.author.show_real_name, :reward => memo.reward, :hidden => reply.hidden,
|
||||
:image_url => "#{url_to_avatar(reply.author, true)}", :username => reply.author.show_real_name, :reward => memo.reward, :hidden => reply.hidden,
|
||||
:praise_count => reply.praises_count,:user_login => reply.author.try(:login), replies_count: reply.can_see_reply_count(current_user)}
|
||||
{
|
||||
status: 0,
|
||||
|
@ -765,7 +765,7 @@ class MemosService
|
|||
permission = current_user ? current_user.manager_of_memo?(memo) : false
|
||||
# 实训(TPM)的管理员可以看到隐藏的评论
|
||||
replies = {:id => memo.id, :content => memo.content, :time => time_from_now(memo.created_at), :user_id => memo.author_id,
|
||||
:image_url => "/images/#{url_to_avatar(memo.author)}?#{Time.now.to_i}", :username => memo.author.show_real_name, :reward => memo.reward, :hidden => memo.hidden,
|
||||
:image_url => "#{url_to_avatar(memo.author, true)}", :username => memo.author.show_real_name, :reward => memo.reward, :hidden => memo.hidden,
|
||||
:permission => permission, :praise_count => memo.praises_count, :user_praise => user_praise,
|
||||
:user_login => memo.author.try(:login), :admin => current_user&.admin, is_banned: is_banned, replies_count: memo.can_see_reply_count(current_user)}
|
||||
childrens = Memo.where(:parent_id => memo.id).includes(:author).reorder("created_at desc").limit(5)
|
||||
|
@ -777,7 +777,7 @@ class MemosService
|
|||
children_praise = child.praise_tread.exists?(user_id: current_user.try(:id).to_i)
|
||||
children_is_banned = user_is_banned?(child.author) #帖子的用户是否被禁言
|
||||
children_list << {:id => child.id, :content => child.content, :time => time_from_now(child.created_at),:praise_count => memo.praises_count, :user_praise => children_praise,
|
||||
:image_url => "/images/#{url_to_avatar(child.author)}?#{Time.now.to_i}", :username => child.author.show_real_name, :hidden => child.hidden, replies_count: child.can_see_reply_count(current_user),
|
||||
:image_url => "#{url_to_avatar(child.author,true)}?#{Time.now.to_i}", :username => child.author.show_real_name, :hidden => child.hidden, replies_count: child.can_see_reply_count(current_user),
|
||||
:permission => permission, :user_login => child.author.try(:login), :user_id => child.author.try(:id), :parent_id => child.parent_id, is_banned: children_is_banned}
|
||||
end
|
||||
list << replies.merge({children: children_list})
|
||||
|
|
|
@ -76,7 +76,7 @@ class UsersService
|
|||
block_lists.push({
|
||||
username: user.show_name,
|
||||
login: user.login,
|
||||
image_url: "/images/#{url_to_avatar(user)}?#{Time.now.to_i}",
|
||||
image_url: "#{url_to_avatar(user, true)}",
|
||||
brief: user&.user_extension.try(:brief_introduction)
|
||||
})
|
||||
end
|
||||
|
@ -275,7 +275,7 @@ class UsersService
|
|||
#id用户id
|
||||
def show_user(params)
|
||||
@user = User.find(params[:id])
|
||||
img_url = "/images/"+url_to_avatar(@user)
|
||||
img_url = url_to_avatar(@user, true)
|
||||
gender = @user.user_extension.gender.nil? ? 0 : @user.user_extension.gender
|
||||
work_unit = get_user_work_unit @user
|
||||
location = get_user_location @user
|
||||
|
@ -419,7 +419,7 @@ class UsersService
|
|||
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||
course_list = []
|
||||
membership.each do |mp|
|
||||
course_list << {:course => mp.course,:img_url => "/images/"+url_to_avatar(mp.course),:current_user_is_member => current_user.member_of_course?(mp.course),:current_user_is_teacher => is_course_teacher(current_user,mp.course)}
|
||||
course_list << {:course => mp.course,:img_url => +url_to_avatar(mp.course,true),:current_user_is_member => current_user.member_of_course?(mp.course),:current_user_is_teacher => is_course_teacher(current_user,mp.course)}
|
||||
end
|
||||
course_list
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'examination-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= user.real_name %></td>
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<% end %>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'identity-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
<% if user.from_sub_site? %>
|
||||
<span class="badge badge-pill badge-info">合作</span>
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'item-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= user.real_name %></td>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= link_to user&.real_name,"/users/#{user&.login}", target: "_blank" %></td>
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<% end %>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
<% if user.from_sub_site? %>
|
||||
<span class="badge badge-pill badge-info">合作</span>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= link_to user&.real_name,"/users/#{user&.login}", target: "_blank" %></td>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'subject-authorization-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= link_to user&.real_name,"/users/#{user&.login}", target: "_blank" %></td>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<div class="box user-edit-container">
|
||||
<div class="user-info mb-4 row">
|
||||
<%= link_to "/users/#{@user.login}", class: 'user-info-avatar col-md-1', target: '_blank', data: { toggle: 'tooltip', title: '个人中心' } do %>
|
||||
<img src="/images/<%= url_to_avatar(@user) %>" class="rounded-circle" width="80" height="80" />
|
||||
<img src="<%= url_to_avatar(@user, true) %>" class="rounded-circle" width="80" height="80" />
|
||||
<% end %>
|
||||
<div class="d-flex flex-column justify-content-between col-md-3 user-info-content">
|
||||
<div class="user-info-name flex"><%= @user.real_name %> | <%= @user.id %> | <%= @user.login %></div>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td>
|
||||
<%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
|
||||
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
|
||||
<img src="<%= url_to_avatar(user, true) %>" class="rounded-circle" width="40" height="40" />
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= link_to user&.real_name,"/users/#{user&.login}", target: "_blank" %></td>
|
||||
|
|
Loading…
Reference in New Issue