|
|
|
@ -14,66 +14,130 @@ module Mobile
|
|
|
|
|
requires :token, type: String
|
|
|
|
|
end
|
|
|
|
|
post ':id' do
|
|
|
|
|
authenticate!
|
|
|
|
|
# authenticate!
|
|
|
|
|
status = 0
|
|
|
|
|
tip = 0 #0班级1项目
|
|
|
|
|
type = params[:type]
|
|
|
|
|
result = 1
|
|
|
|
|
if params[:content]!="" && current_user
|
|
|
|
|
case type
|
|
|
|
|
when "HomeworkCommon"
|
|
|
|
|
homework_common = HomeworkCommon.find(params[:id])
|
|
|
|
|
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
|
|
|
|
|
if (feedback.errors.empty?)
|
|
|
|
|
homework_common.update_column(:updated_at, Time.now)
|
|
|
|
|
result = 2
|
|
|
|
|
|
|
|
|
|
#如果是私有的 并且不是成员则不能回复
|
|
|
|
|
is_public = homework_common.course.is_public
|
|
|
|
|
if is_public == 0 && !current_user.member_of_course?(homework_common.course)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 0
|
|
|
|
|
else
|
|
|
|
|
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
|
|
|
|
|
if (feedback.errors.empty?)
|
|
|
|
|
homework_common.update_column(:updated_at, Time.now)
|
|
|
|
|
result = 2
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
when "News"
|
|
|
|
|
news = News.find(params[:id])
|
|
|
|
|
comment = Comment.new
|
|
|
|
|
comment.comments = params[:content]
|
|
|
|
|
comment.author = current_user
|
|
|
|
|
if news.comments << comment
|
|
|
|
|
result = 2
|
|
|
|
|
|
|
|
|
|
if news.project
|
|
|
|
|
if news.project.is_public == false && !current_user.member_of?(news.project)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 1
|
|
|
|
|
end
|
|
|
|
|
elsif news.course
|
|
|
|
|
if news.course.is_public == 0 && !current_user.member_of_course?(news.course)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if status == 0
|
|
|
|
|
comment = Comment.new
|
|
|
|
|
comment.comments = params[:content]
|
|
|
|
|
comment.author = current_user
|
|
|
|
|
if news.comments << comment
|
|
|
|
|
result = 2
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
when "Message"
|
|
|
|
|
message = Message.find(params[:id])
|
|
|
|
|
board = Board.find(message.board_id)
|
|
|
|
|
topic = message.root
|
|
|
|
|
reply = Message.new
|
|
|
|
|
reply.author = current_user
|
|
|
|
|
reply.board = board
|
|
|
|
|
reply.content = params[:content]
|
|
|
|
|
reply.parent_id = params[:id]
|
|
|
|
|
reply.subject = "RE: #{topic.subject}"
|
|
|
|
|
if topic.children << reply
|
|
|
|
|
result = 2
|
|
|
|
|
|
|
|
|
|
if message.project
|
|
|
|
|
if message.project.is_public == false && !current_user.member_of?(message.project)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 1
|
|
|
|
|
end
|
|
|
|
|
elsif message.course
|
|
|
|
|
if message.course.is_public == 0 && !current_user.member_of_course?(message.course)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if status == 0
|
|
|
|
|
topic = message.root
|
|
|
|
|
reply = Message.new
|
|
|
|
|
reply.author = current_user
|
|
|
|
|
reply.board = board
|
|
|
|
|
reply.content = params[:content]
|
|
|
|
|
reply.parent_id = params[:id]
|
|
|
|
|
reply.subject = "RE: #{topic.subject}"
|
|
|
|
|
if topic.children << reply
|
|
|
|
|
result = 2
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
when "JournalsForMessage"
|
|
|
|
|
jour = JournalsForMessage.find params[:id]
|
|
|
|
|
parent_id = params[:id]
|
|
|
|
|
author_id = current_user.id
|
|
|
|
|
reply_user_id = jour.user_id
|
|
|
|
|
reply_id = params[:id]
|
|
|
|
|
content = params[:content]
|
|
|
|
|
options = {:user_id => author_id,
|
|
|
|
|
:status => true,
|
|
|
|
|
:m_parent_id => parent_id,
|
|
|
|
|
:m_reply_id => reply_id,
|
|
|
|
|
:reply_id => reply_user_id,
|
|
|
|
|
:notes => content,
|
|
|
|
|
:is_readed => false}
|
|
|
|
|
jfm = jour.user.add_jour(nil, nil, nil, options)
|
|
|
|
|
if jfm.errors.empty?
|
|
|
|
|
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
|
|
|
|
|
result = 2
|
|
|
|
|
|
|
|
|
|
if jour.jour_type == "Project"
|
|
|
|
|
if jour.project.is_public == false && !current_user.member_of?(jour.project)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 1
|
|
|
|
|
end
|
|
|
|
|
elsif jour.jour_type == "Course"
|
|
|
|
|
if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if status == 0
|
|
|
|
|
parent_id = params[:id]
|
|
|
|
|
author_id = current_user.id
|
|
|
|
|
reply_user_id = jour.user_id
|
|
|
|
|
reply_id = params[:id]
|
|
|
|
|
content = params[:content]
|
|
|
|
|
options = {:user_id => author_id,
|
|
|
|
|
:status => true,
|
|
|
|
|
:m_parent_id => parent_id,
|
|
|
|
|
:m_reply_id => reply_id,
|
|
|
|
|
:reply_id => reply_user_id,
|
|
|
|
|
:notes => content,
|
|
|
|
|
:is_readed => false}
|
|
|
|
|
jfm = jour.user.add_jour(nil, nil, nil, options)
|
|
|
|
|
if jfm.errors.empty?
|
|
|
|
|
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
|
|
|
|
|
result = 2
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
when 'Issue'
|
|
|
|
|
issue = Issue.find params[:id]
|
|
|
|
|
is_jour = Journal.new
|
|
|
|
|
is_jour.user_id = current_user.id
|
|
|
|
|
is_jour.notes = params[:content]
|
|
|
|
|
is_jour.journalized = issue
|
|
|
|
|
if is_jour.save
|
|
|
|
|
result = 2
|
|
|
|
|
|
|
|
|
|
if issue.project.is_public == false && !current_user.member_of?(issue.project)
|
|
|
|
|
status = -1
|
|
|
|
|
tip = 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if status == 0
|
|
|
|
|
is_jour = Journal.new
|
|
|
|
|
is_jour.user_id = current_user.id
|
|
|
|
|
is_jour.notes = params[:content]
|
|
|
|
|
is_jour.journalized = issue
|
|
|
|
|
if is_jour.save
|
|
|
|
|
result = 2
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
when 'BlogComment'
|
|
|
|
|
blog = BlogComment.find(params[:id]).root
|
|
|
|
@ -97,7 +161,8 @@ module Mobile
|
|
|
|
|
result = 3
|
|
|
|
|
end
|
|
|
|
|
present :result, result
|
|
|
|
|
present :status, 0
|
|
|
|
|
present :status, status
|
|
|
|
|
present :tip, tip
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|