diff --git a/.access_token b/.access_token
deleted file mode 100644
index 2e228963c..000000000
--- a/.access_token
+++ /dev/null
@@ -1 +0,0 @@
-{"access_token":"b_Pc60Dd5eyg_ut3cHbsjQO9EJJdj2Qj5F99o9LH9ltKSme7_FZ3Of22lWLL-K2V0siWzv-bd9PO0Dn-L1PBvIy9LhXa0qPVaFl6vTtZHR2kA8qjo1ps2ancya0t7KmzURGbAFAAXM","expires_in":7200,"got_token_at":1467976842}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 1ef7e63ce..8a40f3ca7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,3 +36,4 @@ public/javascripts/wechat/node_modules/
.ruby-version
.access_token
tmux*.log
+config/wechat.yml
diff --git a/Gemfile b/Gemfile
index 03dbb5785..6e8a4dcdf 100644
--- a/Gemfile
+++ b/Gemfile
@@ -49,9 +49,11 @@ gem 'kaminari'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
+#rails 3.2.22.2 bug
+gem "test-unit", "~>3.0"
### profile
-gem 'oneapm_rpm'
+# gem 'oneapm_rpm'
group :development do
gem 'grape-swagger'
diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb
index 9b4bdb5d6..3ff9895a6 100644
--- a/app/api/mobile/api.rb
+++ b/app/api/mobile/api.rb
@@ -20,13 +20,14 @@ module Mobile
require_relative 'apis/praise'
require_relative 'apis/resources'
require_relative 'apis/syllabuses'
+ require_relative 'apis/projects'
class API < Grape::API
version 'v1', using: :path
format :json
content_type :json, "application/json;charset=UTF-8"
use ActionDispatch::Session::CookieStore
- use Mobile::Middleware::ErrorHandler
+ use Middleware::ErrorHandler
helpers do
def logger
@@ -42,9 +43,9 @@ module Mobile
end
def current_user
- openid = params[:openid]
+ openid = session[:wechat_openid]
if openid
- uw = UserWechat.find_by_openid(params[:openid])
+ uw = UserWechat.find_by_openid(openid)
return uw.user if uw
end
@@ -75,6 +76,7 @@ module Mobile
mount Apis::Praise
mount Apis::Resources
mount Apis::Syllabuses
+ mount Apis::Projects
add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index 60e00280e..eec6e8ead 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -419,6 +419,53 @@ module Mobile
end
+ desc "获取班级某成员角色信息"
+ params do
+ requires :id, type: Integer
+ requires :token, type: String
+ requires :user_id, type: Integer
+ end
+ post 'get_member_info' do
+ authenticate!
+
+ c = Course.find("#{params[:id]}")
+
+ my_member = c.member_principals.where("users.id=#{params[:user_id]}").first
+
+ if my_member && my_member.roles[0]
+ present :course_id,params[:id]
+ present :user_id,params[:user_id]
+ present :member_info,my_member, with: Mobile::Entities::ProjectMember
+ present :status, 0
+ else
+ present :status, -1
+ end
+
+ end
+
+ desc "修改班级某成员角色信息"
+ params do
+ requires :id, type: Integer
+ requires :token, type: String
+ requires :user_id, type: Integer
+ requires :role_id, type: Integer
+ end
+ post 'edit_member_role' do
+ authenticate!
+
+ c = Course.find("#{params[:id]}")
+
+ #7教辅 9教师 10学生
+ if c.tea_id == params[:user_id] || c.tea_id != current_user.id || !(params[:role_id] == 7 || params[:role_id] == 9 || params[:role_id] == 10)
+ present :status, -1
+ else
+
+ cs = CoursesService.new
+ status = cs.modify_user_course_role params
+ present :status, status
+ end
+ end
+
end
end
end
diff --git a/app/api/mobile/apis/projects.rb b/app/api/mobile/apis/projects.rb
new file mode 100644
index 000000000..5ab0878d0
--- /dev/null
+++ b/app/api/mobile/apis/projects.rb
@@ -0,0 +1,181 @@
+#coding=utf-8
+
+module Mobile
+ module Apis
+ class Projects < Grape::API
+
+ resources :projects do
+ desc "获取项目列表"
+ params do
+ requires :token, type: String
+ end
+ get do
+ authenticate!
+
+ ps = ProjectsService.new
+ projects = ps.user_projects(current_user)
+ present :data, projects, with: Mobile::Entities::Project,user: current_user
+ present :status, 0
+ end
+
+ desc "返回单个项目"
+ params do
+ requires :id, type: Integer
+ requires :token,type:String
+ end
+ route_param :id do
+ get do
+ # course = Course.find(params[:id])
+ ps = ProjectsService.new
+ project = ps.show_project(params,current_user)
+
+ if project[:status] == 9
+ {status:-1, message: '该项目不存在或已被删除啦' }
+ else
+ present :data, project, with: Mobile::Entities::Project,user: current_user
+ present :status, 0
+ end
+ end
+ end
+
+ desc "获取项目动态"
+ params do
+ requires :id, type: Integer
+ requires :token, type: String
+ end
+ post 'activities' do
+ authenticate!
+
+ user = current_user
+
+ project_types = "('Message','Issue','Project')"
+ activities = UserActivity.where("(container_type = 'Project' and container_id = #{params[:id]} and act_type in #{project_types})").order('updated_at desc')
+
+ page = params[:page] ? params[:page] : 0
+ all_count = activities.count
+ activities = activities.limit(10).offset(page * 10)
+ count = activities.count
+ present :data, activities, with: Mobile::Entities::Activity,user: user
+ present :all_count, all_count
+ present :count, count
+ present :page, page
+ present :status, 0
+ end
+
+ desc "获取项目成员"
+ params do
+ requires :id, type: Integer
+ requires :token, type: String
+ end
+ post 'members' do
+ authenticate!
+
+ project = Project.find("#{params[:id]}")
+ members = project.member_principals
+
+ master_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=3").all.sort
+
+ master_members.each do |m|
+ if m.user_id == project.user_id
+ master_members.delete(m)
+ master_members.insert(0,m)
+ break
+ end
+ end
+
+ develop_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=4").all.sort
+ report_members = project.member_principals.includes(:roles, :principal).where("member_roles.role_id=5").all.sort
+
+ present :master_members,master_members, with: Mobile::Entities::ProjectMember
+ present :develop_members,develop_members, with: Mobile::Entities::ProjectMember
+ present :report_members,report_members, with: Mobile::Entities::ProjectMember
+ present :status, 0
+ end
+
+ desc "获取项目某成员角色信息"
+ params do
+ requires :id, type: Integer
+ requires :token, type: String
+ requires :user_id, type: Integer
+ end
+ post 'get_member_info' do
+ authenticate!
+
+ project = Project.find("#{params[:id]}")
+
+ my_member = project.member_principals.where("users.id=#{params[:user_id]}").first
+
+ if my_member && my_member.roles[0]
+ present :project_id,params[:id]
+ present :user_id,params[:user_id]
+ present :member_info,my_member, with: Mobile::Entities::ProjectMember
+ present :status, 0
+ else
+ present :status, -1
+ end
+
+ end
+
+ desc "修改项目某成员角色信息"
+ params do
+ requires :id, type: Integer
+ requires :token, type: String
+ requires :user_id, type: Integer
+ requires :role_id, type: Integer
+ end
+ post 'edit_member_role' do
+ authenticate!
+
+ project = Project.find("#{params[:id]}")
+
+ my_member = project.member_principals.where("users.id=#{current_user.id}").first
+
+ #3管理 4开发 5报告
+ if !(my_member && my_member.roles[0] && my_member.roles[0].id == 3 ) || project.user_id == params[:user_id] || !(params[:role_id] == 3 || params[:role_id] == 4 || params[:role_id] == 5)
+ present :status, -1
+ else
+ ps = ProjectsService.new
+
+ status = ps.modify_user_project_role params
+
+ present :status, status
+ end
+ end
+
+ desc "新建项目"
+ params do
+ requires :token, type: String
+ requires :name, type: String, desc: '项目名称'
+ end
+ post 'create' do
+ authenticate!
+
+ ps = ProjectsService.new
+
+ status = ps.createNewProject params,current_user
+
+
+ present :status, 0
+
+ end
+
+ desc "加入项目"
+ params do
+ requires :token, type: String
+ requires :invite_code, type: String, desc: '邀请码'
+ end
+ post "join" do
+ authenticate!
+
+ # ps = ProjectsService.new
+ # status = ps.join_project({role: "5", openid: params[:openid], invite_code: params[:invite_code]}, current_user)
+ #
+ # present :status, status
+
+ {status:-1, message: '该功能将在近日开放,敬请期待!' }
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb
index db1e7e269..9d03eed9f 100644
--- a/app/api/mobile/apis/whomeworks.rb
+++ b/app/api/mobile/apis/whomeworks.rb
@@ -13,8 +13,14 @@ module Mobile
#0一级回复的更多 1 二级回复的更多
type = params[:type] || 0
page = params[:page] || 0
- homework = HomeworkCommon.find params[:id]
- present :data, homework, with: Mobile::Entities::Whomework,user: user,type: type,page: page
+
+ if type == 0
+ homework = HomeworkCommon.find params[:id]
+ present :data, homework, with: Mobile::Entities::Whomework,user: user,type: type,page: page,comment_type: "homework"
+ else
+ jour = JournalsForMessage.find params[:id]
+ present :data, jour, with: Mobile::Entities::Jours,user: user,type: type,page: page,comment_type: "homework"
+ end
present :type, type
present :page, page
present :status, 0
diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb
index 3f58e901f..726949bb5 100644
--- a/app/api/mobile/entities/blog_comment.rb
+++ b/app/api/mobile/entities/blog_comment.rb
@@ -51,9 +51,8 @@ module Mobile
blog_comment_expose :id
blog_comment_expose :locked
blog_comment_expose :praise_count
- expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
+ expose :all_children, using:Mobile::Entities::BlogComment do |c,opt|
if c.is_a? (::BlogComment)
- ##自己的父回复为空 才有子回复
if !opt[:children]
if c.parent.nil? && opt[:type] == 0
opt[:children] = true
@@ -86,7 +85,7 @@ module Mobile
#取二级回复的底楼层
parents_reply = []
parents_reply = get_reply_parents_no_root(parents_reply, c)
- if parents_reply.count > 0 && !opt[:bottom]
+ if parents_reply.count > 0 && parents_reply.count != 2 && !opt[:bottom]
if opt[:type] == 1
# opt[:bottom] = true
# parents_reply[opt[:page]..opt[:page]]
@@ -105,7 +104,7 @@ module Mobile
#取二级回复的顶楼层
parents_reply = []
parents_reply = get_reply_parents_no_root(parents_reply, c)
- if parents_reply.count > 0 && !opt[:top]
+ if parents_reply.count >= 2 && !opt[:top]
if opt[:type] == 1
opt[:bottom] = true
tStart = (opt[:page]-1)*5+2
diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb
index 88c8ba144..aaf5dd78b 100644
--- a/app/api/mobile/entities/course.rb
+++ b/app/api/mobile/entities/course.rb
@@ -86,6 +86,15 @@ module Mobile
expose :my_homework,using: Mobile::Entities::Homework do |f, opt|
f[:my_homework] if f.is_a?(Hash) && f.key?(:my_homework)
end
+ expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
+ if instance[:course]
+ course = instance[:course]
+ else
+ course = instance
+ end
+ current_user = options[:user]
+ course.tea_id == current_user.id
+ end
course_expose :current_user_is_member
course_expose :current_user_is_teacher
course_expose :work_unit
diff --git a/app/api/mobile/entities/issue.rb b/app/api/mobile/entities/issue.rb
index b99ea03a5..dc4fd0567 100644
--- a/app/api/mobile/entities/issue.rb
+++ b/app/api/mobile/entities/issue.rb
@@ -22,10 +22,10 @@ module Mobile
(get_user(issue.assigned_to_id)).login
when :issue_status
IssueStatus.find(issue.status_id).name
- when :journals_count
- # issue.journals.where("notes is not null and notes != ''").count
- all_comments = []
- get_all_children(all_comments, f).count
+ when :comment_count
+ issue.journals.where("notes is not null and notes != ''").count
+ # all_comments = []
+ # get_all_children(all_comments, f).count
when :project_name
issue.project.name
when :praise_count
@@ -49,7 +49,7 @@ module Mobile
issue_expose :issue_priority
issue_expose :issue_assigned_to
issue_expose :issue_status
- issue_expose :journals_count
+ issue_expose :comment_count
issue_expose :project_name
issue_expose :praise_count
expose :issue_journals, using: Mobile::Entities::Journal do |f, opt|
diff --git a/app/api/mobile/entities/jours.rb b/app/api/mobile/entities/jours.rb
index f98d7a9ed..0e4c699c2 100644
--- a/app/api/mobile/entities/jours.rb
+++ b/app/api/mobile/entities/jours.rb
@@ -17,7 +17,7 @@ module Mobile
case field
when :lasted_comment
time_from_now f.created_on
- when :reply_count
+ when :comment_count
# f.children.count
all_comments = []
get_all_children(all_comments, f).count
@@ -27,6 +27,8 @@ module Mobile
'JournalsForMessage'
when :act_id
f.id
+ when :content
+ f.notes
end
end
end
@@ -42,10 +44,10 @@ module Mobile
end
jours_expose :created_on
jours_expose :lasted_comment
- jours_expose :notes
+ jours_expose :content
jours_expose :m_reply_id
jours_expose :m_parent_id
- jours_expose :reply_count
+ jours_expose :comment_count
jours_expose :praise_count
expose :course,using:Mobile::Entities::Course do |f,opt|
if f.is_a?(::JournalsForMessage) && f[:jour_type] == "Course"
@@ -55,9 +57,20 @@ module Mobile
expose :reply_user,using: Mobile::Entities::User do |f, opt|
f.at_user
end
- expose :child_reply,using: Mobile::Entities::Jours do |f, opt|
+ expose :all_children,using: Mobile::Entities::Jours do |f, opt|
if f.is_a?(::JournalsForMessage)
- f.children.reverse
+ # f.children.reverse
+ if !opt[:children] && opt[:comment_type].nil?
+ if f.parent.nil? && opt[:type] == 0
+ opt[:children] = true
+ all_comments = []
+ tStart = opt[:page]*5
+ tEnd = (opt[:page]+1)*5 - 1
+
+ all_comments = get_all_children(all_comments, f)[tStart..tEnd]
+ all_comments
+ end
+ end
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
@@ -67,6 +80,78 @@ module Mobile
has_praise = obj.empty? ? false : true
has_praise
end
+
+ expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options|
+ parents_reply = []
+
+ if options[:comment_type].nil?
+ parents_reply = get_reply_parents_no_root(parents_reply, instance)
+ elsif options[:comment_type] == "homework"
+ parents_reply = get_reply_parents(parents_reply, instance)
+ end
+ parents_reply.count
+ end
+
+ expose :parents_reply_bottom, using:Mobile::Entities::Jours do |f,opt|
+ if f.is_a? (::JournalsForMessage)
+ #取二级回复的底楼层
+ parents_reply = []
+ if opt[:comment_type].nil?
+ parents_reply = get_reply_parents_no_root(parents_reply, f)
+ elsif opt[:comment_type] == "homework"
+ parents_reply = get_reply_parents(parents_reply, f)
+ end
+ if parents_reply.count > 0 && parents_reply.count != 2 && !opt[:bottom]
+ if opt[:type] == 1
+ # opt[:bottom] = true
+ # parents_reply[opt[:page]..opt[:page]]
+ else
+ opt[:bottom] = true
+ parents_reply[0..0]
+ end
+ else
+ []
+ end
+ end
+ end
+
+ expose :parents_reply_top, using:Mobile::Entities::Jours do |f,opt|
+ if f.is_a? (::JournalsForMessage)
+ #取二级回复的顶楼层
+ parents_reply = []
+
+ if opt[:comment_type].nil?
+ parents_reply = get_reply_parents_no_root(parents_reply, f)
+ elsif opt[:comment_type] == "homework"
+ parents_reply = get_reply_parents(parents_reply, f)
+ end
+ if parents_reply.count >= 2 && !opt[:top]
+ if opt[:type] == 1
+ opt[:bottom] = true
+ tStart = (opt[:page]-1)*5+2
+ tEnd = (opt[:page])*5+2 - 1
+
+ if tEnd >= parents_reply.count - 1
+ tEnd = parents_reply.count - 2
+ end
+
+ if tStart <= parents_reply.count - 2
+ parents_reply = parents_reply.reverse[tStart..tEnd]
+ parents_reply.reverse
+ else
+ []
+ end
+ else
+ opt[:top] = true
+ parents_reply = parents_reply.reverse[0..1]
+ parents_reply.reverse
+ end
+ else
+ []
+ end
+ end
+ end
+
end
end
end
diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb
index d58192378..c2744f63a 100644
--- a/app/api/mobile/entities/message.rb
+++ b/app/api/mobile/entities/message.rb
@@ -30,7 +30,7 @@ module Mobile
'Message'
when :act_id
u.id
- when :replies_count
+ when :comment_count
all_comments = []
get_all_children(all_comments, u).count
end
@@ -51,15 +51,26 @@ module Mobile
message_expose :board_id
message_expose :subject
message_expose :content
- message_expose :replies_count
+ message_expose :comment_count
message_expose :praise_count
message_expose :created_on
message_expose :locked
message_expose :id
message_expose :lasted_comment
- expose :message_children,using:Mobile::Entities::Message do |c,opt|
+ expose :all_children,using:Mobile::Entities::Message do |c,opt|
if c.is_a? (::Message)
- c.children.reverse
+ # c.children.reverse
+ if !opt[:children]
+ if c.parent.nil? && opt[:type] == 0
+ opt[:children] = true
+ all_comments = []
+ tStart = opt[:page]*5
+ tEnd = (opt[:page]+1)*5 - 1
+
+ all_comments = get_all_children(all_comments, c)[tStart..tEnd]
+ all_comments
+ end
+ end
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
@@ -69,6 +80,63 @@ module Mobile
has_praise = obj.empty? ? false : true
has_praise
end
+
+ expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options|
+ parents_reply = []
+ parents_reply = get_reply_parents_no_root(parents_reply, instance)
+ parents_reply.count
+ end
+
+ expose :parents_reply_bottom, using:Mobile::Entities::Message do |c,opt|
+ if c.is_a? (::Message)
+ #取二级回复的底楼层
+ parents_reply = []
+ parents_reply = get_reply_parents_no_root(parents_reply, c)
+ if parents_reply.count > 0 && parents_reply.count != 2 && !opt[:bottom]
+ if opt[:type] == 1
+ # opt[:bottom] = true
+ # parents_reply[opt[:page]..opt[:page]]
+ else
+ opt[:bottom] = true
+ parents_reply[0..0]
+ end
+ else
+ []
+ end
+ end
+ end
+
+ expose :parents_reply_top, using:Mobile::Entities::Message do |c,opt|
+ if c.is_a? (::Message)
+ #取二级回复的顶楼层
+ parents_reply = []
+ parents_reply = get_reply_parents_no_root(parents_reply, c)
+ if parents_reply.count >= 2 && !opt[:top]
+ if opt[:type] == 1
+ opt[:bottom] = true
+ tStart = (opt[:page]-1)*5+2
+ tEnd = (opt[:page])*5+2 - 1
+
+ if tEnd >= parents_reply.count - 1
+ tEnd = parents_reply.count - 2
+ end
+
+ if tStart <= parents_reply.count - 2
+ parents_reply = parents_reply.reverse[tStart..tEnd]
+ parents_reply.reverse
+ else
+ []
+ end
+ else
+ opt[:top] = true
+ parents_reply = parents_reply.reverse[0..1]
+ parents_reply.reverse
+ end
+ else
+ []
+ end
+ end
+ end
end
end
end
\ No newline at end of file
diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb
index ff1452b1c..be9fa3ceb 100644
--- a/app/api/mobile/entities/news.rb
+++ b/app/api/mobile/entities/news.rb
@@ -24,9 +24,8 @@ module Mobile
'News'
when :act_id
f.id
- when :comments_count
- all_comments = []
- get_all_children(all_comments, f).count
+ when :comment_count
+ f.comments.count
end
end
elsif f.is_a?(Hash) && !f.key?(field)
@@ -70,7 +69,7 @@ module Mobile
#发布时间
news_expose :created_on
#评论数量
- news_expose :comments_count
+ news_expose :comment_count
news_expose :praise_count
#课程名字
news_expose :course_name
diff --git a/app/api/mobile/entities/project.rb b/app/api/mobile/entities/project.rb
new file mode 100644
index 000000000..3e1899caa
--- /dev/null
+++ b/app/api/mobile/entities/project.rb
@@ -0,0 +1,32 @@
+module Mobile
+ module Entities
+ class Project < Grape::Entity
+ expose :name
+ expose :id
+ expose :user_id
+ # expose :invite_code
+ # expose :qrcode
+ expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
+ current_user = options[:user]
+
+ my_member = instance.member_principals.where("users.id=#{current_user.id}").first
+ can_setting = false
+ if my_member && my_member.roles[0] && my_member.roles[0].id == 3
+ can_setting = true
+ end
+ can_setting
+ end
+
+ expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
+ current_user = options[:user]
+
+ current_user.id == instance.user_id
+ end
+
+
+ expose :member_count, if: lambda { |instance, options| options[:user] } do |instance, options|
+ instance.members.count
+ end
+ end
+ end
+end
diff --git a/app/api/mobile/entities/project_member.rb b/app/api/mobile/entities/project_member.rb
new file mode 100644
index 000000000..58edf7ea7
--- /dev/null
+++ b/app/api/mobile/entities/project_member.rb
@@ -0,0 +1,35 @@
+module Mobile
+ module Entities
+ class ProjectMember < Grape::Entity
+ include Redmine::I18n
+ include ApplicationHelper
+ include ApiHelper
+ def self.member_expose(f)
+ expose f do |u,opt|
+ if u.is_a?(Hash) && u.key?(f)
+ u[f]
+ elsif u.is_a?(::Member)
+ if u.respond_to?(f)
+ u.send(f)
+ else
+ case f
+ when :roles_id
+ u.roles[0].id
+ end
+ end
+ end
+
+ end
+ end
+
+ expose :user, using: Mobile::Entities::User do |c, opt|
+ if c.is_a?(::Member)
+ c.user
+ end
+ end
+
+ member_expose :roles_id
+
+ end
+ end
+end
diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb
index 2eb20f0db..dcdf48d3b 100644
--- a/app/api/mobile/entities/user.rb
+++ b/app/api/mobile/entities/user.rb
@@ -24,10 +24,12 @@ module Mobile
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction
when :student_num
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id
- when :realname
- u.nil? ? "" : get_user_realname(u)
+ when :real_name
+ u.nil? ? "" : get_user_realname(u).gsub(/\s*/,"");
when :name
u.nil? ? "" : u.show_name
+ when :roles_id
+ u[:roles_id].nil? ? nil : u.roles_id
end
end
end
@@ -37,11 +39,13 @@ module Mobile
expose :id
#头像
- user_expose :img_url
- #昵称
expose :nickname
#真名
- user_expose :realname
+ user_expose :img_url
+ #昵称
+ expose :realname
+ #昵称
+ user_expose :real_name
#性别
user_expose :gender
#我的二维码
@@ -62,6 +66,8 @@ module Mobile
user_expose :role_name
+ user_expose :roles_id
+
user_expose :name
end
diff --git a/app/api/mobile/entities/whomework.rb b/app/api/mobile/entities/whomework.rb
index 8985f3d60..7178ff67d 100644
--- a/app/api/mobile/entities/whomework.rb
+++ b/app/api/mobile/entities/whomework.rb
@@ -26,7 +26,7 @@ module Mobile
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
when :praise_count
get_activity_praise_num(wh)
- when :whomework_journal_count
+ when :comment_count
wh.journals_for_messages.count
when :course_name
wh.course.name
@@ -58,6 +58,7 @@ module Mobile
expose :anonymous_comment
expose :quotes
expose :is_open
+ expose :id
whomework_expose :act_type
whomework_expose :act_id
whomework_expose :course_name
@@ -66,11 +67,19 @@ module Mobile
whomework_expose :evaluation_start
whomework_expose :evaluation_end
whomework_expose :praise_count
- whomework_expose :whomework_journal_count
- expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt|
+ whomework_expose :comment_count
+ expose :all_children, using: Mobile::Entities::Jours do |f, opt|
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
if f.is_a?(::HomeworkCommon)
- f.journals_for_messages.reverse
+ # f.journals_for_messages.reverse
+ if !opt[:children] && opt[:type] == 0
+ opt[:children] = true
+ tStart = opt[:page]*5
+ tEnd = (opt[:page]+1)*5 - 1
+
+ all_comments = f.journals_for_messages.reorder("created_on desc")
+ all_comments[tStart..tEnd]
+ end
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
diff --git a/app/api/mobile/exceptions/auth_exception.rb b/app/api/mobile/exceptions/auth_exception.rb
new file mode 100644
index 000000000..5dceab572
--- /dev/null
+++ b/app/api/mobile/exceptions/auth_exception.rb
@@ -0,0 +1,13 @@
+#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
diff --git a/app/api/mobile/middleware/error_handler.rb b/app/api/mobile/middleware/error_handler.rb
index 699dd1537..94d74e568 100644
--- a/app/api/mobile/middleware/error_handler.rb
+++ b/app/api/mobile/middleware/error_handler.rb
@@ -1,3 +1,6 @@
+#coding=utf-8
+
+
module Mobile
module Middleware
class ErrorHandler < Grape::Middleware::Base
@@ -6,7 +9,10 @@ module Mobile
begin
@app.call(@env)
rescue =>e
- message = {status: 1, message: e.message }.to_json
+ code = 1
+
+ message = {status: code, message: e.message }.to_json
+
Rails.logger.error e.inspect
Rails.logger.error e.backtrace.join("\n")
status = 200
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 21dac6ada..a38cc8d34 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -636,8 +636,11 @@ class CoursesController < ApplicationController
end
if @course
#发送微信消息
- ss = SyllabusesService.new
- ss.send_wechat_create_class_notice User.current,@course
+ count = ShieldWechatMessage.where("container_type='User' and container_id=#{User.current.id} and shield_type='Course' and shield_id=#{@course.id}").count
+ if count == 0
+ ss = SyllabusesService.new
+ ss.send_wechat_create_class_notice User.current,@course
+ end
respond_to do |format|
flash[:notice] = l(:notice_successful_create)
format.html {redirect_to course_url(@course)}
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index d8c174bc3..f135c8ab2 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -238,6 +238,10 @@ class ProjectsController < ApplicationController
#end
@project.members << m
@project.project_infos << project_info
+
+ p = Project.find("#{@project.id}")
+ ps = ProjectsService.new
+ ps.send_wechat_create_project_notice User.current,p
#end
respond_to do |format|
format.html {
diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb
index dab752afb..d02a7d859 100644
--- a/app/controllers/school_controller.rb
+++ b/app/controllers/school_controller.rb
@@ -203,6 +203,7 @@ class SchoolController < ApplicationController
end
end
+
render :json =>status
end
end
diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb
index 6b1e3010d..23a443925 100644
--- a/app/controllers/wechats_controller.rb
+++ b/app/controllers/wechats_controller.rb
@@ -8,10 +8,12 @@ class WechatsController < ActionController::Base
# default text responder when no other match
on :text do |request, content|
#邀请码
- if join_request(request)
+ if join_class_request(request)
sendBindClass(request, {invite_code: content})
+ # elsif join_project_request(request)
+ # sendBindProject(request, {invite_code: content})
else
- request.reply.text '您的意见已收到,感谢您的反馈!'
+ request.reply.text "您的意见已收到,非常感谢~ \n更多问题可以通过以下方式联系我们:\n官方QQ群:173184401\n我们会认真聆听您的意见和建议。"
end
end
@@ -143,11 +145,17 @@ class WechatsController < ActionController::Base
end
on :click, with: 'PROJECT' do |request, key|
- request.reply.text "此功能正在开发中,很快就会上线,谢谢!"
+ request.reply.text "该功能将在近日开放,敬请期待!"
end
on :click, with: 'JOIN_PROJECT' do |request, key|
- request.reply.text "此功能正在开发中,很快就会上线,谢谢!"
+ request.reply.text "该功能将在近日开放,敬请期待!"
+ # uw = user_binded?(request[:FromUserName])
+ # unless uw
+ # sendBind(request)
+ # else
+ # request.reply.text "请直接回复6位项目邀请码\n(不区分大小写):"
+ # end
end
on :click, with: 'JOIN_CLASS' do |request, key|
@@ -159,12 +167,18 @@ class WechatsController < ActionController::Base
end
end
- def join_request(request)
+ def join_class_request(request)
openid = request[:FromUserName]
wl = WechatLog.where("openid = '#{openid}' and request_raw like '%\"Event\":\"click\"%'").order('id desc').first
wl && JSON(wl.request_raw)["EventKey"] == 'JOIN_CLASS'
end
+ def join_project_request(request)
+ openid = request[:FromUserName]
+ wl = WechatLog.where("openid = '#{openid}' and request_raw like '%\"Event\":\"click\"%'").order('id desc').first
+ wl && JSON(wl.request_raw)["EventKey"] == 'JOIN_PROJECT'
+ end
+
def sendBindClass(request, params)
begin
uw = user_binded?(request[:FromUserName])
@@ -180,6 +194,21 @@ class WechatsController < ActionController::Base
end
end
+ def sendBindProject(request, params)
+ begin
+ uw = user_binded?(request[:FromUserName])
+ if !uw
+ return sendBind(request)
+ else
+ return join_project(params, uw.user, request)
+ end
+ rescue => e
+ logger.error e.inspect
+ logger.error e.backtrace.join("\n")
+ return request.reply.text e
+ end
+ end
+
def default_msg(request)
uw = user_binded?(request[:FromUserName])
if uw && uw.user
@@ -234,6 +263,36 @@ class WechatsController < ActionController::Base
end
+ def join_project(params, user, request)
+ project = nil
+ project = Project.where(qrcode: params[:ticket]).first if params[:ticket]
+ project = Project.where(invite_code: params[:invite_code]).first if params[:invite_code]
+ raise "项目不存在,请确认您的邀请码是否输入正确,谢谢!" unless project
+
+ #取出用户角色类型
+ role = 5
+
+ ps = ProjectsService.new
+ status = ps.join_project({invite_code: project.invite_code}, user)
+ if status[:state] != 0
+ raise ProjectService::JoinProjectError.message(status)
+ end
+
+ creator = User.find(project.user_id)
+
+ news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入项目,开始研发吧!',
+ content: "项目名称:#{project.name}\n发起人:#{creator.name}\n进入项目,和小伙伴轻松的研发吧!"} }
+ return request.reply.news(news) do |article, n, index| # article is return object
+ url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities#/project?id='+project.id.to_s}&response_type=code&scope=snsapi_base&state=myproject#wechat_redirect"
+ pic_url = "#{ROOT_URL}/images/wechat/class.jpg"
+ article.item title: "#{n[:title]}",
+ description: n[:content],
+ pic_url: pic_url,
+ url: url
+ end
+
+ end
+
### controller method
module Controllers
def get_bind
@@ -288,8 +347,7 @@ class WechatsController < ActionController::Base
session[:wechat_code] = params[:code] if params[:code]
openid = get_openid_from_code(params[:code])
@wechat_user = user_binded?(openid)
-
- render 'wechats/login', layout: 'base_wechat'
+ render 'wechats/user_activities', layout: nil
end
def user_activities
@@ -299,13 +357,20 @@ class WechatsController < ActionController::Base
unless open_id
render 'wechats/open_wechat', layout: nil and return
end
- if params[:state] == 'myclass'
- @course_id = params[:id];
- end
+
+ unless user_binded?(open_id)
+ @path = '/login'
+ else
+ if params[:state] == 'myclass'
+ @course_id = params[:id];
+ elsif params[:state] == 'myproject'
+ @project_id = params[:id];
+ end
- session[:wechat_openid] = open_id
- if params[:code]
- redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return
+ session[:wechat_openid] = open_id
+ if params[:code]
+ redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return
+ end
end
render 'wechats/user_activities', layout: nil
end
diff --git a/app/models/project.rb b/app/models/project.rb
index bbc639f3d..aa70084d2 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -165,6 +165,7 @@ class Project < ActiveRecord::Base
scope :has_module, lambda {|mod|
where("#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s)
}
+ scope :not_deleted, lambda{where("status<>9")}
scope :active, lambda { where(:status => STATUS_ACTIVE) }
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
scope :all_public, lambda { where(:is_public => true) }
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index d864b6462..811d73f55 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -89,7 +89,8 @@ class CoursesService
@members = searchTeacherAndAssistant(c)
when '2'
#@subPage_title = l :label_student_list
- @members = searchStudent(c)
+ # @members = searchStudent(c)
+ @members = searchmember_by_name(student_homework_score(0,c.id, 0,"desc"),"")
else
#@subPage_title = ''
@members = c.member_principals.includes(:roles, :principal).all.sort
@@ -104,6 +105,7 @@ class CoursesService
:work_unit => work_unit, :mail => m.user.mail, :location => location,
role_name: m.roles.first.name,
name: m.user.show_name,
+ roles_id: m.roles[0].id,
:brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname}
end
users
@@ -954,5 +956,49 @@ class CoursesService
# student_works[index + 1 .. index + n]
# end
+ #修改班级成员角色
+ def modify_user_course_role params
+ status = -1
+
+ c = Course.find("#{params[:id]}")
+
+ member = c.member_principals.includes(:roles, :principal).where("user_id=?",params[:user_id]).first
+
+ if member
+ role = Role.find(params[:role_id])
+
+ member.member_roles[0].role_id = params[:role_id]
+
+ # 这里的判断只能通过角色名,可以弄成常量
+ if params[:role_id] == 10
+ StudentsForCourse.create(:student_id => params[:user_id], :course_id =>params[:id])
+ else
+ joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:id])
+ joined.each do |join|
+ join.delete
+ end
+ member.course_group_id = 0
+ end
+ if role.allowed_to?(:is_manager)
+ courseInfo = CourseInfos.new(:user_id => params[:user_id], :course_id => params[:id])
+ courseInfo.save
+ else
+ user_admin = CourseInfos.where("user_id = ? and course_id = ?", params[:user_id], params[:id])
+ if user_admin.size > 0
+ user_admin.each do |user|
+ user.destroy
+ end
+ end
+ end
+
+ Role.givable.all[3..5]
+
+ if member.member_roles[0].save
+ status = 0
+ end
+ end
+ status
+ end
+
end
diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb
new file mode 100644
index 000000000..91b9a0336
--- /dev/null
+++ b/app/services/projects_service.rb
@@ -0,0 +1,145 @@
+#coding=utf-8
+
+class ProjectsService
+
+ include ApplicationHelper
+
+ #获取指定用户的项目列表
+ def user_projects(user)
+ projects = user.projects.not_deleted.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updated_at ").order("updated_at desc")
+ projects
+ end
+
+ #显示项目
+ def show_project(params,current_user)
+ project = Project.find(params[:id])
+ # project.generate_invite_code
+ # project.generate_qrcode
+
+ project
+ end
+
+ def send_wechat_create_project_notice user,project
+ count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count
+ Rails.logger.info "!!!!!!!!!!!!!!!!!!!!!!#{project}"
+ if count == 0
+ ws = WechatService.new
+ title = "恭喜您创建项目成功。"
+ ws.create_project_notice user.id, "create_project_notice", project.id,title, project.name, format_time(project.created_on),"点击查看项目详情。"
+ end
+ end
+
+
+ def createNewProject params,user
+ status = -1
+ issue_custom_fields = IssueCustomField.sorted.all
+ trackers = Tracker.sorted.all
+ project = Project.new
+
+ project[:name] = params[:name]
+ project[:description] = ''
+ project[:is_public] = '1' #公开
+ project[:project_type] = 0
+ project[:project_new_type] = 1
+ project[:identifier] = Project.next_identifier if Setting.sequential_project_identifiers?
+
+ project.organization_id = params[:organization_id]
+ project.user_id = user.id
+
+ # if validate_parent_id && @project.save
+ if project.save
+ p = Project.find("#{project.id}")
+ send_wechat_create_project_notice user,p
+ r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
+ m = Member.new(:user => user, :roles => [r])
+ # project's score
+ if ProjectScore.where("project_id=?", project.id).first.nil?
+ ProjectScore.create(:project_id => project.id, :score => false)
+ end
+ # end
+ project_info = ProjectInfo.new(:user_id => user.id, :project_id => project.id)
+ user_grades = UserGrade.create(:user_id => user.id, :project_id => project.id)
+ project_status = ProjectStatus.create(:project_id => project.id, :watchers_count => 0, :changesets_count => 0, :project_type => project.project_type,:grade => 0)
+ project.members << m
+ project.project_infos << project_info
+ status = 0
+ end
+ status
+ end
+
+ #修改项目成员角色
+ def modify_user_project_role params
+ status = -1
+
+ project = Project.find("#{params[:id]}")
+
+ member = project.member_principals.includes(:roles, :principal).where("user_id=?",params[:user_id]).first
+
+ if member
+ member.member_roles[0].role_id = params[:role_id]
+
+
+ role = Role.find(params[:role_id])
+ if role.allowed_to?(:is_manager)
+ projectInfo = ProjectInfo.new(:user_id => member.user_id, :project_id => project.id)
+ projectInfo.save
+ else
+ user_admin = ProjectInfo.where("user_id = ? and project_id = ?", member.user_id, project.id)
+ if user_admin.size > 0
+ user_admin.each do |user|
+ user.destroy
+ end
+ end
+ end
+
+ if member.member_roles[0].save
+ status = 0
+ end
+ end
+ status
+ end
+
+ class JoinProjectError < Errors
+ define_error [
+ 0, '加入成功',
+ 1, '您的邀请码不正确',
+ 2, '您还未登录',
+ 3, '您已经是该项目的管理人员',
+ 4, '您已经是该项目的开发人员',
+ 5, '您已经是该项目的报告人员',
+ 6, '该项目不存在或已被删除啦',
+ '未知错误,请稍后再试'
+ ]
+ end
+
+ def join_project params,current_user
+ status = -1
+ project = project.find_by_invite_code(params[:invite_code]) if params[:invite_code]
+
+ if project
+ if project[:is_delete] == 1
+ status = 6
+ else
+ if current_user.member_of?(project) #如果已经是成员
+ member = project.member_principals.includes(:roles, :principal).where("user_id=?",current_user.id).first
+ status = member.member_roles[0].role_id
+ else
+ if params[:invite_code].present?
+ members = []
+ members << Member.new(:role_ids => [5], :user_id => current_user.id)
+ project.members << members
+ projectInfo = ProjectInfo.new(:user_id => current_user.id, :project_id => project.id)
+ projectInfo.save
+ status = 0
+ else
+ status = 4
+ end
+ end
+ end
+ else
+ status = 4
+ end
+ status
+ end
+
+end
diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb
index 7ac4e99d3..5f52aea49 100644
--- a/app/services/wechat_service.rb
+++ b/app/services/wechat_service.rb
@@ -323,4 +323,41 @@ class WechatService
end
end
+ def create_project_notice(user_id, type, id, first, key1, key2,remark="")
+ uw = UserWechat.where(user_id: user_id).first
+ unless uw.nil?
+ data = {
+ touser:uw.openid,
+ template_id:Wechat.config.create_project_notice,
+ url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/project?id="+id.to_s,
+ topcolor:"#FF0000",
+ data:{
+ first: {
+ value:first,
+ color:"#707070"
+ },
+ keyword1:{
+ value:key1,
+ color:"#707070"
+ },
+ keyword2:{
+ value:key2,
+ color:"#707070"
+ },
+ remark:{
+ value:remark,
+ color:"#707070"
+ }
+ }
+ }
+ #data = three_keys_template uw.openid,Wechat.config.create_class_notice, type, id, first, key1, key2, key3, remark
+ begin
+ req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
+ rescue Exception => e
+ Rails.logger.error "[wechat_create_project_notice] ===> #{e}"
+ end
+ Rails.logger.info "send over. #{req}"
+ end
+ end
+
end
\ No newline at end of file
diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb
index d21449648..f5cfb8250 100644
--- a/app/views/wechats/user_activities.html.erb
+++ b/app/views/wechats/user_activities.html.erb
@@ -18,6 +18,8 @@
window.g_redirect_path = '<%= @path %>';
<% if @course_id %>
window.g_courseid = <%= @course_id %>;
+ <% elsif @project_id %>
+ window.g_projectid = <%= @project_id %>;
<% end %>
diff --git a/config/menu.yml b/config/menu.yml
index cc799b531..19891b911 100644
--- a/config/menu.yml
+++ b/config/menu.yml
@@ -30,11 +30,11 @@ button:
type: "click"
name: "加入项目"
key: "JOIN_PROJECT"
- -
- type: "click"
- name: "反馈"
- key: "FEEDBACK"
-
type: "view"
name: "历史推文"
url: "http://mp.weixin.qq.com/mp/getmasssendmsg?__biz=MzIwOTM2NDkxMA==#wechat_webview_type=1&wechat_redirect"
+ -
+ type: "click"
+ name: "联系我们"
+ key: "FEEDBACK"
diff --git a/config/menu.yml.production b/config/menu.yml.production
index 1128f9961..fb9ef41a3 100644
--- a/config/menu.yml.production
+++ b/config/menu.yml.production
@@ -2,18 +2,22 @@ button:
-
type: "view"
name: "我的动态"
- url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=http://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=activities#wechat_redirect"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=activities#wechat_redirect"
-
- name: "我的课程"
+ name: "我的群组"
sub_button:
-
type: "view"
- name: "课程"
- url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=http://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=class_list#wechat_redirect"
+ name: "我的课程"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=class_list#wechat_redirect"
+ -
+ type: "click"
+ name: "我的项目"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=project_list#wechat_redirect"
-
type: "view"
- name: "资源"
- url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=http://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=myresource#wechat_redirect"
+ name: "我的宝库"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=myresource#wechat_redirect"
-
name: "更多"
@@ -24,9 +28,13 @@ button:
key: "JOIN_CLASS"
-
type: "click"
- name: "反馈"
- key: "FEEDBACK"
+ name: "加入项目"
+ key: "JOIN_PROJECT"
-
type: "view"
name: "历史推文"
url: "http://mp.weixin.qq.com/mp/getmasssendmsg?__biz=MzIwOTM2NDkxMA==#wechat_webview_type=1&wechat_redirect"
+ -
+ type: "click"
+ name: "联系我们"
+ key: "FEEDBACK"
diff --git a/config/menu.yml.test b/config/menu.yml.test
index 521ff290a..bdc47ba8d 100644
--- a/config/menu.yml.test
+++ b/config/menu.yml.test
@@ -2,22 +2,22 @@ button:
-
type: "view"
name: "我的动态"
- url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=activities#wechat_redirect"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=activities#wechat_redirect"
-
name: "我的群组"
sub_button:
-
type: "view"
name: "我的课程"
- url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=class_list#wechat_redirect"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=class_list#wechat_redirect"
-
- type: "click"
+ type: "view"
name: "我的项目"
- key: "PROJECT"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=project_list#wechat_redirect"
-
type: "view"
name: "我的宝库"
- url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=myresource#wechat_redirect"
+ url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=myresource#wechat_redirect"
-
name: "更多"
@@ -30,11 +30,11 @@ button:
type: "click"
name: "加入项目"
key: "JOIN_PROJECT"
- -
- type: "click"
- name: "反馈"
- key: "FEEDBACK"
-
type: "view"
name: "历史推文"
url: "http://mp.weixin.qq.com/mp/getmasssendmsg?__biz=MzIwOTM2NDkxMA==#wechat_webview_type=1&wechat_redirect"
+ -
+ type: "click"
+ name: "联系我们"
+ key: "FEEDBACK"
diff --git a/config/wechat.yml b/config/wechat.yml.template
similarity index 54%
rename from config/wechat.yml
rename to config/wechat.yml.template
index b8bf670a1..ee2be1c51 100644
--- a/config/wechat.yml
+++ b/config/wechat.yml.template
@@ -2,19 +2,11 @@ default: &default
# corpid: "corpid"
# corpsecret: "corpsecret"
# agentid: 1
-#
-#- # guange test
- #appid: "wxf694495398c7d470"
- #secret: "743e038392f1d89540e95f8f7645849a"
#production
appid: "wx8e1ab05163a28e37"
secret: "beb4d3bc4b32b3557811680835357841"
- #test
-# appid: "wxc09454f171153c2d"
-# secret: "dff5b606e34dcafe24163ec82c2715f8"
-
token: "123456"
access_token: "1234567"
encrypt_mode: false # if true must fill encoding_aes_key
@@ -22,24 +14,14 @@ default: &default
#production
encoding_aes_key: "QGfP13YP4BbQGkkrlYuxpn4ZIDXpBJww4fxl8CObvNw"
jsapi_ticket: "C:/Users/[user_name]/wechat_jsapi_ticket"
-#
-# #template
+
+ #template
binding_succ_notice: "jjpDrgFErnmkrE9tf2M3o0t31ZrJ7mr0YtuE_wyLaMc"
journal_notice: "uC1zAw4F2q6HTA3Pcj8VUO6wKKKiYFwnPJB4iXxpdoM"
homework_message_notice: "tCf7teCVqc2vl2LZ_hppIdWmpg8yLcrI8XifxYePjps"
class_notice: "MQ_mFupbXP-9jWbeHT3C5xqNBvPo8EIlNv4ULakSpJA"
create_class_notice: "2GtJJGzzNlNy2i0UrsjEDlvfSVIUXQfSo47stpcQAVw"
-
- #test
-# encoding_aes_key: "QyocNOkRmrT5HzBpCG54EVPUQjk86nJapXNVDQm6Yy6"
-# jsapi_ticket: "C:/Users/[user_name]/wechat_jsapi_ticket"
-#
-# #template
-# binding_succ_notice: "n4KLwcWNrIMYkKxWL2hUwzunm5RTT54EbWem2MIUapU"
-# journal_notice: "XpHHYkqSGkwuF9vHthRdmPQLvCFRQ4_NbRBP12T7ciE"
-# homework_message_notice: "Kom0TsYYKsNKCS6luweYVRo9z-mH0wRPr24b1clGCPQ"
-# class_notice: "8LVu33l6bP-56SDomVgHn-yJc57YpCwwJ81rAJgRONk"
-# create_class_notice: "9CDIvHIKiGwPEQWRw_-wieec1o50tMXQPPZIfECKu0I"
+ create_project_notice: "R2ZaQKJfDJgujPcHWPzadKHIRkIyj2CjX2o_qIuRqig"
production:
<<: *default
diff --git a/config/wechat.yml.test b/config/wechat.yml.test
index 9bc33029e..ec5e760fa 100644
--- a/config/wechat.yml.test
+++ b/config/wechat.yml.test
@@ -2,26 +2,26 @@ default: &default
# corpid: "corpid"
# corpsecret: "corpsecret"
# agentid: 1
-# Or if using public account, only need above two line
- # guange test
- #appid: "wxf694495398c7d470"
- #secret: "743e038392f1d89540e95f8f7645849a"
-
- appid: "wx8e1ab05163a28e37"
- secret: "beb4d3bc4b32b3557811680835357841"
+ #test
+ appid: "wxc09454f171153c2d"
+ secret: "dff5b606e34dcafe24163ec82c2715f8"
token: "123456"
- access_token: ".access_token"
+ access_token: "1234567"
encrypt_mode: false # if true must fill encoding_aes_key
- encoding_aes_key: "QGfP13YP4BbQGkkrlYuxpn4ZIDXpBJww4fxl8CObvNw"
- jsapi_ticket: "tmp/wechat_jsapi_ticket"
+
+ #test
+ encoding_aes_key: "QyocNOkRmrT5HzBpCG54EVPUQjk86nJapXNVDQm6Yy6"
+ jsapi_ticket: "C:/Users/[user_name]/wechat_jsapi_ticket"
#template
- binding_succ_notice: "jjpDrgFErnmkrE9tf2M3o0t31ZrJ7mr0YtuE_wyLaMc"
- journal_notice: "uC1zAw4F2q6HTA3Pcj8VUO6wKKKiYFwnPJB4iXxpdoM"
- homework_message_notice: "tCf7teCVqc2vl2LZ_hppIdWmpg8yLcrI8XifxYePjps"
- class_notice: "MQ_mFupbXP-9jWbeHT3C5xqNBvPo8EIlNv4ULakSpJA"
+ binding_succ_notice: "n4KLwcWNrIMYkKxWL2hUwzunm5RTT54EbWem2MIUapU"
+ journal_notice: "XpHHYkqSGkwuF9vHthRdmPQLvCFRQ4_NbRBP12T7ciE"
+ homework_message_notice: "Kom0TsYYKsNKCS6luweYVRo9z-mH0wRPr24b1clGCPQ"
+ class_notice: "8LVu33l6bP-56SDomVgHn-yJc57YpCwwJ81rAJgRONk"
+ create_class_notice: "9CDIvHIKiGwPEQWRw_-wieec1o50tMXQPPZIfECKu0I"
+ create_project_notice: "R2ZaQKJfDJgujPcHWPzadKHIRkIyj2CjX2o_qIuRqig"
production:
<<: *default
diff --git a/db/schema.rb b/db/schema.rb
index 3a92d4fc0..c7d918346 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20160720094503) do
+ActiveRecord::Schema.define(:version => 20160725091759) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -67,6 +67,7 @@ ActiveRecord::Schema.define(:version => 20160720094503) do
t.integer "status", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "user_id"
end
create_table "apply_homeworks", :force => true do |t|
@@ -395,6 +396,17 @@ ActiveRecord::Schema.define(:version => 20160720094503) do
add_index "comments", ["author_id"], :name => "index_comments_on_author_id"
add_index "comments", ["commented_id", "commented_type"], :name => "index_comments_on_commented_id_and_commented_type"
+ create_table "commits", :force => true do |t|
+ t.integer "repository_id"
+ t.string "version"
+ t.string "committer"
+ t.text "comments"
+ t.datetime "committed_on"
+ t.integer "project_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "contest_notifications", :force => true do |t|
t.text "title"
t.text "content"
diff --git a/lib/email_verifier b/lib/email_verifier
deleted file mode 160000
index 222a9bdd7..000000000
--- a/lib/email_verifier
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 222a9bdd72014f197baf2131ab71cc41660111ed
diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
index 06d661478..26c78cdd2 100644
--- a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
+++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
@@ -51,7 +51,7 @@ module Redmine
#通过model层删除以触发before_destroy事件 -by zjc
watchers = Watcher.find_by_sql "select * from `watchers` where watchable_type = 'Principal' AND watchable_id = #{self.id} AND user_id = #{user.id}"
watchers.each do |watcher|
- watcher.destroy
+ watcher.destroy
end
#Watcher.delete_all "watchable_type = 'Principal' AND watchable_id = #{self.id} AND user_id = #{user.id}"
else
diff --git a/lib/wechat/lib/wechat.rb b/lib/wechat/lib/wechat.rb
index 266e1aa06..c223844b7 100644
--- a/lib/wechat/lib/wechat.rb
+++ b/lib/wechat/lib/wechat.rb
@@ -1,3 +1,4 @@
+require 'wechat/cache_file.rb'
require 'wechat/api_loader'
require 'wechat/api'
require 'wechat/corp_api'
diff --git a/lib/wechat/lib/wechat/cache_file.rb b/lib/wechat/lib/wechat/cache_file.rb
new file mode 100644
index 000000000..0e51b24ee
--- /dev/null
+++ b/lib/wechat/lib/wechat/cache_file.rb
@@ -0,0 +1,25 @@
+#coding=utf-8
+#
+
+module Wechat
+ class CacheFile
+ class << self
+ def cache
+ if defined?(Rails)
+ Rails.cache
+ else
+ File
+ end
+ end
+
+ def read(key)
+ cache.read(key) || ''
+ end
+
+ def write(key, val)
+ cache.write(key, val)
+ end
+ end
+ end
+end
+
diff --git a/lib/wechat/lib/wechat/ticket/jsapi_base.rb b/lib/wechat/lib/wechat/ticket/jsapi_base.rb
index b6ab510a0..cc02ce243 100644
--- a/lib/wechat/lib/wechat/ticket/jsapi_base.rb
+++ b/lib/wechat/lib/wechat/ticket/jsapi_base.rb
@@ -44,7 +44,7 @@ module Wechat
protected
def read_ticket_from_file
- td = JSON.parse(File.read(jsapi_ticket_file))
+ td = JSON.parse(CacheFile.read(jsapi_ticket_file))
@got_ticket_at = td.fetch('got_ticket_at').to_i
@ticket_life_in_seconds = td.fetch('expires_in').to_i
@access_ticket = td.fetch('ticket')
@@ -54,7 +54,7 @@ module Wechat
def write_ticket_to_file(ticket_hash)
ticket_hash.merge!('got_ticket_at'.freeze => Time.now.to_i)
- File.write(jsapi_ticket_file, ticket_hash.to_json)
+ CacheFile.write(jsapi_ticket_file, ticket_hash.to_json)
end
def remain_life_seconds
diff --git a/lib/wechat/lib/wechat/token/access_token_base.rb b/lib/wechat/lib/wechat/token/access_token_base.rb
index 7b8cecfac..ba980e319 100644
--- a/lib/wechat/lib/wechat/token/access_token_base.rb
+++ b/lib/wechat/lib/wechat/token/access_token_base.rb
@@ -21,7 +21,7 @@ module Wechat
protected
def read_token_from_file
- td = JSON.parse(File.read(token_file))
+ td = JSON.parse(CacheFile.read(token_file))
@got_token_at = td.fetch('got_token_at').to_i
@token_life_in_seconds = td.fetch('expires_in').to_i
@access_token = td.fetch('access_token')
@@ -31,7 +31,7 @@ module Wechat
def write_token_to_file(token_hash)
token_hash.merge!('got_token_at'.freeze => Time.now.to_i)
- File.write(token_file, token_hash.to_json)
+ CacheFile.write(token_file, token_hash.to_json)
end
def remain_life_seconds
diff --git a/plugins/redmine_ckeditor/.gitmodules b/plugins/redmine_ckeditor/.gitmodules
deleted file mode 100644
index de30e7590..000000000
--- a/plugins/redmine_ckeditor/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "app/assets/javascripts/ckeditor-releases"]
- path = app/assets/javascripts/ckeditor-releases
- url = git://github.com/ckeditor/ckeditor-releases.git
diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html
index d18575b94..ee9e968d2 100644
--- a/public/assets/wechat/blog_detail.html
+++ b/public/assets/wechat/blog_detail.html
@@ -13,11 +13,13 @@