Add Memo API
This commit is contained in:
parent
fbec7a6e35
commit
141bf1a488
2
Gemfile
2
Gemfile
|
@ -14,7 +14,7 @@ gem 'turbolinks', '~> 5'
|
||||||
gem 'jbuilder', '~> 2.5'
|
gem 'jbuilder', '~> 2.5'
|
||||||
gem 'groupdate', '~> 4.1.0'
|
gem 'groupdate', '~> 4.1.0'
|
||||||
gem 'chartkick'
|
gem 'chartkick'
|
||||||
gem 'grape', '~> 0.9.0'
|
# gem 'grape', '~> 0.9.0'
|
||||||
gem 'grape-entity', '~> 0.7.1'
|
gem 'grape-entity', '~> 0.7.1'
|
||||||
gem 'kaminari', '~> 1.1', '>= 1.1.1'
|
gem 'kaminari', '~> 1.1', '>= 1.1.1'
|
||||||
|
|
||||||
|
|
30
Gemfile.lock
30
Gemfile.lock
|
@ -70,10 +70,6 @@ GEM
|
||||||
autoprefixer-rails (9.7.4)
|
autoprefixer-rails (9.7.4)
|
||||||
execjs
|
execjs
|
||||||
awesome_print (1.8.0)
|
awesome_print (1.8.0)
|
||||||
axiom-types (0.1.1)
|
|
||||||
descendants_tracker (~> 0.0.4)
|
|
||||||
ice_nine (~> 0.11.0)
|
|
||||||
thread_safe (~> 0.3, >= 0.3.1)
|
|
||||||
axlsx (3.0.0.pre)
|
axlsx (3.0.0.pre)
|
||||||
htmlentities (~> 4.3, >= 4.3.4)
|
htmlentities (~> 4.3, >= 4.3.4)
|
||||||
mimemagic (~> 0.3)
|
mimemagic (~> 0.3)
|
||||||
|
@ -109,15 +105,11 @@ GEM
|
||||||
archive-zip (~> 0.10)
|
archive-zip (~> 0.10)
|
||||||
nokogiri (~> 1.8)
|
nokogiri (~> 1.8)
|
||||||
chunky_png (1.3.11)
|
chunky_png (1.3.11)
|
||||||
coercible (1.0.0)
|
|
||||||
descendants_tracker (~> 0.0.1)
|
|
||||||
concurrent-ruby (1.1.6)
|
concurrent-ruby (1.1.6)
|
||||||
connection_pool (2.2.2)
|
connection_pool (2.2.2)
|
||||||
crass (1.0.6)
|
crass (1.0.6)
|
||||||
deep_cloneable (3.0.0)
|
deep_cloneable (3.0.0)
|
||||||
activerecord (>= 3.1.0, < 7)
|
activerecord (>= 3.1.0, < 7)
|
||||||
descendants_tracker (0.0.4)
|
|
||||||
thread_safe (~> 0.3, >= 0.3.1)
|
|
||||||
diff-lcs (1.3)
|
diff-lcs (1.3)
|
||||||
diffy (3.3.0)
|
diffy (3.3.0)
|
||||||
e2mmap (0.1.0)
|
e2mmap (0.1.0)
|
||||||
|
@ -131,7 +123,6 @@ GEM
|
||||||
multi_json
|
multi_json
|
||||||
enumerize (2.3.1)
|
enumerize (2.3.1)
|
||||||
activesupport (>= 3.2)
|
activesupport (>= 3.2)
|
||||||
equalizer (0.0.11)
|
|
||||||
erubi (1.9.0)
|
erubi (1.9.0)
|
||||||
execjs (2.7.0)
|
execjs (2.7.0)
|
||||||
faraday (0.15.4)
|
faraday (0.15.4)
|
||||||
|
@ -141,16 +132,6 @@ GEM
|
||||||
sass (>= 3.2)
|
sass (>= 3.2)
|
||||||
globalid (0.4.2)
|
globalid (0.4.2)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
grape (0.9.0)
|
|
||||||
activesupport
|
|
||||||
builder
|
|
||||||
hashie (>= 2.1.0)
|
|
||||||
multi_json (>= 1.3.2)
|
|
||||||
multi_xml (>= 0.5.2)
|
|
||||||
rack (>= 1.3.0)
|
|
||||||
rack-accept
|
|
||||||
rack-mount
|
|
||||||
virtus (>= 1.0.0)
|
|
||||||
grape-entity (0.7.1)
|
grape-entity (0.7.1)
|
||||||
activesupport (>= 4.0)
|
activesupport (>= 4.0)
|
||||||
multi_json (>= 1.3.2)
|
multi_json (>= 1.3.2)
|
||||||
|
@ -164,7 +145,6 @@ GEM
|
||||||
multi_xml (>= 0.5.2)
|
multi_xml (>= 0.5.2)
|
||||||
i18n (1.8.2)
|
i18n (1.8.2)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
ice_nine (0.11.2)
|
|
||||||
io-like (0.3.1)
|
io-like (0.3.1)
|
||||||
jaro_winkler (1.5.4)
|
jaro_winkler (1.5.4)
|
||||||
jbuilder (2.10.0)
|
jbuilder (2.10.0)
|
||||||
|
@ -244,14 +224,10 @@ GEM
|
||||||
public_suffix (4.0.3)
|
public_suffix (4.0.3)
|
||||||
puma (3.12.2)
|
puma (3.12.2)
|
||||||
rack (2.0.9)
|
rack (2.0.9)
|
||||||
rack-accept (0.4.5)
|
|
||||||
rack (>= 0.4)
|
|
||||||
rack-cors (1.1.1)
|
rack-cors (1.1.1)
|
||||||
rack (>= 2.0.0)
|
rack (>= 2.0.0)
|
||||||
rack-mini-profiler (2.0.1)
|
rack-mini-profiler (2.0.1)
|
||||||
rack (>= 1.2.0)
|
rack (>= 1.2.0)
|
||||||
rack-mount (0.8.3)
|
|
||||||
rack (>= 1.0.0)
|
|
||||||
rack-protection (2.0.8.1)
|
rack-protection (2.0.8.1)
|
||||||
rack
|
rack
|
||||||
rack-test (1.1.0)
|
rack-test (1.1.0)
|
||||||
|
@ -441,11 +417,6 @@ GEM
|
||||||
uglifier (4.2.0)
|
uglifier (4.2.0)
|
||||||
execjs (>= 0.3.0, < 3)
|
execjs (>= 0.3.0, < 3)
|
||||||
unicode-display_width (1.6.1)
|
unicode-display_width (1.6.1)
|
||||||
virtus (1.0.5)
|
|
||||||
axiom-types (~> 0.1)
|
|
||||||
coercible (~> 1.0)
|
|
||||||
descendants_tracker (~> 0.0, >= 0.0.3)
|
|
||||||
equalizer (~> 0.0, >= 0.0.9)
|
|
||||||
web-console (3.7.0)
|
web-console (3.7.0)
|
||||||
actionview (>= 5.0)
|
actionview (>= 5.0)
|
||||||
activemodel (>= 5.0)
|
activemodel (>= 5.0)
|
||||||
|
@ -485,7 +456,6 @@ DEPENDENCIES
|
||||||
faraday (~> 0.15.4)
|
faraday (~> 0.15.4)
|
||||||
font-awesome-sass (= 4.7.0)
|
font-awesome-sass (= 4.7.0)
|
||||||
gitlab!
|
gitlab!
|
||||||
grape (~> 0.9.0)
|
|
||||||
grape-entity (~> 0.7.1)
|
grape-entity (~> 0.7.1)
|
||||||
groupdate (~> 4.1.0)
|
groupdate (~> 4.1.0)
|
||||||
harmonious_dictionary (~> 0.0.1)
|
harmonious_dictionary (~> 0.0.1)
|
||||||
|
|
|
@ -1,107 +0,0 @@
|
||||||
#coding=utf-8
|
|
||||||
# status值
|
|
||||||
# 0:成功;-1:500错误;403:无权限;404:页面不存在
|
|
||||||
|
|
||||||
module Mobile
|
|
||||||
require_relative 'middleware/error_handler'
|
|
||||||
require_relative 'apis/auth'
|
|
||||||
require_relative 'apis/memos'
|
|
||||||
require_relative 'apis/forum_sections'
|
|
||||||
require_relative 'apis/my_memos'
|
|
||||||
# require_relative 'apis/my_forums'
|
|
||||||
|
|
||||||
class API < Grape::API
|
|
||||||
version 'v1', using: :path
|
|
||||||
format :json
|
|
||||||
content_type :json, "application/json;charset=UTF-8"
|
|
||||||
# use ActionDispatch::Session::CookieStore
|
|
||||||
use Middleware::ErrorHandler
|
|
||||||
|
|
||||||
helpers do
|
|
||||||
def logger
|
|
||||||
API.logger
|
|
||||||
end
|
|
||||||
|
|
||||||
def authenticate!
|
|
||||||
begin
|
|
||||||
# current_user = User.find(2) if current_user.blank?
|
|
||||||
if params[:debug] == 'admin'
|
|
||||||
logger.info("Login as admin user, for test only")
|
|
||||||
User.current = User.find 1
|
|
||||||
elsif params[:debug] == 'normal'
|
|
||||||
logger.info("Login as normal user, for test only")
|
|
||||||
User.current = User.where(admin:false).first
|
|
||||||
end
|
|
||||||
rescue Exception => e
|
|
||||||
return {:status => -2, :message => 'Unauthorized. 用户认证失败.'}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
# def manager_of_game
|
|
||||||
# myshixun_id = Game.where(:identifier => params[:identifier]).pluck(:myshixun_id).first
|
|
||||||
# myshixun = Myshixun.find(myshixun_id)
|
|
||||||
# unless (current_user.admin? || myshixun.user_id == current_user.id)
|
|
||||||
# return {}
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
def session
|
|
||||||
env['rack.session']
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_user
|
|
||||||
openid = session[:wechat_openid]
|
|
||||||
if openid
|
|
||||||
uw = UserWechat.find_by_openid(openid)
|
|
||||||
return uw.user if uw
|
|
||||||
end
|
|
||||||
|
|
||||||
token = ApiKey.where(access_token: params[:token]).first
|
|
||||||
if token && !token.expired?
|
|
||||||
return User.find(token.user_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
# 本地调试找不到用户信息
|
|
||||||
if Rails.env.development? && session[:user_id].blank?
|
|
||||||
# session[:user_id] = 12 #116
|
|
||||||
end
|
|
||||||
|
|
||||||
if session[:user_id].blank? || params[:debug].present?
|
|
||||||
if params[:debug] == 'admin'
|
|
||||||
Rails.logger.info("######________session_user_id________#############{session[:user_id]}")
|
|
||||||
logger.info("Login as admin user, for test only")
|
|
||||||
User.current = User.find 1
|
|
||||||
session[:user_id] = 1
|
|
||||||
elsif params[:debug] == 'normal'
|
|
||||||
logger.info("Login as normal user, for test only")
|
|
||||||
User.current = User.find 49
|
|
||||||
session[:user_id] = 49
|
|
||||||
else
|
|
||||||
session[:user_id] = 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Rails.logger.info("####### session user_id is #{session[:user_id]}")
|
|
||||||
if session[:user_id]
|
|
||||||
user = (User.find(session[:user_id]) rescue nil)
|
|
||||||
return user if user
|
|
||||||
end
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_user_ip
|
|
||||||
env['REMOTE_ADDR']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
mount Apis::Auth
|
|
||||||
mount Apis::Memos
|
|
||||||
mount Apis::ForumSections
|
|
||||||
mount Apis::MyMemos
|
|
||||||
# add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
#coding=utf-8
|
|
||||||
|
|
||||||
module Mobile
|
|
||||||
|
|
||||||
module Entities
|
|
||||||
class Auth < Grape::Entity
|
|
||||||
expose :token
|
|
||||||
expose :user, using: User
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module Apis
|
|
||||||
class Auth < Grape::API
|
|
||||||
resource :auth do
|
|
||||||
desc "用户登录"
|
|
||||||
params do
|
|
||||||
requires :login, type: String, desc: 'Username or email'
|
|
||||||
requires :password, type: String, desc: 'Password'
|
|
||||||
end
|
|
||||||
post do
|
|
||||||
user,last_logon = ::User.try_to_login(params[:login], params[:password])
|
|
||||||
if user
|
|
||||||
::ApiKey.delete_all(user_id: user.id)
|
|
||||||
key = ::ApiKey.create!(user_id: user.id)
|
|
||||||
api_user = ::UsersService.new.show_user({id:user.id})
|
|
||||||
present :data, {token: key.access_token, user: api_user}, using: Entities::Auth
|
|
||||||
present :status, 0
|
|
||||||
else
|
|
||||||
present :message, "无效的用户名或密码"
|
|
||||||
present :status,1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "用户登出"
|
|
||||||
params do
|
|
||||||
requires :token, type: String
|
|
||||||
end
|
|
||||||
delete do
|
|
||||||
authenticate!
|
|
||||||
::ApiKey.delete_all(user_id: current_user.id)
|
|
||||||
{status: 0}
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "忘记密码"
|
|
||||||
params do
|
|
||||||
requires :mail,type: String
|
|
||||||
end
|
|
||||||
post 'lost_password' do
|
|
||||||
us = UsersService.new
|
|
||||||
message = us.lost_password params
|
|
||||||
present :message, message
|
|
||||||
present :status, 0
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
@ -1,199 +0,0 @@
|
||||||
#coding=utf-8
|
|
||||||
module Mobile
|
|
||||||
module Apis
|
|
||||||
class ForumSections < Grape::API
|
|
||||||
before {authenticate!}
|
|
||||||
content_type :json, 'application/json;charset=UTF-8'
|
|
||||||
|
|
||||||
resources :forum_sections do
|
|
||||||
|
|
||||||
desc "获取板块的筛选分类"
|
|
||||||
get "select_sections" do
|
|
||||||
ForumSectionsService.new.select_sections
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "获取板块的全部分类"
|
|
||||||
get do
|
|
||||||
ForumSectionsService.new.index params
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "申请版主"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "user_apply" do
|
|
||||||
ForumSectionsService.new.user_apply params, current_user, current_user_ip
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "发布公告"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :content, type: String, desc: "公告的内容"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "edit_notice" do
|
|
||||||
ForumSectionsService.new.edit_notice params
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "版块的头部信息"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "forum_section_header" do
|
|
||||||
ForumSectionsService.new.forum_section_header params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "新增二级版块"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :title, type: String, desc: "版块的名称"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post 'create' do
|
|
||||||
ForumSectionsService.new.create params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "重命名"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :children_section_id, type: Integer, desc: "二级版块的id"
|
|
||||||
requires :title, type: String, desc: "版块的名称"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "rename" do
|
|
||||||
ForumSectionsService.new.rename params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "删除二级版块"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :children_section_id, type: Integer, desc: "二级版块的id"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "destroy" do
|
|
||||||
ForumSectionsService.new.destroy params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "排序"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :order_type, type: String, desc: "排序按desc,和asc排序"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "order_forums" do
|
|
||||||
ForumSectionsService.new.order_forums params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "搜索用户"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :page, type: Integer, desc: "初次(第一页)为0"
|
|
||||||
# requires :user_name, type: String, desc: "输入的关键字"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "search_users" do
|
|
||||||
ForumSectionsService.new.search_users params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "二级版块添加管理员"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :user_ids, type: Array, desc: "输入的关键字"
|
|
||||||
requires :children_section_id, type: Integer, desc: "二级版块的id"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "add_users" do
|
|
||||||
ForumSectionsService.new.add_users params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
desc "管理员页面的版块管理"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "managements" do
|
|
||||||
ForumSectionsService.new.managements params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "管理员页面的申请接口"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "applied_forums" do
|
|
||||||
ForumSectionsService.new.applied_forums params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "管理员页面的申请处理"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :apply_id, type: Integer, desc: "申请的id"
|
|
||||||
requires :deal_type, type: Integer, desc: "处理的方式,1为同意,2为拒绝"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "deal_applies/:apply_id" do
|
|
||||||
ForumSectionsService.new.deal_applies params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "管理员页面的删除二级版主"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的id"
|
|
||||||
requires :moderator_id, type: Integer, desc: "版主的id"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "destroy_moderator/:moderator_id" do
|
|
||||||
ForumSectionsService.new.destroy_moderator params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "待审核的帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的待审核id"
|
|
||||||
requires :page, type: String, desc: "初次(第一页)为0"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "unchecked_memos" do
|
|
||||||
ForumSectionsService.new.unchecked_memos params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "待审查的回复"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的待审核id"
|
|
||||||
requires :page, type: String, desc: "初次(第一页)为0"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "unchecked_replies" do
|
|
||||||
ForumSectionsService.new.unchecked_replies params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "已发布的帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的待审核id"
|
|
||||||
requires :page, type: String, desc: "初次(第一页)为0"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "checked_memos" do
|
|
||||||
ForumSectionsService.new.checked_memos params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,241 +0,0 @@
|
||||||
# encoding=utf-8
|
|
||||||
module Mobile
|
|
||||||
module Apis
|
|
||||||
class Memos < Grape::API
|
|
||||||
before {authenticate!}
|
|
||||||
content_type :json, 'application/json;charset=UTF-8'
|
|
||||||
|
|
||||||
resources :memos do
|
|
||||||
|
|
||||||
desc "帖子详情推荐"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子详情推荐"
|
|
||||||
end
|
|
||||||
get ':id/related_memos' do
|
|
||||||
MemosService.new.related_memos params
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "新建帖子"
|
|
||||||
get 'new' do
|
|
||||||
MemosService.new.new params, current_user, session
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "新建保存帖子"
|
|
||||||
params do
|
|
||||||
requires :memo, type: Hash do
|
|
||||||
requires :subject, type: String, desc: "帖子名"
|
|
||||||
requires :content, type: String, desc: "帖子内容"
|
|
||||||
end
|
|
||||||
requires :forum_id, type: Integer, desc: "帖子类型"
|
|
||||||
end
|
|
||||||
post 'create' do
|
|
||||||
MemosService.new.create params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "帖子详情"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
end
|
|
||||||
get ':id' do
|
|
||||||
MemosService.new.show params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "收藏帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
requires :is_watch, type: Integer, desc:"顶置: 1 关注,0 取消关注 "
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post 'watch_memo' do
|
|
||||||
MemosService.new.watch_memo params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "讨论区列表"
|
|
||||||
get do
|
|
||||||
MemosService.new.index params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "编辑帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "编辑帖子的ID"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get 'edit' do
|
|
||||||
MemosService.new.edit params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "更新帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post 'update' do
|
|
||||||
MemosService.new.update params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO 本来可以跟实训评论一起用,但说不要动实训,所以另起一个方法
|
|
||||||
desc "隐藏帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get :hidden do
|
|
||||||
Memo.find(params[:id]).update_attribute(:hidden, true)
|
|
||||||
{status: 0, message: "隐藏成功"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "帖子设置审核通过/不通过"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post :memo_hidden do
|
|
||||||
MemosService.new.memo_hidden params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "回复帖子"
|
|
||||||
params do
|
|
||||||
requires :parent_id, type: Integer, desc: "给那个帖子的回复id"
|
|
||||||
requires :content, type: String, desc: "回复内容"
|
|
||||||
end
|
|
||||||
route_param :root_id do
|
|
||||||
post :reply do
|
|
||||||
MemosService.new.reply params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "隐藏回复帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "要隐藏的对象id。如:memo.id"
|
|
||||||
requires :hidden, type: String
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post 'hidden' do
|
|
||||||
MemosService.new.hidden(params, current_user)
|
|
||||||
return {:status => 1, :message => "success"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "删除帖子/评论"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "destroy" do
|
|
||||||
MemosService.new.destroy params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# delete ":id" do
|
|
||||||
# Memo.find(params[:id]).destroy
|
|
||||||
# end
|
|
||||||
|
|
||||||
desc "设置贴子顶置/取消顶置"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
requires :sticky, type: Integer, desc:"顶置: 1 置顶,0 取消置顶 "
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "set-top-or-down" do
|
|
||||||
MemosService.new.set_top_or_down params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "设置贴子加精/取消加精推荐"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
requires :is_fine, type: Integer, desc:"加精: 1 加精,0 取消加精 "
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "is_fine" do
|
|
||||||
MemosService.new.is_fine params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "用户禁言或取消禁言"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
requires :user_id, type: Integer, desc:"被禁言用户的id"
|
|
||||||
requires :banned, type: Integer, desc:"顶置: 1 禁言,0 取消禁言 "
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
post "banned_user" do
|
|
||||||
MemosService.new.banned_user params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "帖子回复更多"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子ID"
|
|
||||||
requires :page, type: String, desc: "初次(第一页)为0"
|
|
||||||
end
|
|
||||||
route_param :id do
|
|
||||||
get "more_reply" do
|
|
||||||
MemosService.new.more_reply params, current_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "版块的全部帖子"
|
|
||||||
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的ID"
|
|
||||||
requires :page, type: String, desc: "初次(第一页)为0"
|
|
||||||
# requires :forum_type, type: String, desc: "列表页的分类选择"
|
|
||||||
end
|
|
||||||
get "forum_memos/:id" do
|
|
||||||
MemosService.new.forum_memos params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "版块的头部信息"
|
|
||||||
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的ID"
|
|
||||||
end
|
|
||||||
get "forum_memos_head/:id" do
|
|
||||||
MemosService.new.forum_memos_head params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "版块的右侧信息"
|
|
||||||
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的ID"
|
|
||||||
end
|
|
||||||
get "forum_memos_right/:id" do
|
|
||||||
MemosService.new.forum_memos_right params, current_user
|
|
||||||
end
|
|
||||||
# route_param :id do
|
|
||||||
#
|
|
||||||
# end
|
|
||||||
desc "版块的关注"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "版块的ID"
|
|
||||||
requires :is_watch, type: Integer, desc:"顶置: 1 关注,0 取消关注 "
|
|
||||||
end
|
|
||||||
post "forum_memos/:id/is_watch" do
|
|
||||||
MemosService.new.is_watch params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "申请删除帖子"
|
|
||||||
params do
|
|
||||||
requires :id, type: Integer, desc: "帖子的id"
|
|
||||||
end
|
|
||||||
post ":id/confirm_delete" do
|
|
||||||
MemosService.new.confirm_delete params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# desc "版块的首页"
|
|
||||||
# params do
|
|
||||||
# requires :page, type: String, desc: "初次(第一页)为0"
|
|
||||||
# end
|
|
||||||
# get "index" do
|
|
||||||
# MemosService.new.index params, current_user
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,32 +0,0 @@
|
||||||
#coding=utf-8
|
|
||||||
module Mobile
|
|
||||||
module Apis
|
|
||||||
class MyMemos < Grape::API
|
|
||||||
before {authenticate!}
|
|
||||||
content_type :json, 'application/json;charset=UTF-8'
|
|
||||||
|
|
||||||
resources :my_memos do
|
|
||||||
desc "我的话题"
|
|
||||||
get ":login/memos" do
|
|
||||||
MyMemosService.new.index params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "我感兴趣的话题"
|
|
||||||
get ":login/my_interested" do
|
|
||||||
MyMemosService.new.my_interested params, current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "我的回帖"
|
|
||||||
get ":login/replies_memos" do
|
|
||||||
MyMemosService.new.replies_memos params,current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "右侧推荐"
|
|
||||||
get "recommend_memos" do
|
|
||||||
MyMemosService.new.recommend_memos current_user
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,13 +0,0 @@
|
||||||
#coding=utf-8
|
|
||||||
#
|
|
||||||
module Mobile
|
|
||||||
module Exceptions
|
|
||||||
class AuthException < StandardError
|
|
||||||
attr_reader :err_code, :msg
|
|
||||||
def initialize(code, msg)
|
|
||||||
@err_code = code
|
|
||||||
@msg = msg
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,26 +0,0 @@
|
||||||
#coding=utf-8
|
|
||||||
|
|
||||||
|
|
||||||
module Mobile
|
|
||||||
module Middleware
|
|
||||||
class ErrorHandler < Grape::Middleware::Base
|
|
||||||
def call!(env)
|
|
||||||
@env = env
|
|
||||||
begin
|
|
||||||
@app.call(@env)
|
|
||||||
rescue =>e
|
|
||||||
code = -1
|
|
||||||
|
|
||||||
message = {status: code, message: e.message }.to_json
|
|
||||||
|
|
||||||
Rails.logger.error e.inspect
|
|
||||||
Rails.logger.error e.backtrace.join("\n")
|
|
||||||
status = 200
|
|
||||||
headers = { 'Content-Type' => content_type }
|
|
||||||
Rack::Response.new([message], status, headers).finish
|
|
||||||
# throw :error, :message => e.message || options[:default_message], :status => 500
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -43,7 +43,7 @@ class Admins::ForumModeratorsController < Admins::BaseController
|
||||||
users = User.where("( LOWER(login) LIKE ? or LOWER(concat(lastname, firstname)) LIKE ? or LOWER(mail) LIKE ? )",
|
users = User.where("( LOWER(login) LIKE ? or LOWER(concat(lastname, firstname)) LIKE ? or LOWER(mail) LIKE ? )",
|
||||||
"%#{user_name}%","%#{user_name}%","%#{user_name}%")
|
"%#{user_name}%","%#{user_name}%","%#{user_name}%")
|
||||||
users.each do |u|
|
users.each do |u|
|
||||||
check_html = "<input id='check_user_#{u.login}' class='magic-checkbox' type='checkbox' name='member_ids[]' value=""#{u.id}"" checked='false'><label for='check_user_#{u.login}'>#{u.try(:show_name)}</label>"
|
check_html = "<input id='check_user_#{u.login}' class='magic-checkbox' type='checkbox' name='member_ids[]' value=""#{u.id}"" checked='false'><label for='check_user_#{u.login}'>#{u.try(:show_real_name)}</label>"
|
||||||
return_html << check_html
|
return_html << check_html
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
class ForumSectionsController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
targets = ForumSectionsService.new.index params
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def select_sections
|
||||||
|
targets = ForumSectionsService.new.select_sections
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_apply
|
||||||
|
targets = ForumSectionsService.new.user_apply params, current_user, current_user_ip
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit_notice
|
||||||
|
targets = ForumSectionsService.new.edit_notice params
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def forum_section_header
|
||||||
|
targets = ForumSectionsService.new.forum_section_header params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
targets = ForumSectionsService.new.create params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def rename
|
||||||
|
targets = ForumSectionsService.new.rename params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
targets = ForumSectionsService.new.destroy params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def order_forums
|
||||||
|
targets = ForumSectionsService.new.order_forums params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def search_users
|
||||||
|
targets = ForumSectionsService.new.search_users params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_users
|
||||||
|
targets = ForumSectionsService.new.add_users params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def managements
|
||||||
|
targets = ForumSectionsService.new.managements params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def applied_forums
|
||||||
|
targets = ForumSectionsService.new.applied_forums params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def deal_applies
|
||||||
|
targets = ForumSectionsService.new.deal_applies params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_moderator
|
||||||
|
targets = ForumSectionsService.new.destroy_moderator params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def unchecked_memos
|
||||||
|
targets = ForumSectionsService.new.unchecked_memos params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def unchecked_replies
|
||||||
|
targets = ForumSectionsService.new.unchecked_replies params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def checked_memos
|
||||||
|
targets = ForumSectionsService.new.checked_memos params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_user_ip
|
||||||
|
env['REMOTE_ADDR']
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,109 @@
|
||||||
|
class MemosController < ApplicationController
|
||||||
|
before_action :require_login, only: [:create, :edit, :update, :watch_memo]
|
||||||
|
|
||||||
|
def index
|
||||||
|
memos = MemosService.new.index params, current_user
|
||||||
|
render json: memos
|
||||||
|
end
|
||||||
|
|
||||||
|
def related_memos
|
||||||
|
targets = MemosService.new.related_memos params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
targets = MemosService.new.edit params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
targets = MemosService.new.update params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
params.permit!
|
||||||
|
targets = MemosService.new.create params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
targets = MemosService.new.show params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def watch_memo
|
||||||
|
targets = MemosService.new.watch_memo params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def hidden
|
||||||
|
Memo.find(params[:id]).update_attribute(:hidden, true)
|
||||||
|
{status: 0, message: "隐藏成功"}
|
||||||
|
end
|
||||||
|
|
||||||
|
def memo_hidden
|
||||||
|
targets = MemosService.new.memo_hidden params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def reply
|
||||||
|
targets = MemosService.new.reply params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
targets = MemosService.new.destroy params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_top_or_down
|
||||||
|
targets = MemosService.new.set_top_or_down params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_fine
|
||||||
|
targets = MemosService.new.is_fine params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def banned_user
|
||||||
|
targets = MemosService.new.banned_user params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def more_reply
|
||||||
|
targets = MemosService.new.more_reply params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def forum_memos
|
||||||
|
targets = MemosService.new.forum_memos params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def forum_memos_head
|
||||||
|
targets = MemosService.new.forum_memos_head params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def forum_memos_right
|
||||||
|
targets = MemosService.new.forum_memos_right params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_watch
|
||||||
|
targets = MemosService.new.is_watch params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def confirm_delete
|
||||||
|
targets = MemosService.new.confirm_delete params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def plus
|
||||||
|
targets = MemosService.new.plus params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,22 @@
|
||||||
|
class MyMemosController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
targets = MyMemosService.new.index params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def my_interested
|
||||||
|
targets = MyMemosService.new.my_interested params, current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def replies_memos
|
||||||
|
targets = MyMemosService.new.replies_memos params,current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
|
||||||
|
def recommend_memos
|
||||||
|
targets = MyMemosService.new.recommend_memos current_user
|
||||||
|
render json: targets
|
||||||
|
end
|
||||||
|
end
|
|
@ -38,12 +38,12 @@ module ApiHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def stars_to_json_like starts,show_jour,homework,show_name
|
def stars_to_json_like starts,show_jour,homework,show_real_name
|
||||||
result = []
|
result = []
|
||||||
starts.each do |s|
|
starts.each do |s|
|
||||||
comment = get_homework_review homework,show_jour,s.rater
|
comment = get_homework_review homework,show_jour,s.rater
|
||||||
rater_name = show_name ? s.rater.login : l(:label_anonymous)
|
rater_name = show_real_name ? s.rater.login : l(:label_anonymous)
|
||||||
rater_id = show_name ? s.rater.id : ''
|
rater_id = show_real_name ? s.rater.id : ''
|
||||||
result << {:rater_id =>rater_id ,:rater_name => rater_name,:created_at => format_time(s.created_at),:stars => s.stars,:comment => comment}
|
result << {:rater_id =>rater_id ,:rater_name => rater_name,:created_at => format_time(s.created_at),:stars => s.stars,:comment => comment}
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
|
|
|
@ -8,7 +8,7 @@ module ApiIndexHelper
|
||||||
|
|
||||||
def format_for_current_user(current_user)
|
def format_for_current_user(current_user)
|
||||||
if current_user.present? && (current_user.id != 2)
|
if current_user.present? && (current_user.id != 2)
|
||||||
{username: current_user.show_name,
|
{username: current_user.show_real_name,
|
||||||
login: current_user.login,
|
login: current_user.login,
|
||||||
user_id: current_user.id,
|
user_id: current_user.id,
|
||||||
image_url: "/images/#{url_to_avatar(current_user)}?#{Time.now.to_i}",
|
image_url: "/images/#{url_to_avatar(current_user)}?#{Time.now.to_i}",
|
||||||
|
@ -23,7 +23,7 @@ module ApiIndexHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_common_user(user)
|
def format_common_user(user)
|
||||||
{username: user.show_name,
|
{username: user.show_real_name,
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
login: user.login,
|
login: user.login,
|
||||||
image_url: "/images/#{url_to_avatar(user)}?#{Time.now.to_i}",
|
image_url: "/images/#{url_to_avatar(user)}?#{Time.now.to_i}",
|
||||||
|
@ -92,7 +92,7 @@ module ApiIndexHelper
|
||||||
moderator_id: moder.id,
|
moderator_id: moder.id,
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
login: user.login,
|
login: user.login,
|
||||||
username: user.try(:show_name),
|
username: user.try(:show_real_name),
|
||||||
image_url: url_to_avatar(user),
|
image_url: url_to_avatar(user),
|
||||||
user_url: "/users/#{user.try(:login)}"
|
user_url: "/users/#{user.try(:login)}"
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,9 @@ module ApiIndexHelper
|
||||||
memo_parent_id = memo.parent_id
|
memo_parent_id = memo.parent_id
|
||||||
memo_parent_type = "Memo"
|
memo_parent_type = "Memo"
|
||||||
end
|
end
|
||||||
admin_role_ids= AdminRole.includes(:admin_permissions).joins(:admin_permissions).where("admin_permissions.name = '#{type}'").pluck(:id)
|
user_ids = User.select(:admin, :id).admin_users.pluck(:id)
|
||||||
user_ids = UserAdminRole.where(admin_role_id: admin_role_ids).pluck(:user_id).uniq
|
# admin_role_ids= AdminRole.includes(:admin_permissions).joins(:admin_permissions).where("admin_permissions.name = '#{type}'").pluck(:id)
|
||||||
|
# user_ids = UserAdminRole.where(admin_role_id: admin_role_ids).pluck(:user_id).uniq
|
||||||
if user_ids.size > 0
|
if user_ids.size > 0
|
||||||
user_ids.each do |id|
|
user_ids.each do |id|
|
||||||
Tiding.create(:user_id => id, :trigger_user_id => memo.author_id,
|
Tiding.create(:user_id => id, :trigger_user_id => memo.author_id,
|
||||||
|
@ -221,7 +222,7 @@ module ApiIndexHelper
|
||||||
last_memo = memo&.last_reply_memo(show_hidden_memo)
|
last_memo = memo&.last_reply_memo(show_hidden_memo)
|
||||||
if last_memo
|
if last_memo
|
||||||
new_reply = {
|
new_reply = {
|
||||||
username: last_memo&.author.try(:show_name),
|
username: last_memo&.author.try(:show_real_name),
|
||||||
user_login: last_memo&.author.try(:login),
|
user_login: last_memo&.author.try(:login),
|
||||||
user_id: last_memo&.author.try(:id),
|
user_id: last_memo&.author.try(:id),
|
||||||
content: last_memo&.content,
|
content: last_memo&.content,
|
||||||
|
@ -240,7 +241,7 @@ module ApiIndexHelper
|
||||||
sticky: memo.sticky,
|
sticky: memo.sticky,
|
||||||
is_fine: memo.is_fine,
|
is_fine: memo.is_fine,
|
||||||
is_original: memo.is_original,
|
is_original: memo.is_original,
|
||||||
username: memo.author.show_name,
|
username: memo.author.show_real_name,
|
||||||
image_url: "#{url_to_avatar(memo.author)}?#{Time.now.to_i}",
|
image_url: "#{url_to_avatar(memo.author)}?#{Time.now.to_i}",
|
||||||
user_login: memo.author.try(:login),
|
user_login: memo.author.try(:login),
|
||||||
user_id: memo.author.try(:id),
|
user_id: memo.author.try(:id),
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
class BlockUser < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
scope :block_user_present, ->(target_id){where(block_user_id: target_id)}
|
||||||
|
end
|
|
@ -4,14 +4,18 @@ module Watchable
|
||||||
included do
|
included do
|
||||||
has_many :watchers, as: :watchable, dependent: :destroy
|
has_many :watchers, as: :watchable, dependent: :destroy
|
||||||
has_many :watcher_users, through: :watchers, source: :user, validate: false
|
has_many :watcher_users, through: :watchers, source: :user, validate: false
|
||||||
|
|
||||||
scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) }
|
scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) }
|
||||||
|
attr_reader :watcher_ids, :watcher_user_ids
|
||||||
end
|
end
|
||||||
|
|
||||||
def watched?(watchable)
|
def watched?(watchable)
|
||||||
watchable.watchers.exists?(user: self)
|
watchable.watchers.exists?(user: self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def watched_by?(user)
|
||||||
|
!!(user && self.watcher_user_ids && self.watcher_user_ids.detect {|uid| uid == user.id })
|
||||||
|
end
|
||||||
|
|
||||||
def watch!(watchable)
|
def watch!(watchable)
|
||||||
watchable.watchers.create!(user: self, created_at: Time.current)
|
watchable.watchers.create!(user: self, created_at: Time.current)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class ForumSection < ApplicationRecord
|
class ForumSection < ApplicationRecord
|
||||||
|
include Watchable
|
||||||
has_ancestry
|
has_ancestry
|
||||||
#论坛板块的表
|
#论坛板块的表
|
||||||
# attr_accessible :title, :body
|
# attr_accessible :title, :body
|
||||||
|
|
|
@ -4,16 +4,12 @@
|
||||||
# is_fine 是否加精,默认为false
|
# is_fine 是否加精,默认为false
|
||||||
# hidden 是否隐藏
|
# hidden 是否隐藏
|
||||||
|
|
||||||
# require 'elasticsearch/model'
|
|
||||||
class Memo < ApplicationRecord
|
class Memo < ApplicationRecord
|
||||||
# include Redmine::SafeAttributes
|
|
||||||
# include UserScoreHelper
|
|
||||||
include ApplicationHelper, Watchable
|
include ApplicationHelper, Watchable
|
||||||
# include Elasticsearch::Model
|
|
||||||
#敏感词过滤
|
#敏感词过滤
|
||||||
# include DunCheckAble
|
# include DunCheckAble
|
||||||
has_many :forums, :through => :memo_forums
|
has_many :forums, :through => :memo_forums
|
||||||
belongs_to :forum_section, counter_cache: true
|
belongs_to :forum_section, counter_cache: true, optional: true
|
||||||
has_many :memo_forums, :dependent => :destroy
|
has_many :memo_forums, :dependent => :destroy
|
||||||
has_many :visit_actions, as: :visitable, dependent: :destroy
|
has_many :visit_actions, as: :visitable, dependent: :destroy
|
||||||
#用户是否禁言
|
#用户是否禁言
|
||||||
|
@ -30,39 +26,9 @@ class Memo < ApplicationRecord
|
||||||
|
|
||||||
scope :total_replies, ->{where("hidden = false and root_id is not null")}
|
scope :total_replies, ->{where("hidden = false and root_id is not null")}
|
||||||
# scope :roots, -> {where()}
|
# scope :roots, -> {where()}
|
||||||
|
has_many :attachments, as: :container, dependent: :destroy
|
||||||
# 创意征集方式 0-默认,1-申请, ps. 删除后,该帖子即删除, 拒绝后,该帖子状态将为初始状态
|
# 创意征集方式 0-默认,1-申请, ps. 删除后,该帖子即删除, 拒绝后,该帖子状态将为初始状态
|
||||||
enum destroy_status: { common: 0, apply_destroy: 1 }
|
enum destroy_status: { common: 0, apply_destroy: 1 }
|
||||||
# acts_as_watchable
|
|
||||||
#elasticsearch kaminari init
|
|
||||||
# Kaminari::Hooks.init
|
|
||||||
# Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
|
|
||||||
# settings index: {
|
|
||||||
# number_of_shards: 5 ,
|
|
||||||
# analysis: {
|
|
||||||
# char_filter: {
|
|
||||||
# and_filter: {
|
|
||||||
# type: "mapping",
|
|
||||||
# mappings: [ "&=> and "]
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# analyzer: {
|
|
||||||
# my_analyzer: {
|
|
||||||
# type: 'custom',
|
|
||||||
# tokenizer: 'standard',
|
|
||||||
# filter: ['classic'],
|
|
||||||
# char_filter: ['html_strip']
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# } do
|
|
||||||
# mappings dynamic: 'false' do
|
|
||||||
# indexes :subject, analyzer: 'smartcn',index_options: 'offsets'#, char_filter: 'html_strip'
|
|
||||||
# indexes :content, analyzer:'my_analyzer',index_options: 'offsets',search_analyzer: 'smartcn'
|
|
||||||
# indexes :updated_at,index:"not_analyzed" ,type:'date'
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC", dependent: :destroy
|
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC", dependent: :destroy
|
||||||
# acts_as_attachable
|
# acts_as_attachable
|
||||||
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
|
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
|
||||||
|
@ -72,46 +38,7 @@ class Memo < ApplicationRecord
|
||||||
# 消息
|
# 消息
|
||||||
has_many :memo_messages, :class_name =>'MemoMessage', :dependent => :destroy
|
has_many :memo_messages, :class_name =>'MemoMessage', :dependent => :destroy
|
||||||
# end
|
# end
|
||||||
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id', optional: true
|
||||||
# acts_as_searchable :column => ['subject', 'content'],
|
|
||||||
# #:include => { :forum => :p}
|
|
||||||
# #:project_key => "#{Forum.table_name}.project_id"
|
|
||||||
# :date_column => "#{table_name}.created_at"
|
|
||||||
#acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"},
|
|
||||||
#:datetime => :updated_at,
|
|
||||||
# :datetime => :created_at,
|
|
||||||
#:description => :content,
|
|
||||||
#:author => :author,
|
|
||||||
#:type => Proc.new {|o| o.parent_id.nil? ? 'Memo' : 'Reply'},
|
|
||||||
#:url => Proc.new {|o| {:controller => 'memos', :action => 'show', :forum_id => o.forum_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :r => o.id, :anchor => "reply-#{o.id}"})}
|
|
||||||
# acts_as_activity_provider :author_key => :author_id,
|
|
||||||
# :func => 'memos',
|
|
||||||
# :timestamp => 'created_at'
|
|
||||||
# :find_options => {:type => 'memos'}
|
|
||||||
# acts_as_watchable
|
|
||||||
|
|
||||||
# safe_attributes "author_id",
|
|
||||||
# "subject",
|
|
||||||
# "content",
|
|
||||||
# "last_memo_id",
|
|
||||||
# "lock",
|
|
||||||
# "sticky",
|
|
||||||
# "parent_id",
|
|
||||||
# "replies_count",
|
|
||||||
# "root_id",
|
|
||||||
# "language"
|
|
||||||
|
|
||||||
# after_create :add_author_as_watcher, :reset_counters!, :send_tiding
|
|
||||||
# after_create :add_author_as_watcher #浏览记录
|
|
||||||
# after_update
|
|
||||||
# after_destroy :reset_counters!,:delete_kindeditor_assets #,:down_user_score -- 公共区发帖暂不计入得分,
|
|
||||||
# after_create :send_notification
|
|
||||||
# after_save :plusParentAndForum
|
|
||||||
# after_destroy :minusParentAndForum
|
|
||||||
#before_save :be_user_score
|
|
||||||
# scope :visible, lambda { |*args|
|
|
||||||
# includes(:forum => ).where()
|
|
||||||
# }
|
|
||||||
scope :indexable,lambda {
|
scope :indexable,lambda {
|
||||||
where('parent_id is null')
|
where('parent_id is null')
|
||||||
}
|
}
|
||||||
|
@ -136,34 +63,6 @@ class Memo < ApplicationRecord
|
||||||
where("#{time_type} between ? and ?",start_time.present? ? start_time.to_time : Time.now, end_time.present? ? end_time.to_time.end_of_day : Time.now)
|
where("#{time_type} between ? and ?",start_time.present? ? start_time.to_time : Time.now, end_time.present? ? end_time.to_time.end_of_day : Time.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# def self.search(query)
|
|
||||||
# __elasticsearch__.search(
|
|
||||||
# {
|
|
||||||
# query: {
|
|
||||||
# multi_match: {
|
|
||||||
# query: query,
|
|
||||||
# type:"most_fields",
|
|
||||||
# operator: "or",
|
|
||||||
# fields: ['subject','content^0.5']
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# sort: {
|
|
||||||
# _score:{order: "desc" },
|
|
||||||
# updated_at:{order: "desc" }
|
|
||||||
# },
|
|
||||||
# highlight: {
|
|
||||||
# pre_tags: ['<span class="c_red">'],
|
|
||||||
# post_tags: ['</span>'],
|
|
||||||
# fields: {
|
|
||||||
# subject: {},
|
|
||||||
# content: {}
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
# end
|
|
||||||
|
|
||||||
def memo_parent
|
def memo_parent
|
||||||
Memo.find(parent_id)
|
Memo.find(parent_id)
|
||||||
end
|
end
|
||||||
|
@ -201,11 +100,11 @@ class Memo < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hottest_five_memos
|
def self.hottest_five_memos
|
||||||
order("replies_count desc, praises_count desc, viewed_count desc").limit(8).select([:id,:subject])
|
order("replies_count desc, praises_count desc, viewed_count desc").limit(8).select(:id,:subject)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.recommend_five_memos
|
def self.recommend_five_memos
|
||||||
recommend_memos.order("updated_at desc").limit(8).select([:id,:subject])
|
recommend_memos.order("updated_at desc").limit(8).select(:id,:subject)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
class MemoMessage < ApplicationRecord
|
||||||
|
end
|
|
@ -14,6 +14,10 @@ class PraiseTread < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.is_user_praise(target_id,target_type, target_user_id)
|
||||||
|
where(:praise_tread_object_id => target_id, :praise_tread_object_type => target_type, :user_id => target_user_id, :praise_or_tread => 1)
|
||||||
|
end
|
||||||
|
|
||||||
def self.find_object_by_type_and_id(id, type)
|
def self.find_object_by_type_and_id(id, type)
|
||||||
type.constantize find_by_id id
|
type.constantize find_by_id id
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,6 +54,7 @@ class User < ApplicationRecord
|
||||||
has_one :qq_open_user, class_name: 'OpenUsers::QQ'
|
has_one :qq_open_user, class_name: 'OpenUsers::QQ'
|
||||||
accepts_nested_attributes_for :user_extension, update_only: true
|
accepts_nested_attributes_for :user_extension, update_only: true
|
||||||
has_many :fork_users, dependent: :destroy
|
has_many :fork_users, dependent: :destroy
|
||||||
|
has_many :block_users, :dependent => :destroy
|
||||||
|
|
||||||
has_many :versions
|
has_many :versions
|
||||||
has_many :issue_times, :dependent => :destroy
|
has_many :issue_times, :dependent => :destroy
|
||||||
|
@ -72,7 +73,7 @@ class User < ApplicationRecord
|
||||||
has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
|
has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
|
||||||
has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
|
has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
|
||||||
|
|
||||||
has_many :watchers, as: :watchable, dependent: :destroy
|
# has_many :watchers, as: :watchable, dependent: :destroy
|
||||||
|
|
||||||
# 认证
|
# 认证
|
||||||
has_many :apply_user_authentication
|
has_many :apply_user_authentication
|
||||||
|
@ -320,6 +321,10 @@ class User < ApplicationRecord
|
||||||
status == STATUS_LOCKED
|
status == STATUS_LOCKED
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.admin_users
|
||||||
|
where(admin: true)
|
||||||
|
end
|
||||||
|
|
||||||
def activate
|
def activate
|
||||||
self.status = STATUS_ACTIVE
|
self.status = STATUS_ACTIVE
|
||||||
end
|
end
|
||||||
|
@ -579,6 +584,10 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blocked_for(user_id)
|
||||||
|
block_users.where(block_user_id: user_id).exists?
|
||||||
|
end
|
||||||
|
|
||||||
def salt_password(clear_password)
|
def salt_password(clear_password)
|
||||||
self.salt = User.generate_salt
|
self.salt = User.generate_salt
|
||||||
self.hashed_password = User.hash_password("#{salt}#{User.hash_password clear_password}")
|
self.hashed_password = User.hash_password("#{salt}#{User.hash_password clear_password}")
|
||||||
|
|
|
@ -13,15 +13,15 @@
|
||||||
<%= image_tag(url_to_avatar(user),width:"50px",height:"50px",class:"radius mr15") %>
|
<%= image_tag(url_to_avatar(user),width:"50px",height:"50px",class:"radius mr15") %>
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
<li class="clearfix mb20">
|
<li class="clearfix mb20">
|
||||||
<%= link_to user.try(:show_name),user,class: "fl mr15 color-grey-3 font-16" %>
|
<%= link_to user.try(:show_real_name),user,class: "fl mr15 color-grey-3 font-16" %>
|
||||||
<span class="fl color-grey-9 mt3 mr15"><%= time_from_now(ban.updated_at) %></span>
|
<span class="fl color-grey-9 mt3 mr15"><%= time_from_now(ban.updated_at) %></span>
|
||||||
<span class="fl color-grey-9 mt3">第<span class="color-orange"><%= ban.banned_count %></span>次 被禁言</span>
|
<span class="fl color-grey-9 mt3">第<span class="color-orange"><%= ban.banned_count %></span>次 被禁言</span>
|
||||||
<span class="fr">
|
<span class="fr">
|
||||||
<% if @banned_type == "banned" %>
|
<% if @banned_type == "banned" %>
|
||||||
<% remove_ban_message = "是否确认解除"+"\"#{user.try(:show_name)}\""+"的禁言?" %>
|
<% remove_ban_message = "是否确认解除"+"\"#{user.try(:show_real_name)}\""+"的禁言?" %>
|
||||||
<%= link_to "取消禁言", "javascript:void(0)", class: "color-blue_4C", onclick: "custom_confirm_remote_box('#{confirm_banned_admin_banned_users_path(user_id: user.id, id: memo.id)}','#{remove_ban_message}','post');"%>
|
<%= link_to "取消禁言", "javascript:void(0)", class: "color-blue_4C", onclick: "custom_confirm_remote_box('#{confirm_banned_admin_banned_users_path(user_id: user.id, id: memo.id)}','#{remove_ban_message}','post');"%>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to author.try(:show_name), user_path(author), class: "" %>
|
<%= link_to author.try(:show_real_name), user_path(author), class: "" %>
|
||||||
<span class="color-grey-9 ml20">
|
<span class="color-grey-9 ml20">
|
||||||
<%= time_from_now(ban.updated_at) %>
|
<%= time_from_now(ban.updated_at) %>
|
||||||
</span>
|
</span>
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<div class="color-grey-9">
|
<div class="color-grey-9">
|
||||||
在【<span class="max-width-300"><%= link_to memo.subject.truncate(50), "forums/#{memo.id}", class: "color-blue_4C" %></span>】被<%= author_type %>:<%= link_to author.try(:show_name), user_path(author), class: "" %> 禁言
|
在【<span class="max-width-300"><%= link_to memo.subject.truncate(50), "forums/#{memo.id}", class: "color-blue_4C" %></span>】被<%= author_type %>:<%= link_to author.try(:show_real_name), user_path(author), class: "" %> 禁言
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<%= image_tag(url_to_avatar(user),width:"50px",height:"50px",class:"radius mr15") %>
|
<%= image_tag(url_to_avatar(user),width:"50px",height:"50px",class:"radius mr15") %>
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
<li class="clearfix mb20">
|
<li class="clearfix mb20">
|
||||||
<%= link_to user.try(:show_name),user_path(user),class: "fl mr15 color-grey-3 font-16" %>
|
<%= link_to user.try(:show_real_name),user_path(user),class: "fl mr15 color-grey-3 font-16" %>
|
||||||
<span class="fl color-grey-9 mt3"><%= time_from_now(apply.updated_at) %></span>
|
<span class="fl color-grey-9 mt3"><%= time_from_now(apply.updated_at) %></span>
|
||||||
<span class="fl color-grey-9 mt3 ml50">IP:<%= user_ip_addr apply.user_ip %></span>
|
<span class="fl color-grey-9 mt3 ml50">IP:<%= user_ip_addr apply.user_ip %></span>
|
||||||
<span class="fr">
|
<span class="fr">
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
<% apply_user = apply&.reviews&.acted_forum&.last&.user %>
|
<% apply_user = apply&.reviews&.acted_forum&.last&.user %>
|
||||||
<% if apply_user.present? %>
|
<% if apply_user.present? %>
|
||||||
<span class="fl mr20">
|
<span class="fl mr20">
|
||||||
<%= link_to apply_user.try(:show_name), user_path(apply_user) %>
|
<%= link_to apply_user.try(:show_real_name), user_path(apply_user) %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if apply.is_confirm == 2 %>
|
<% if apply.is_confirm == 2 %>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<% users.each do |u| %>
|
<% users.each do |u| %>
|
||||||
<% user = u.user %>
|
<% user = u.user %>
|
||||||
<span class="blue-user-btn" id="forum_section_moderator_user_<%= u.id %>">
|
<span class="blue-user-btn" id="forum_section_moderator_user_<%= u.id %>">
|
||||||
<span class="mr5"><%= link_to user.try(:show_name), user_path(user) %></span>
|
<span class="mr5"><%= link_to user.try(:show_real_name), user_path(user) %></span>
|
||||||
<span><%= link_to "<i class='fa fa-close font16'></i>".html_safe,admin_forum_section_forum_moderator_path(forum, u), method: :delete, data:{confirm: "确认删除吗?"}, remote: true, class: "color-grey-9" %></span>
|
<span><%= link_to "<i class='fa fa-close font16'></i>".html_safe,admin_forum_section_forum_moderator_path(forum, u), method: :delete, data:{confirm: "确认删除吗?"}, remote: true, class: "color-grey-9" %></span>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<!--<div class="homepageEditProfile"><a href="javascript:void(0);" class="homepageEditProfileIcon"></a></div>-->
|
<!--<div class="homepageEditProfile"><a href="javascript:void(0);" class="homepageEditProfileIcon"></a></div>-->
|
||||||
</div>
|
</div>
|
||||||
<div class="fl" style="width: 135px;">
|
<div class="fl" style="width: 135px;">
|
||||||
<% user_name = @forum.creator.show_name.empty? ? @forum.creator.name : @forum.creator.show_name %>
|
<% user_name = @forum.creator.show_real_name.empty? ? @forum.creator.name : @forum.creator.show_real_name %>
|
||||||
<div class="fl mb8 mt10">吧主:</div>
|
<div class="fl mb8 mt10">吧主:</div>
|
||||||
<a href="<%= user_path(@forum.creator)%>" target="_blank" class="linkBlue w80 fl mb8 mt10" style="overflow: hidden;white-space: nowrap;text-overflow:ellipsis; "><%= user_name %></a>
|
<a href="<%= user_path(@forum.creator)%>" target="_blank" class="linkBlue w80 fl mb8 mt10" style="overflow: hidden;white-space: nowrap;text-overflow:ellipsis; "><%= user_name %></a>
|
||||||
<div class="fontGrey3 fl">回答:<a href="javascript:void(0);" class="linkOrange mr5" style="cursor: default"><%= @my_replies_count %></a>
|
<div class="fontGrey3 fl">回答:<a href="javascript:void(0);" class="linkOrange mr5" style="cursor: default"><%= @my_replies_count %></a>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<!--<div class="homepageEditProfile"><a href="javascript:void(0);" class="homepageEditProfileIcon"></a></div>-->
|
<!--<div class="homepageEditProfile"><a href="javascript:void(0);" class="homepageEditProfileIcon"></a></div>-->
|
||||||
</div>
|
</div>
|
||||||
<div class="fl" style="width: 135px;">
|
<div class="fl" style="width: 135px;">
|
||||||
<% user_name = @forum.creator.show_name.empty? ? @forum.creator.name : @forum.creator.show_name %>
|
<% user_name = @forum.creator.show_real_name.empty? ? @forum.creator.name : @forum.creator.show_real_name %>
|
||||||
<div class="fl mb8 mt10">吧主:</div>
|
<div class="fl mb8 mt10">吧主:</div>
|
||||||
<a href="<%= user_path(@forum.creator)%>" target="_blank" class="linkBlue w80 fl mb8 mt10" style="overflow: hidden;white-space: nowrap;text-overflow:ellipsis; "><%= user_name %></a>
|
<a href="<%= user_path(@forum.creator)%>" target="_blank" class="linkBlue w80 fl mb8 mt10" style="overflow: hidden;white-space: nowrap;text-overflow:ellipsis; "><%= user_name %></a>
|
||||||
<div class="fontGrey3 fl">回答:<a href="javascript:void(0);" class="linkOrange mr5" style="cursor: default"><%= @my_replies_count %></a>
|
<div class="fontGrey3 fl">回答:<a href="javascript:void(0);" class="linkOrange mr5" style="cursor: default"><%= @my_replies_count %></a>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="edu-class-container edu-position">
|
<div class="edu-class-container edu-position">
|
||||||
<p class="mb10 font-14">
|
<p class="mb10 font-14">
|
||||||
<i class="fa fa-map-marker mr5 color-grey"></i>
|
<i class="fa fa-map-marker mr5 color-grey"></i>
|
||||||
<a href="<%= user_path(@user) %>"><%= @user.show_name %></a> > <a href="<%= forums_path %>">讨论 </a> > 编辑
|
<a href="<%= user_path(@user) %>"><%= @user.show_real_name %></a> > <a href="<%= forums_path %>">讨论 </a> > 编辑
|
||||||
</p>
|
</p>
|
||||||
<div class="edu-con-top user_bg_shadow bor-grey-e">
|
<div class="edu-con-top user_bg_shadow bor-grey-e">
|
||||||
<p class="ml15 color-grey3">编辑话题</p>
|
<p class="ml15 color-grey3">编辑话题</p>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="edu-class-container edu-position">
|
<div class="edu-class-container edu-position">
|
||||||
<p class="mb10 font-14">
|
<p class="mb10 font-14">
|
||||||
<i class="fa fa-map-marker mr5 color-grey"></i>
|
<i class="fa fa-map-marker mr5 color-grey"></i>
|
||||||
<a href="<%= user_path(@user) %>"><%= @user.show_name %></a> > <a href="<%= forums_path %>">讨论区 </a> > 新建
|
<a href="<%= user_path(@user) %>"><%= @user.show_real_name %></a> > <a href="<%= forums_path %>">讨论区 </a> > 新建
|
||||||
</p>
|
</p>
|
||||||
<div class="edu-con-top user_bg_shadow bor-grey-e">
|
<div class="edu-con-top user_bg_shadow bor-grey-e">
|
||||||
<p class="ml15 color-grey3">新建话题</p>
|
<p class="ml15 color-grey3">新建话题</p>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<div class="edu-class-container edu-position">
|
<div class="edu-class-container edu-position">
|
||||||
<p class="mb10 font-14">
|
<p class="mb10 font-14">
|
||||||
<i class="fa fa-map-marker mr5 color-grey"></i>
|
<i class="fa fa-map-marker mr5 color-grey"></i>
|
||||||
<a href="<%= user_path(@user)%>"><%= @user.show_name %></a> > <a href="<%= forums_path %>">讨论区 </a>
|
<a href="<%= user_path(@user)%>"><%= @user.show_real_name %></a> > <a href="<%= forums_path %>">讨论区 </a>
|
||||||
</p>
|
</p>
|
||||||
<div class="edu-con-top user_bg_shadow bor-grey-e clearfix mb20">
|
<div class="edu-con-top user_bg_shadow bor-grey-e clearfix mb20">
|
||||||
<p class="ml15 color-grey3 fl">
|
<p class="ml15 color-grey3 fl">
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
<!-- <p class="color-grey fr font-12 mr15 mt5"><a href="javascript:void(0)">返回</a></p>-->
|
<!-- <p class="color-grey fr font-12 mr15 mt5"><a href="javascript:void(0)">返回</a></p>-->
|
||||||
</div>
|
</div>
|
||||||
<p class="mb10">
|
<p class="mb10">
|
||||||
<a href="<%= user_path(@memo.author) %>" class="font-14 mr15 color-grey" target="_blank"><%= @memo.author.show_name %></a><span class="font-14 color-grey">更新于<%= time_from_now @memo.updated_at %></span>
|
<a href="<%= user_path(@memo.author) %>" class="font-14 mr15 color-grey" target="_blank"><%= @memo.author.show_real_name %></a><span class="font-14 color-grey">更新于<%= time_from_now @memo.updated_at %></span>
|
||||||
<span id="reword_score_<%= @memo.id %>">
|
<span id="reword_score_<%= @memo.id %>">
|
||||||
<% if @memo.try(:reward).present? %>
|
<% if @memo.try(:reward).present? %>
|
||||||
<span class="ml15 color-orange03" style="cursor: default;" data-tip-down="获得平台奖励金币:<%= @memo.try(:reward) %>"><i class="fa fa-gift mr5 font-16"></i><%= @memo.try(:reward) %></span>
|
<span class="ml15 color-orange03" style="cursor: default;" data-tip-down="获得平台奖励金币:<%= @memo.try(:reward) %>"><i class="fa fa-gift mr5 font-16"></i><%= @memo.try(:reward) %></span>
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
<div class="cl"></div>
|
<div class="cl"></div>
|
||||||
|
|
||||||
<div class="postDetailCreater">
|
<div class="postDetailCreater">
|
||||||
<%= link_to @memo.author.show_name, user_path(@memo.author), :class => "linkBlue2", :target=> "_blank"%></div>
|
<%= link_to @memo.author.show_real_name, user_path(@memo.author), :class => "linkBlue2", :target=> "_blank"%></div>
|
||||||
<div class="postDetailDate mb5"><%= format_date( @memo.created_at)%></div>
|
<div class="postDetailDate mb5"><%= format_date( @memo.created_at)%></div>
|
||||||
<div class="cl"></div>
|
<div class="cl"></div>
|
||||||
<div class="homepagePostIntro memo-content ke-block" id="activity_description_<%= @memo.id %>" style="word-break: break-all; word-wrap:break-word;margin-bottom: 0px !important;" >
|
<div class="homepagePostIntro memo-content ke-block" id="activity_description_<%= @memo.id %>" style="word-break: break-all; word-wrap:break-word;margin-bottom: 0px !important;" >
|
||||||
|
|
|
@ -103,7 +103,7 @@ class ForumSectionsService
|
||||||
user_item = {
|
user_item = {
|
||||||
id: u.id,
|
id: u.id,
|
||||||
login: u.try(:login),
|
login: u.try(:login),
|
||||||
username: u.try(:show_name),
|
username: u.try(:show_real_name),
|
||||||
nickname: u.try(:nickname)
|
nickname: u.try(:nickname)
|
||||||
}
|
}
|
||||||
search_users.push(user_item)
|
search_users.push(user_item)
|
||||||
|
@ -133,7 +133,7 @@ class ForumSectionsService
|
||||||
user_list = {
|
user_list = {
|
||||||
forum_moderator_id: new_forum_moder.id,
|
forum_moderator_id: new_forum_moder.id,
|
||||||
login: user.try(:login),
|
login: user.try(:login),
|
||||||
username: user.try(:show_name),
|
username: user.try(:show_real_name),
|
||||||
user_url: "/users/#{user.try(:login)}"
|
user_url: "/users/#{user.try(:login)}"
|
||||||
}
|
}
|
||||||
forum_users.push(user_list)
|
forum_users.push(user_list)
|
||||||
|
@ -230,7 +230,7 @@ class ForumSectionsService
|
||||||
end
|
end
|
||||||
apply_user = {
|
apply_user = {
|
||||||
apply_id: apply.id,
|
apply_id: apply.id,
|
||||||
username: user.try(:show_name),
|
username: user.try(:show_real_name),
|
||||||
login: user.try(:login),
|
login: user.try(:login),
|
||||||
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
||||||
user_url: "/users/#{user.try(:login)}",
|
user_url: "/users/#{user.try(:login)}",
|
||||||
|
@ -335,8 +335,9 @@ class ForumSectionsService
|
||||||
extra = "2"
|
extra = "2"
|
||||||
else
|
else
|
||||||
parent_section_id = ""
|
parent_section_id = ""
|
||||||
admin_role_ids= AdminRole.includes(:admin_permissions).joins(:admin_permissions).where("admin_permissions.name = 'forum_post'").pluck(:id)
|
manager_ids = User.select(:admin, :id).admin_users.pluck(:id)
|
||||||
manager_ids = UserAdminRole.where(admin_role_id: admin_role_ids).pluck(:user_id).uniq
|
# admin_role_ids= AdminRole.includes(:admin_permissions).joins(:admin_permissions).where("admin_permissions.name = 'forum_post'").pluck(:id)
|
||||||
|
# manager_ids = UserAdminRole.where(admin_role_id: admin_role_ids).pluck(:user_id).uniq
|
||||||
extra = "1"
|
extra = "1"
|
||||||
end
|
end
|
||||||
if manager_ids.size == 0
|
if manager_ids.size == 0
|
||||||
|
@ -394,7 +395,7 @@ class ForumSectionsService
|
||||||
memo_id: memo.id,
|
memo_id: memo.id,
|
||||||
is_banned: is_banned,
|
is_banned: is_banned,
|
||||||
memo_title: memo.subject,
|
memo_title: memo.subject,
|
||||||
username: user.try(:show_name),
|
username: user.try(:show_real_name),
|
||||||
login: user.try(:login),
|
login: user.try(:login),
|
||||||
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
||||||
user_url: "/users/#{user.try(:login)}",
|
user_url: "/users/#{user.try(:login)}",
|
||||||
|
@ -441,7 +442,7 @@ class ForumSectionsService
|
||||||
is_banned: is_banned,
|
is_banned: is_banned,
|
||||||
reply_id: memo.id,
|
reply_id: memo.id,
|
||||||
reply_content: memo.content,
|
reply_content: memo.content,
|
||||||
username: user.try(:show_name),
|
username: user.try(:show_real_name),
|
||||||
login: user.try(:login),
|
login: user.try(:login),
|
||||||
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
||||||
user_url: "/users/#{user.try(:login)}",
|
user_url: "/users/#{user.try(:login)}",
|
||||||
|
@ -504,7 +505,7 @@ class ForumSectionsService
|
||||||
memo_id: memo.id,
|
memo_id: memo.id,
|
||||||
is_banned: is_banned,
|
is_banned: is_banned,
|
||||||
memo_title: memo.subject,
|
memo_title: memo.subject,
|
||||||
username: user.try(:show_name),
|
username: user.try(:show_real_name),
|
||||||
login: user.try(:login),
|
login: user.try(:login),
|
||||||
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}",
|
||||||
user_url: "/users/#{user.try(:login)}",
|
user_url: "/users/#{user.try(:login)}",
|
||||||
|
|
|
@ -12,7 +12,7 @@ class MemosService
|
||||||
search = params[:search].to_s.strip
|
search = params[:search].to_s.strip
|
||||||
sort_name = params[:sort] || "published_at"
|
sort_name = params[:sort] || "published_at"
|
||||||
|
|
||||||
all_memos = Memo&.visible&.roots&.includes(:forum_section,author: :user_extensions)
|
all_memos = Memo&.visible&.roots
|
||||||
|
|
||||||
all_hottest_memos = all_memos.hottest_five_memos
|
all_hottest_memos = all_memos.hottest_five_memos
|
||||||
hottest_memos = object_to_hash(all_hottest_memos)
|
hottest_memos = object_to_hash(all_hottest_memos)
|
||||||
|
@ -25,7 +25,7 @@ class MemosService
|
||||||
end
|
end
|
||||||
|
|
||||||
memos_count = all_memos.size # 帖子的总数
|
memos_count = all_memos.size # 帖子的总数
|
||||||
all_memos = all_memos.order_index(sort_name).limit(index_limit).offset(offset)
|
all_memos = all_memos.order_index(sort_name)&.includes(:forum_section,author: :user_extension).limit(index_limit).offset(offset)
|
||||||
|
|
||||||
memo_lists = get_memo_lists(all_memos, false, current_user, false)
|
memo_lists = get_memo_lists(all_memos, false, current_user, false)
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ class MemosService
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def related_memos params
|
def related_memos params, current_user
|
||||||
memo = Memo.find(params[:id])
|
memo = Memo.find(params[:id])
|
||||||
return { status: 404 } if memo.hidden? && (!current_user || !(current_user.admin? || current_user.id == memo.author_id))
|
return { status: 404 } if memo.hidden? && (!current_user || !(current_user.admin? || current_user.id == memo.author_id))
|
||||||
all_memos = Memo.visible.roots.where("id != ?", params[:id].to_i).includes(memo_forums: :forum_section,author: :user_extensions).related_search_name(memo.try(:subject).to_s).order_index("published_at").limit(5).offset(0)
|
all_memos = Memo.visible.roots.where("id != ?", params[:id].to_i).includes(memo_forums: :forum_section,author: :user_extension).related_search_name(memo.try(:subject).to_s).order_index("published_at").limit(5).offset(0)
|
||||||
memo_lists = get_memo_lists(all_memos, false, current_user, false)
|
memo_lists = get_memo_lists(all_memos, false, current_user, false)
|
||||||
{status: 0, memos: memo_lists}
|
{status: 0, memos: memo_lists}
|
||||||
end
|
end
|
||||||
|
@ -81,7 +81,7 @@ class MemosService
|
||||||
# memo.published_at = Time.now if params[:memo][:published_at].blank?
|
# memo.published_at = Time.now if params[:memo][:published_at].blank?
|
||||||
memo.hidden = true
|
memo.hidden = true
|
||||||
# memo.save!
|
# memo.save!
|
||||||
if memo.save
|
if memo.save!
|
||||||
memo.update_attachments(params[:attachments]) if params[:attachments].present?
|
memo.update_attachments(params[:attachments]) if params[:attachments].present?
|
||||||
# 为了区分帖子头像,改变其类型为MemoIcon
|
# 为了区分帖子头像,改变其类型为MemoIcon
|
||||||
create_user_tidings(memo, "forum_post")
|
create_user_tidings(memo, "forum_post")
|
||||||
|
@ -95,8 +95,7 @@ class MemosService
|
||||||
{status: -1, message: memo.errors.messages.values[0][0]}
|
{status: -1, message: memo.errors.messages.values[0][0]}
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
{status: -1, message: "出现错误"}
|
{status: -1, message: e}
|
||||||
raise ActiveRecord::Rollback
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -147,7 +146,7 @@ class MemosService
|
||||||
|
|
||||||
is_md = memo.is_md
|
is_md = memo.is_md
|
||||||
|
|
||||||
author_info = {username: memo_author.show_name,
|
author_info = {username: memo_author.show_real_name,
|
||||||
watched: watched,
|
watched: watched,
|
||||||
is_blocked: current_user&.blocked_for(memo_author.id),
|
is_blocked: current_user&.blocked_for(memo_author.id),
|
||||||
is_blocked_by: memo_author&.blocked_for(current_user.id),
|
is_blocked_by: memo_author&.blocked_for(current_user.id),
|
||||||
|
@ -156,10 +155,10 @@ class MemosService
|
||||||
identity: memo_author.identity,
|
identity: memo_author.identity,
|
||||||
login: memo_author.login,
|
login: memo_author.login,
|
||||||
user_id: memo_author.id,
|
user_id: memo_author.id,
|
||||||
description: memo_author&.user_extensions&.brief_introduction,
|
description: memo_author&.user_extension&.brief_introduction,
|
||||||
memos_count: memo_author_memos.posts.size,
|
memos_count: memo_author_memos.posts.size,
|
||||||
replies_count: memo_author_memos.total_replies.size,
|
replies_count: memo_author_memos.total_replies.size,
|
||||||
watchers_count: memo_author.watcher_users.size,
|
watchers_count: memo_author.fan_count,
|
||||||
current_login: current_user.try(:login),
|
current_login: current_user.try(:login),
|
||||||
is_current_user: memo.author_id == current_user.try(:id)
|
is_current_user: memo.author_id == current_user.try(:id)
|
||||||
}
|
}
|
||||||
|
@ -189,20 +188,21 @@ class MemosService
|
||||||
|
|
||||||
}
|
}
|
||||||
if current_user
|
if current_user
|
||||||
unless memo.children.blank?
|
#TODO 通知消息暂时隐藏
|
||||||
memo.children.includes(:memo_messages).each do |child|
|
# unless memo.children.blank?
|
||||||
child.memo_messages.each do |memo_message|
|
# memo.children.includes(:memo_messages).each do |child|
|
||||||
memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
|
# child.memo_messages.each do |memo_message|
|
||||||
end
|
# memo_message.update_attributes(:viewed => true) if current_user.id == memo_message.user_id
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
query_memo_messages = memo.memo_messages
|
# query_memo_messages = memo.memo_messages
|
||||||
unless query_memo_messages
|
# unless query_memo_messages
|
||||||
query_memo_messages.each do |query_memo_message|
|
# query_memo_messages.each do |query_memo_message|
|
||||||
query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
|
# query_memo_message.update_attributes(:viewed => true) if current_user.id == query_memo_message.user_id
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
if memo.author_id != current_user.id
|
if memo.author_id != current_user.id
|
||||||
if memo.visit_actions.exists?(watcher_params)
|
if memo.visit_actions.exists?(watcher_params)
|
||||||
|
@ -268,7 +268,7 @@ class MemosService
|
||||||
|
|
||||||
def destroy params, current_user
|
def destroy params, current_user
|
||||||
user_permission = check_banned_permission current_user, params[:id]
|
user_permission = check_banned_permission current_user, params[:id]
|
||||||
memo = Memo.select([:id,:parent_id]).find(params[:id])
|
memo = Memo.select(:id,:parent_id, :forum_section_id).find(params[:id])
|
||||||
return {status: -1, message: "帖子不存在!"} unless memo.present?
|
return {status: -1, message: "帖子不存在!"} unless memo.present?
|
||||||
return {status: -1, message: "您没有权限操作!"} unless user_permission
|
return {status: -1, message: "您没有权限操作!"} unless user_permission
|
||||||
if memo.destroy
|
if memo.destroy
|
||||||
|
@ -412,7 +412,7 @@ class MemosService
|
||||||
memo.children << reply
|
memo.children << reply
|
||||||
create_user_tidings(reply, "forum_comment")
|
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,
|
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_name, :reward => memo.reward, :hidden => reply.hidden,
|
:image_url => "/images/#{url_to_avatar(reply.author)}?#{Time.now.to_i}", :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)}
|
:praise_count => reply.praises_count,:user_login => reply.author.try(:login), replies_count: reply.can_see_reply_count(current_user)}
|
||||||
{
|
{
|
||||||
status: 0,
|
status: 0,
|
||||||
|
@ -483,6 +483,30 @@ class MemosService
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def plus params, current_user
|
||||||
|
plus_type = params[:container_type].to_s
|
||||||
|
plus_id = params[:id]
|
||||||
|
|
||||||
|
pt = PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type],
|
||||||
|
:user_id => current_user, :praise_or_tread => 1).first
|
||||||
|
# 如果当前用户已赞过,则不能重复赞
|
||||||
|
if params[:type] == 1 && pt.blank?
|
||||||
|
if pt.blank?
|
||||||
|
PraiseTread.create!(:praise_tread_object_id => plus_id, :praise_tread_object_type => plus_type,
|
||||||
|
:user_id => current_user.id, :praise_or_tread => 1) if pt.blank?
|
||||||
|
|
||||||
|
plus_name = plus_type.constantize.find(params[:id])
|
||||||
|
Tiding.create(:user_id => plus_name.try(:author_id), :trigger_user_id => current_user.id,
|
||||||
|
container_id: plus_id, container_type: plus_type,
|
||||||
|
:parent_container_id => plus_id, :parent_container_type => plus_type,
|
||||||
|
:viewed => 0, :tiding_type => "PraiseTread")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
pt.destroy if pt.present? # 如果已赞过,则删掉这条赞(取消);如果没赞过,则为非法请求不处理
|
||||||
|
end
|
||||||
|
{:praise_count => PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type],
|
||||||
|
:praise_or_tread => 1).count}
|
||||||
|
end
|
||||||
|
|
||||||
def banned_user params, current_user
|
def banned_user params, current_user
|
||||||
user_permission = check_banned_permission current_user, params[:id]
|
user_permission = check_banned_permission current_user, params[:id]
|
||||||
|
@ -533,14 +557,14 @@ class MemosService
|
||||||
forum_section = ForumSection.find_by_id(params[:id])
|
forum_section = ForumSection.find_by_id(params[:id])
|
||||||
return {status: -1, message: "版块不存在"} if forum_section.blank?
|
return {status: -1, message: "版块不存在"} if forum_section.blank?
|
||||||
section_author = forum_section.user
|
section_author = forum_section.user
|
||||||
forum_section_user = {username: section_author.try(:show_name), user_login: section_author.try(:login)}
|
forum_section_user = {username: section_author.try(:show_real_name), user_login: section_author.try(:login)}
|
||||||
forum_moders = []
|
forum_moders = []
|
||||||
if ForumModerator.exists?(forum_section_id: forum_section.id)
|
if ForumModerator.exists?(forum_section_id: forum_section.id)
|
||||||
all_forum_moderators = forum_section.forum_moderators.includes(user: :user_extensions).select([:id, :user_id])
|
all_forum_moderators = forum_section.forum_moderators.includes(user: :user_extension).select([:id, :user_id])
|
||||||
all_forum_moderators.each do |moder|
|
all_forum_moderators.each do |moder|
|
||||||
moder_user = moder.user
|
moder_user = moder.user
|
||||||
forum_moder = {
|
forum_moder = {
|
||||||
username: moder_user.show_name,
|
username: moder_user.show_real_name,
|
||||||
user_login: moder_user.try(:login)
|
user_login: moder_user.try(:login)
|
||||||
}
|
}
|
||||||
forum_moders << forum_moder
|
forum_moders << forum_moder
|
||||||
|
@ -616,13 +640,13 @@ class MemosService
|
||||||
active_user_array = []
|
active_user_array = []
|
||||||
active_users.each do |user|
|
active_users.each do |user|
|
||||||
active_user_array.push({
|
active_user_array.push({
|
||||||
username: user.show_name,
|
username: user.show_real_name,
|
||||||
login: user.login,
|
login: user.login,
|
||||||
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}"
|
image_url: "#{url_to_avatar(user)}?#{Time.now.to_i}"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
username: forum_section.user.show_name,
|
username: forum_section.user.show_real_name,
|
||||||
user_login: forum_section.user.login,
|
user_login: forum_section.user.login,
|
||||||
notice: notice.try(:content),
|
notice: notice.try(:content),
|
||||||
recommend_forum_sections: new_childre_section,
|
recommend_forum_sections: new_childre_section,
|
||||||
|
@ -685,7 +709,7 @@ class MemosService
|
||||||
memo_list = []
|
memo_list = []
|
||||||
memos.each do |m|
|
memos.each do |m|
|
||||||
forum_name = m.forums.map(&:name)
|
forum_name = m.forums.map(&:name)
|
||||||
user_info = {username: m.author.show_name, login: m.author.login, image_url: "#{url_to_avatar(m.author)}?#{Time.now.to_i}", forum_name:forum_name, praise_count: m.praises_count}
|
user_info = {username: m.author.show_real_name, login: m.author.login, image_url: "#{url_to_avatar(m.author)}?#{Time.now.to_i}", forum_name:forum_name, praise_count: m.praises_count}
|
||||||
memo_list << m.attributes.dup.merge(user_info)
|
memo_list << m.attributes.dup.merge(user_info)
|
||||||
end
|
end
|
||||||
memo_list
|
memo_list
|
||||||
|
@ -731,7 +755,7 @@ class MemosService
|
||||||
permission = current_user ? current_user.manager_of_memo?(memo) : false
|
permission = current_user ? current_user.manager_of_memo?(memo) : false
|
||||||
# 实训(TPM)的管理员可以看到隐藏的评论
|
# 实训(TPM)的管理员可以看到隐藏的评论
|
||||||
replies = {:id => memo.id, :content => memo.content, :time => time_from_now(memo.created_at), :user_id => memo.author_id,
|
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_name, :reward => memo.reward, :hidden => memo.hidden,
|
:image_url => "/images/#{url_to_avatar(memo.author)}?#{Time.now.to_i}", :username => memo.author.show_real_name, :reward => memo.reward, :hidden => memo.hidden,
|
||||||
:permission => permission, :praise_count => memo.praises_count, :user_praise => user_praise,
|
: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)}
|
: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)
|
childrens = Memo.where(:parent_id => memo.id).includes(:author).reorder("created_at desc").limit(5)
|
||||||
|
@ -743,7 +767,7 @@ class MemosService
|
||||||
children_praise = child.praise_tread.exists?(user_id: current_user.try(:id).to_i)
|
children_praise = child.praise_tread.exists?(user_id: current_user.try(:id).to_i)
|
||||||
children_is_banned = user_is_banned?(child.author) #帖子的用户是否被禁言
|
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,
|
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_name, :hidden => child.hidden, replies_count: child.can_see_reply_count(current_user),
|
: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),
|
||||||
:permission => permission, :user_login => child.author.try(:login), :user_id => child.author.try(:id), :parent_id => child.parent_id, is_banned: children_is_banned}
|
: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
|
end
|
||||||
list << replies.merge({children: children_list})
|
list << replies.merge({children: children_list})
|
||||||
|
|
|
@ -61,7 +61,7 @@ class MyMemosService
|
||||||
def recommend_memos current_user
|
def recommend_memos current_user
|
||||||
return {status: -1, message: "请登录"} unless current_user
|
return {status: -1, message: "请登录"} unless current_user
|
||||||
|
|
||||||
all_memos = Memo.includes(memo_forums: :forum_section,author: :user_extensions)
|
all_memos = Memo.includes(memo_forums: :forum_section,author: :user_extension)
|
||||||
|
|
||||||
all_hottest_memos = all_memos.visible.hottest_five_memos
|
all_hottest_memos = all_memos.visible.hottest_five_memos
|
||||||
hottest_memos = object_to_hash(all_hottest_memos)
|
hottest_memos = object_to_hash(all_hottest_memos)
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Projects::ApplyJoinService < ApplicationService
|
||||||
return if owner.phone.blank?
|
return if owner.phone.blank?
|
||||||
|
|
||||||
Educoder::Sms.send(mobile: owner.phone, send_type:'applied_project_info',
|
Educoder::Sms.send(mobile: owner.phone, send_type:'applied_project_info',
|
||||||
user_name: owner.show_name, name: project.name)
|
user_name: owner.show_real_name, name: project.name)
|
||||||
rescue Exception => ex
|
rescue Exception => ex
|
||||||
Rails.logger.error("发送短信失败 => #{ex.message}")
|
Rails.logger.error("发送短信失败 => #{ex.message}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
=end%>
|
=end%>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to(memo.try(:author).try(:show_name), user_path(memo.author)) %>
|
<%= link_to(memo.try(:author).try(:show_real_name), user_path(memo.author)) %>
|
||||||
<%# if memo.try(:author).try(:realname) == ' '%>
|
<%# if memo.try(:author).try(:realname) == ' '%>
|
||||||
<%#= link_to(memo.try(:author), user_path(memo.author)) %>
|
<%#= link_to(memo.try(:author), user_path(memo.author)) %>
|
||||||
<%# else %>
|
<%# else %>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
|
<td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to(memo.try(:author).try(:show_name), user_path(memo.author)) %>
|
<%= link_to(memo.try(:author).try(:show_real_name), user_path(memo.author)) %>
|
||||||
</td>
|
</td>
|
||||||
<td class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
|
<td class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
|
||||||
<% if memo.parent_id.nil? || memo.subject.starts_with?('RE:')%>
|
<% if memo.parent_id.nil? || memo.subject.starts_with?('RE:')%>
|
||||||
|
|
|
@ -43,12 +43,5 @@ module Educoderplus
|
||||||
resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put]
|
resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
config.middleware.use Rack::Cors do
|
|
||||||
allow do
|
|
||||||
origins '*'
|
|
||||||
# location of your API
|
|
||||||
resource '/api/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
# if Rails.env.development?
|
|
||||||
# lib_ruby_files = Dir.glob(File.join("app/api/**", "*.rb"))
|
|
||||||
# lib_reloader ||= ActiveSupport::FileUpdateChecker.new(lib_ruby_files) do
|
|
||||||
# # lib_ruby_files.each do |lib_file|
|
|
||||||
# # puts "start require #{lib_file}"
|
|
||||||
# # require_dependency(lib_file)
|
|
||||||
# # end
|
|
||||||
# #
|
|
||||||
|
|
||||||
# # binding.pry
|
|
||||||
# # if Object.const_defined?(:Mobile)
|
|
||||||
# # Object.send(:remove_const, :Mobile)
|
|
||||||
# # end
|
|
||||||
# #
|
|
||||||
# # $".delete_if {|s| s.include?('api/mobile') }
|
|
||||||
# # require File.join(Rails.root,"app/api/mobile/api.rb")
|
|
||||||
# Rails.application.reload_routes!
|
|
||||||
# end
|
|
||||||
|
|
||||||
# ActionDispatch::Callbacks.to_prepare do
|
|
||||||
# lib_reloader.execute_if_updated
|
|
||||||
# end
|
|
||||||
|
|
||||||
# end
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
require 'sidekiq/web'
|
require 'sidekiq/web'
|
||||||
require 'admin_constraint'
|
require 'admin_constraint'
|
||||||
mount Mobile::API => '/api'
|
# mount Mobile::API => '/api'
|
||||||
# mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new
|
# mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new
|
||||||
|
|
||||||
# Serve websocket cable requests in-process
|
# Serve websocket cable requests in-process
|
||||||
|
@ -45,6 +45,51 @@ Rails.application.routes.draw do
|
||||||
resources :edu_settings
|
resources :edu_settings
|
||||||
|
|
||||||
scope '/api' do
|
scope '/api' do
|
||||||
|
get 'my_memos/:login/memos', to: 'my_memos#index'
|
||||||
|
get 'my_memos/:login/my_interested', to: 'my_memos#my_interested'
|
||||||
|
get 'my_memos/:login/replies_memos', to: 'my_memos#replies_memos'
|
||||||
|
get 'my_memos/:login/recommend_memos', to: 'my_memos#recommend_memos'
|
||||||
|
get 'forum_sections/:id/deal_applies/:apply_id', to: 'forum_sections#deal_applies'
|
||||||
|
get 'forum_sections/:id/destroy_moderator/:moderator_id', to: 'forum_sections#destroy_moderator'
|
||||||
|
resources :forum_sections, only: [:index, :create, :destroy] do
|
||||||
|
collection do
|
||||||
|
get :select_sections
|
||||||
|
end
|
||||||
|
member do
|
||||||
|
post :user_apply
|
||||||
|
post :edit_notice
|
||||||
|
get :forum_section_header
|
||||||
|
post :rename
|
||||||
|
get :order_forums
|
||||||
|
get :search_users
|
||||||
|
post :add_users
|
||||||
|
get :managements
|
||||||
|
get :applied_forums
|
||||||
|
get :unchecked_memos
|
||||||
|
get :unchecked_replies
|
||||||
|
get :checked_memos
|
||||||
|
end
|
||||||
|
end
|
||||||
|
get 'memos/forum_memos/:id', to: 'memos#forum_memos'
|
||||||
|
get 'memos/forum_memos_head/:id', to: 'memos#forum_memos_head'
|
||||||
|
get 'memos/forum_memos_right/:id', to: 'memos#forum_memos_right'
|
||||||
|
post 'forum_memos/:id/is_watch', to: 'memos#is_watch'
|
||||||
|
resources :memos, only: [:index, :create, :edit, :update, :show, :destroy] do
|
||||||
|
member do
|
||||||
|
get :related_memos
|
||||||
|
post :watch_memo
|
||||||
|
get :hidden
|
||||||
|
post :watch_memo
|
||||||
|
post :memo_hidden
|
||||||
|
post :reply
|
||||||
|
get :set_top_or_down
|
||||||
|
post :is_fine
|
||||||
|
post :banned_user
|
||||||
|
get :more_reply
|
||||||
|
post :confirm_delete
|
||||||
|
post :plus
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :sync_forge, only: [:create] do
|
resources :sync_forge, only: [:create] do
|
||||||
collection do
|
collection do
|
||||||
post :sync_users
|
post :sync_users
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeMemoNullTrue < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
change_column_null(:memos, :forum_id, true)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddMemoImageToAttachment < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :attachments, :memo_image, :boolean, default: false
|
||||||
|
add_column :attachments, :extra_type, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,11 @@
|
||||||
|
class CreateBlockUsers < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :block_users do |t|
|
||||||
|
t.integer "user_id"
|
||||||
|
t.integer "block_user_id"
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :block_users, :user_id
|
||||||
|
add_index :block_users, :block_user_id
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
class CreateMemoMessages < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :memo_messages do |t|
|
||||||
|
t.integer "user_id"
|
||||||
|
t.integer "forum_id"
|
||||||
|
t.integer "memo_id"
|
||||||
|
t.string "memo_type"
|
||||||
|
t.integer "viewed"
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe BlockUser, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe MemoMessage, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in New Issue