Merge branch 'develop' of https://git.trustie.net/jacknudt/trustieforge into develop
Conflicts: .access_tokendev_pull v20160708_04
commit
320db4ddd9
@ -0,0 +1,114 @@
|
||||
source 'https://ruby.taobao.org/'
|
||||
|
||||
unless RUBY_PLATFORM =~ /w32/
|
||||
# unix-like only
|
||||
gem 'iconv'
|
||||
gem "rmagick", ">= 2.0.0"
|
||||
gem 'certified'
|
||||
end
|
||||
|
||||
gem 'net-ssh', '2.9.1'
|
||||
gem 'jenkins_api_client'
|
||||
gem 'nokogiri'
|
||||
|
||||
gem 'wechat',path: 'lib/wechat'
|
||||
gem 'grack', path:'lib/grack'
|
||||
gem 'gitlab', path: 'lib/gitlab-cli'
|
||||
gem 'rest-client'
|
||||
gem "mysql2", "= 0.3.18"
|
||||
gem 'redis-rails'
|
||||
gem 'rubyzip'
|
||||
gem 'delayed_job_active_record'#, :group => :production
|
||||
gem 'daemons'
|
||||
gem 'grape', '~> 0.9.0'
|
||||
gem 'grape-entity'
|
||||
gem 'rack-cors', :require => 'rack/cors'
|
||||
gem 'seems_rateable', '~> 1.0.13'
|
||||
gem 'rails', '~> 3.2'
|
||||
gem "jquery-rails", "~> 2.0.2"
|
||||
gem "i18n", "~> 0.6.0"
|
||||
gem 'coderay', '~> 1.1.0'
|
||||
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
|
||||
gem "builder", "3.0.0"
|
||||
gem 'acts-as-taggable-on', '2.4.1'
|
||||
gem 'spreadsheet'
|
||||
gem 'ruby-ole'
|
||||
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
|
||||
gem 'binding_of_caller'
|
||||
gem 'chinese_pinyin'
|
||||
# gem 'sunspot_rails', '~> 1.3.3'
|
||||
# gem 'sunspot_solr'
|
||||
# gem 'sunspot'
|
||||
# gem 'progress_bar'
|
||||
gem 'ansi'
|
||||
|
||||
gem 'kaminari'
|
||||
gem 'elasticsearch-model'
|
||||
gem 'elasticsearch-rails'
|
||||
|
||||
|
||||
### profile
|
||||
#gem 'oneapm_rpm'
|
||||
|
||||
group :development do
|
||||
gem 'grape-swagger'
|
||||
gem 'better_errors', '~> 1.1.0'
|
||||
# gem "query_reviewer"
|
||||
# gem 'rack-mini-profiler', '~> 0.9.3'
|
||||
if RUBY_PLATFORM =~ /w32/
|
||||
gem 'win32console'
|
||||
end
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
unless RUBY_PLATFORM =~ /w32/
|
||||
gem 'pry-rails'
|
||||
if RUBY_VERSION >= '2.0.0'
|
||||
gem 'pry-byebug'
|
||||
end
|
||||
gem 'pry-stack_explorer'
|
||||
if RUBY_PLATFORM =~ /darwin/
|
||||
gem 'puma'
|
||||
end
|
||||
end
|
||||
|
||||
gem 'rspec-rails', '~> 3.0'
|
||||
gem 'factory_girl_rails'
|
||||
end
|
||||
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
group :assets do
|
||||
gem 'sass-rails', '~> 3.2.3'
|
||||
gem 'coffee-rails', '~> 3.2.1'
|
||||
|
||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||
# gem 'therubyracer', :platforms => :ruby
|
||||
|
||||
gem 'uglifier', '>= 1.0.3'
|
||||
end
|
||||
|
||||
# Optional gem for LDAP authentication
|
||||
group :ldap do
|
||||
gem "net-ldap", "~> 0.3.1"
|
||||
end
|
||||
|
||||
|
||||
# Optional gem for OpenID authentication
|
||||
group :openid do
|
||||
gem "ruby-openid", "~> 2.1.4", :require => "openid"
|
||||
gem "rack-openid"
|
||||
end
|
||||
|
||||
|
||||
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
|
||||
if File.exist?(database_file)
|
||||
else
|
||||
warn("Please configure your config/database.yml first")
|
||||
end
|
||||
|
||||
# Load plugins' Gemfiles
|
||||
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
|
||||
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
|
||||
instance_eval File.read(file)
|
||||
end
|
@ -0,0 +1,103 @@
|
||||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Syllabuses < Grape::API
|
||||
|
||||
resources :syllabuses do
|
||||
desc "获取大纲列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
|
||||
cs = SyllabusesService.new
|
||||
courses = cs.user_syllabus(current_user)
|
||||
present :data, courses, with: Mobile::Entities::Syllabus
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取某个大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':id' do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ::Syllabus.find(params[:id])
|
||||
sy.courses = sy.courses.not_deleted
|
||||
sy = ss.judge_can_setting(sy,current_user)
|
||||
|
||||
present :data, sy, with: Mobile::Entities::Syllabus
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取新建大纲的权限"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'auth' do
|
||||
authenticate!
|
||||
|
||||
auth = 0
|
||||
|
||||
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
|
||||
auth = 1
|
||||
end
|
||||
|
||||
present :auth, auth
|
||||
end
|
||||
|
||||
desc "新建大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
requires :courses, type: Array[String], desc: '课程名'
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ss.create(current_user, params[:title],
|
||||
params[:courses].map{|c| {name: c} })
|
||||
|
||||
if sy.new_record?
|
||||
{status:-1, message: '创建大纲失败' }
|
||||
else
|
||||
present :data, sy, with: Mobile::Entities::Syllabus
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc '编辑大纲'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
# requires :add_courses, type: Array[String], desc: '课程名'
|
||||
# requires :modify_courses, type: Array[Integer,String], desc: '课程名'
|
||||
end
|
||||
post ':id/edit' do
|
||||
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
#修改课程大纲
|
||||
status = ss.edit(current_user, params)
|
||||
|
||||
if status == -1
|
||||
{status:status, message: '修改课程信息失败' }
|
||||
else
|
||||
present :status, status
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
module Mobile
|
||||
module Entities
|
||||
class Syllabus < Grape::Entity
|
||||
include ApplicationHelper
|
||||
|
||||
expose :title
|
||||
expose :id
|
||||
expose :can_setting
|
||||
|
||||
expose :courses, using: Mobile::Entities::Course
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,53 @@
|
||||
#coding=utf-8
|
||||
|
||||
class ResourcesService
|
||||
|
||||
#发送资源到课程
|
||||
def send_resource_to_course user,params
|
||||
send_id = params[:send_id]
|
||||
@ori = Attachment.find_by_id(send_id)
|
||||
course_ids = params[:course_ids]
|
||||
@flag = false
|
||||
unless course_ids.nil?
|
||||
course_ids.each do |id|
|
||||
next if @ori.blank?
|
||||
@exist = false
|
||||
Course.find(id).attachments.each do |att| #如果课程中包含该资源
|
||||
if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from
|
||||
att.created_on = Time.now
|
||||
att.save
|
||||
@exist = true
|
||||
@flag = true
|
||||
break
|
||||
end
|
||||
end
|
||||
next if @exist
|
||||
attach_copied_obj = @ori.copy
|
||||
attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联
|
||||
attach_copied_obj.container = Course.find(id)
|
||||
attach_copied_obj.created_on = Time.now
|
||||
attach_copied_obj.author_id = user.id
|
||||
attach_copied_obj.is_public = 0
|
||||
attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from
|
||||
if attach_copied_obj.attachtype == nil
|
||||
attach_copied_obj.attachtype = 4
|
||||
end
|
||||
if attach_copied_obj.save
|
||||
# 更新引用次数
|
||||
quotes = @ori.quotes.to_i + 1
|
||||
@ori.update_attribute(:quotes, quotes) unless @ori.nil?
|
||||
@ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
|
||||
@flag = true
|
||||
else
|
||||
@flag = false
|
||||
@save_message = attach_copied_obj.errors.full_messages
|
||||
break
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
[@ori, @flag, @save_message]
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,143 @@
|
||||
#coding=utf-8
|
||||
|
||||
class SyllabusesService
|
||||
|
||||
include ApplicationHelper
|
||||
include CoursesHelper
|
||||
|
||||
def judge_can_setting(sy,user)
|
||||
sy[:can_setting] = sy[:user_id] == user.id ? true : false
|
||||
|
||||
sy[:can_setting] = false if sy[:id].nil?
|
||||
|
||||
sy.courses.each do |c|
|
||||
c[:can_setting] = false
|
||||
|
||||
member = c.members.where("user_id=#{user.id} and course_id=#{c.id}")[0]
|
||||
roleName = member.roles[0].name if member
|
||||
|
||||
if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" )
|
||||
c[:can_setting] = true
|
||||
end
|
||||
|
||||
if c.tea_id == user.id
|
||||
c[:can_setting] = true
|
||||
end
|
||||
end
|
||||
|
||||
sy
|
||||
end
|
||||
#获取指定用户的课程大纲
|
||||
def user_syllabus(user)
|
||||
courses = CoursesService.new.user_courses_list(user)
|
||||
|
||||
other = Syllabus.new(title: '未命名课程',user_id: user.id)
|
||||
|
||||
courses.each do |c|
|
||||
other.courses << c[:course] unless c[:course].syllabus
|
||||
end
|
||||
|
||||
# user.syllabuses.each do |syllabus|
|
||||
# syllabus.courses = syllabus.courses.not_deleted
|
||||
# end
|
||||
#
|
||||
# user.syllabuses.to_a << other
|
||||
|
||||
courses = user.courses.not_deleted
|
||||
syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
|
||||
syllabuses = Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc")
|
||||
|
||||
syllabuses.each do |syllabus|
|
||||
syllabus.courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc")
|
||||
end
|
||||
|
||||
syllabuses.to_a << other
|
||||
|
||||
#管理权限 can_setting
|
||||
syllabuses.each do |s|
|
||||
s = judge_can_setting(s,user)
|
||||
end
|
||||
|
||||
syllabuses
|
||||
end
|
||||
|
||||
def after_create_course(course, user)
|
||||
#unless User.current.admin?
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => user, :roles => [r])
|
||||
m.project_id = -1
|
||||
course_info = CourseInfos.new(:user_id => user.id, :course_id => course.id)
|
||||
#user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
|
||||
course.members << m
|
||||
course.course_infos << course_info
|
||||
end
|
||||
|
||||
#创建大纲
|
||||
# params {title: '大纲名称', [{course}, {course}]}
|
||||
def create(user, title, courses = [])
|
||||
sy = Syllabus.new(title: title, user_id: user.id)
|
||||
ActiveRecord::Base.transaction() do
|
||||
sy.save!
|
||||
|
||||
courses.each do |course|
|
||||
if ::Course === course
|
||||
course.syllabus_id = sy.id
|
||||
course.save!
|
||||
elsif Hash === course
|
||||
c = ::Course.new(course)
|
||||
c.tea_id = user.id
|
||||
c.syllabus_id = sy.id
|
||||
c.update_default_value
|
||||
c.is_public = 0
|
||||
c.save!
|
||||
after_create_course(c, user)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
sy[:can_setting] = true
|
||||
sy
|
||||
end
|
||||
|
||||
#修改课程大纲的名称、班级名称、新增班级
|
||||
def edit(user, option)
|
||||
courses = []
|
||||
status = -1
|
||||
syllabus_id = option[:id]
|
||||
|
||||
sy = Syllabus.where("id=?",option[:id]).first
|
||||
|
||||
if sy && sy.user_id == user.id
|
||||
syllabus_title = option[:title]
|
||||
|
||||
sy.title = syllabus_title
|
||||
sy.save!
|
||||
#修改班级名称
|
||||
modify_courses = option[:modify_courses]
|
||||
modify_courses.each do |c|
|
||||
course = Course.where("id=?",c.id).first
|
||||
|
||||
if course && course.tea_id == user.id
|
||||
course.name = c.name
|
||||
!course.save
|
||||
end
|
||||
end
|
||||
|
||||
#新增班级
|
||||
add_courses = option[:add_courses]
|
||||
add_courses.each do |c|
|
||||
course = Course.new()
|
||||
course.name = c
|
||||
course.tea_id = user.id
|
||||
course.syllabus_id = sy.id
|
||||
course.update_default_value
|
||||
course.is_public = 0
|
||||
course.save!
|
||||
after_create_course(course, user)
|
||||
end
|
||||
status = 0
|
||||
end
|
||||
status
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,33 @@
|
||||
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"
|
||||
|
||||
token: "123456"
|
||||
access_token: ".access_token"
|
||||
encrypt_mode: false # if true must fill encoding_aes_key
|
||||
encoding_aes_key: "QGfP13YP4BbQGkkrlYuxpn4ZIDXpBJww4fxl8CObvNw"
|
||||
jsapi_ticket: "tmp/wechat_jsapi_ticket"
|
||||
|
||||
#template
|
||||
binding_succ_notice: "jjpDrgFErnmkrE9tf2M3o0t31ZrJ7mr0YtuE_wyLaMc"
|
||||
journal_notice: "uC1zAw4F2q6HTA3Pcj8VUO6wKKKiYFwnPJB4iXxpdoM"
|
||||
homework_message_notice: "tCf7teCVqc2vl2LZ_hppIdWmpg8yLcrI8XifxYePjps"
|
||||
class_notice: "MQ_mFupbXP-9jWbeHT3C5xqNBvPo8EIlNv4ULakSpJA"
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
|
||||
test:
|
||||
<<: *default
|
@ -0,0 +1,8 @@
|
||||
class RenewQrcode < ActiveRecord::Migration
|
||||
def up
|
||||
Course.update_all(:qrcode => '')
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue