diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 369185ca2..bfd559402 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -287,6 +287,30 @@ module Mobile end end + desc "获取课程动态" + params do + requires :id, type: Integer + requires :token, type: String + end + post 'activities' do + authenticate! + + user = current_user + + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + activities = UserActivity.where("(container_type = 'Course' and container_id = #{params[:id]} and act_type in #{course_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 :token, type: String @@ -558,6 +582,85 @@ module Mobile end end + desc "发布班级通知" + params do + requires :id, type: Integer + requires :token, type: String + requires :text, type: String + requires :title, type: String + end + post ':id/publishnotice' do + authenticate! + + #老师或教辅才能发通知 + c = Course.find("#{params[:id]}") + + my_member = c.member_principals.where("users.id=#{current_user.id}").first + + roles_ids = [] + my_member.roles.each do |role| + roles_ids << role.id + end + if my_member && (roles_ids.include?(7)|| roles_ids.include?(9) || roles_ids.include?(3)) + + tmpparams = {} + tmpparams['title'] = params[:title] + tmpparams['description'] = params[:text] + tmpparams['sticky'] = 0 + + news = News.new(:course => c, :author => current_user) + #render :layout => 'base_courses' + news.safe_attributes = tmpparams + + news.save! + + present :status, 0 + else + present :status, -1 + present :message,"学生不能发布通知" + end + end + + desc "发布班级问题" + params do + requires :id, type: Integer + requires :token, type: String + requires :text, type: String + end + post ':id/publishissue' do + authenticate! + + c = Course.find("#{params[:id]}") + + boards = c.boards.includes(:last_message => :author).all + if c.boards.empty? + board = c.boards.build + board.name = "班级问答区" + board.description = c.name.to_s + board.project_id = -1 + if board.save + boards = c.boards.includes(:last_message => :author).all + end + end + + board = boards.first + + message = Message.new + message.author = current_user + message.board = board + + tmpparams = {} + tmpparams['subject'] = params[:title] + tmpparams['content'] = params[:text] + + message.safe_attributes = tmpparams + + message.save! + + present :status, 0 + + end + end end end diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb index dfd5a3335..271e3419d 100644 --- a/app/api/mobile/apis/issues.rb +++ b/app/api/mobile/apis/issues.rb @@ -17,11 +17,21 @@ module Mobile #0一级回复的更多 1 二级回复的更多 type = params[:type] || 0 page = params[:page] || 0 - issue = Issue.find params[:id] - present :data, issue, with: Mobile::Entities::Issue,user: user,type: type,page: page + + is_public = 1 + + if type == 0 + issue = Issue.find params[:id] + issue.project.is_public + present :data, issue, with: Mobile::Entities::Issue,user: user,type: type,page: page + else + jour = Journal.find params[:id] + present :data, jour, with: Mobile::Entities::Issue,user: user,type: type,page: page + end + present :type, type present :page, page - present :is_public, issue.project.is_public + present :is_public,is_public present :status, 0 rescue Exception=>e present :status, -1 diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index c2e2fcb5c..810e4ff2a 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -14,14 +14,19 @@ module Mobile #0一级回复的更多 1 二级回复的更多 type = params[:type] || 0 page = params[:page] || 0 - news = News.find params[:id] is_public = 1 - if news.project - is_public = news.project.is_public - elsif news.course - is_public = news.course.is_public + if type == 0 + news = News.find params[:id] + + if news.project + is_public = news.project.is_public + elsif news.course + is_public = news.course.is_public + end + else + news = Comment.find params[:id] end present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page diff --git a/app/api/mobile/apis/projects.rb b/app/api/mobile/apis/projects.rb index 05d4036f9..2202fbd13 100644 --- a/app/api/mobile/apis/projects.rb +++ b/app/api/mobile/apis/projects.rb @@ -229,6 +229,45 @@ module Mobile present :message, result[:message] end + desc "发布项目帖子" + params do + requires :id, type: Integer + requires :token, type: String + requires :text, type: String + end + post ':id/publishnote' do + authenticate! + + project = Project.find("#{params[:id]}") + + boards = project.boards.includes(:last_message => :author).all + if project.boards.empty? + board = project.boards.build + board.name = "项目讨论区" + board.description = project.name.to_s + board.course_id = -1 + if board.save + boards = project.boards.includes(:last_message => :author).all + end + end + + board = boards.first + + message = Message.new + message.author = current_user + message.board = board + + tmpparams = {} + tmpparams['subject'] = params[:title] + tmpparams['content'] = params[:text] + + message.safe_attributes = tmpparams + + message.save! + + present :status, 0 + + end end end end diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index 0ad3a9dfb..a56deaad3 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -40,6 +40,8 @@ module Mobile ac.act.subject unless ac.nil? || ac.act.nil? elsif ac.act_type == "JournalsForMessage" ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil? + elsif ac.act_type == "Poll" + ac.act.polls_name unless ac.nil? || ac.act.nil? end when :description if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News" @@ -48,6 +50,8 @@ module Mobile strip_html(ac.act.content) unless ac.nil? || ac.act.nil? elsif ac.act_type == "JournalsForMessage" strip_html(ac.act.notes) unless ac.nil? || ac.act.nil? + elsif ac.act_type == "Poll" + ac.act.polls_description unless ac.nil? || ac.act.nil? end when :latest_update time_from_now ac.updated_at unless ac.nil? diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index 028ad633d..8200c04b2 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -23,6 +23,8 @@ module Mobile (number_to_human_size(f.filesize)).gsub("ytes", "").to_s when :coursename f.course.nil? ? "" : f.course.name + when :course_id + f.course.nil? ? 0 : f.course.id end end @@ -38,6 +40,7 @@ module Mobile attachment_expose :file_dir attachment_expose :attafile_size attachment_expose :coursename #所属班级名 + attachment_expose :course_id #所属班级名 expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options| current_user = options[:user] current_user_is_teacher = false diff --git a/app/api/mobile/entities/issue.rb b/app/api/mobile/entities/issue.rb index 9cbeb3459..e3dbb5023 100644 --- a/app/api/mobile/entities/issue.rb +++ b/app/api/mobile/entities/issue.rb @@ -36,15 +36,42 @@ module Mobile issue.id when :title issue.subject + when :subject + issue.subject + when :description + issue.description + when :done_ratio + issue.done_ratio end end + elsif issue.is_a?(::Journal) + case f + when :content + issue[:notes] + when :lasted_comment + time_from_now issue.created_on + when :act_id + issue.id + end end end end - expose :subject - expose :description - expose :author, using: Mobile::Entities::User - expose :done_ratio + issue_expose :subject + issue_expose :description + expose :author, using: Mobile::Entities::User do |f, opt| + if f.is_a?(::Issue) + f.send(:author) + end + end + expose :user,using: Mobile::Entities::User do |f, opt| + if f.is_a?(::Journal) + f.send(:user) + end + end + issue_expose :content + issue_expose :lasted_comment + + issue_expose :done_ratio issue_expose :title issue_expose :act_type issue_expose :act_id @@ -55,11 +82,29 @@ module Mobile issue_expose :comment_count issue_expose :project_name issue_expose :praise_count - expose :issue_journals, using: Mobile::Entities::Journal do |f, opt| + + expose :id + # expose :issue_journals, using: Mobile::Entities::Journal do |f, opt| + # if f.is_a?(::Issue) + # f.journals.where("notes is not null and notes != ''").reverse + # end + # end + + expose :all_children, using: Mobile::Entities::Issue do |f, opt| + #f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages) if f.is_a?(::Issue) - f.journals.where("notes is not null and notes != ''").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.where("notes is not null and notes != ''").reorder("created_on desc") + all_comments[tStart..tEnd] + end end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| has_praise = false current_user = options[:user] @@ -67,6 +112,69 @@ module Mobile has_praise = obj.empty? ? false : true has_praise end + + expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| + if instance.is_a?(::Journal) + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, instance) + parents_reply.count + end + end + + expose :parents_reply_bottom, using:Mobile::Entities::Issue do |f,opt| + if f.is_a? (::Journal) + #取二级回复的底楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 0 && !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::Issue do |f,opt| + if f.is_a? (::Journal) + #取二级回复的顶楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 2 && !opt[:top] + if opt[:type] == 1 + opt[:top] = 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 + elsif parents_reply.count == 2 && !opt[:top] + opt[:top] = true + parents_reply = parents_reply.reverse[0..0] + parents_reply.reverse + 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 be9fa3ceb..a64081d8a 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -28,6 +28,16 @@ module Mobile f.comments.count end end + elsif f.is_a?(::Comment) + case field + when :content + f[:comments] + when :lasted_comment + time_from_now f.created_on + when :act_id + f.id + end + elsif f.is_a?(Hash) && !f.key?(field) n = f[:news] comments = f[:comments] @@ -43,14 +53,16 @@ module Mobile end end end - news_expose :id + expose :id #新闻标题 news_expose :title - expose :author,using: Mobile::Entities::User do |f, opt| + expose :user,using: Mobile::Entities::User do |f, opt| obj = nil if f.is_a?(::News) && f.respond_to?(:author) obj = f.send(:author) + elsif f.is_a?(::Comment) && f.respond_to?(:author) + obj = f.send(:author) elsif f.is_a?(Hash) && f.key?(:author) obj = f[:author] end @@ -73,14 +85,34 @@ module Mobile news_expose :praise_count #课程名字 news_expose :course_name + news_expose :lasted_comment + #评论 - expose :comments, using: Mobile::Entities::Comment do |f, opt| - if f.is_a?(Hash) && f.key?(:comments) - f[:comments] - elsif f.is_a?(::News) && f.respond_to?(:comments) - f.comments.reverse + # expose :comments, using: Mobile::Entities::Comment do |f, opt| + # if f.is_a?(Hash) && f.key?(:comments) + # f[:comments] + # elsif f.is_a?(::News) && f.respond_to?(:comments) + # f.comments.reverse + # end + # end + + news_expose :content + + expose :all_children, using: Mobile::Entities::News do |f, opt| + #f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages) + if f.is_a?(::News) + # 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.comments.reorder("created_on desc") + all_comments[tStart..tEnd] + end end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| has_praise = false current_user = options[:user] @@ -88,6 +120,69 @@ module Mobile has_praise = obj.empty? ? false : true has_praise end + + expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| + if instance.is_a?(::Comment) + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, instance) + parents_reply.count + end + end + + expose :parents_reply_bottom, using:Mobile::Entities::News do |f,opt| + if f.is_a? (::Comment) + #取二级回复的底楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 0 && !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::News do |f,opt| + if f.is_a? (::Comment) + #取二级回复的顶楼层 + parents_reply = [] + parents_reply = get_reply_parents(parents_reply, f) + if parents_reply.count > 2 && !opt[:top] + if opt[:type] == 1 + opt[:top] = 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 + elsif parents_reply.count == 2 && !opt[:top] + opt[:top] = true + parents_reply = parents_reply.reverse[0..0] + parents_reply.reverse + else + [] + end + end + end end end end \ No newline at end of file diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 8187055be..02dfe9a45 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -26,7 +26,15 @@ class AccountController < ApplicationController if request.get? @login = params[:login] || true if User.current.logged? - redirect_to user_path(User.current) + # 判断用户基本资料是否完善,不完善讲强制完善基本资料,完善进入主页 + user = UserExtensions.where(:user_id => User.current.id).first + if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? + redirect_to my_account_path(:tip => 1) + elsif user.identity == 3 && user.school_id.nil? + redirect_to my_account_path(:tip => 1) + else + redirect_to user_path(User.current) + end else render :layout => 'login' end @@ -127,7 +135,7 @@ class AccountController < ApplicationController session[:auth_source_registration] = nil self.logged_user = @user flash[:notice] = l(:notice_account_activated) - redirect_to my_account_path + redirect_to my_account_path(:tip=>1) end else us = UsersService.new @@ -144,7 +152,7 @@ class AccountController < ApplicationController if !@user.new_record? self.logged_user = @user flash[:notice] = l(:notice_account_activated) - redirect_to my_account_url + redirect_to my_account_url(:tip=>1) else redirect_to signin_path end @@ -347,9 +355,17 @@ class AccountController < ApplicationController else #by young #redirect_back_or_default my_page_path - redirect_back_or_default User.current + # 基本资料不完善的用户,将强制用户完善基本资料。 + user = UserExtensions.where(:user_id => User.current.id).first + if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? + redirect_to my_account_path(:tip => 1) + elsif user.identity == 3 && user.school_id.nil? + redirect_to my_account_path(:tip => 1) + else + redirect_back_or_default User.current #redirect_to my_account_url #redirect_to User.current + end end end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 3c012fce7..25cc85ae2 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -698,7 +698,7 @@ class AdminController < ApplicationController apply_school_ids = apply_schools.empty? ? "(-1)" : "(" + apply_schools.map{|sc| sc.school_id}.join(',') + ")" if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" - @schools = School.where("id not in #{apply_school_ids} and #{School.table_name}.name like :p",:p=>search) + @schools = School.where("id not in #{apply_school_ids} and #{School.table_name}.name like :p", :p => search) #@schools = School.all else #@course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)} diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 0e48cd962..66cbf27b8 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -10,7 +10,7 @@ class AtController < ApplicationController @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users #加上all - if @user && @users.size > 0 + if User.current.logged? && @users.size > 0 allUser = Struct.new(:id, :name).new allUser.id = @users.map{|u| u.id}.join(",") allUser.name = "all" diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index fa2c87f8c..7ec532d79 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -202,6 +202,11 @@ class AttachmentsController < ApplicationController end @attachment.save @newfiledense = filedense + end + if @project + + elsif @course + end respond_to do |format| format.js diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index cd3870e9a..988768414 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -325,6 +325,7 @@ class FilesController < ApplicationController @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] show_attachments @containers + # get_attachment_for_tip(@all_attachments) @tag_list = attachment_tag_list @all_attachments @@ -377,6 +378,7 @@ class FilesController < ApplicationController @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] show_attachments @containers + # get_attachment_for_tip(@all_attachments) @tag_list = attachment_tag_list @all_attachments @@ -440,6 +442,39 @@ class FilesController < ApplicationController end + # 获取提示中私有、公开总数信息 + def get_attachment_for_tip all_attachment + + @tip_all_public_attachments = all_attachment.select{|attach| attach.is_public == 1}.count + if params[:project_id] + if User.current.member_of?(@project) || User.current.admin? + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = all_attachment.select{|attach| attach.is_public == 0}.count + else + if params[:tag_name] + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = 0 + else + @tip_all_attachments = Attachment.where(:container_id => params[:project_id], :container_type => "Project").count + @tip_all_private_attachments = Attachment.where(:container_id => params[:project_id], :container_type => "Project", :is_public => 0).count + end + end + elsif params[:course_id] + if User.current.member_of_course?(@course) || User.current.admin? + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = all_attachment.select{|attach| attach.is_public == 0}.count + else + if params[:tag_name] + @tip_all_attachments = all_attachment.count + @tip_all_private_attachments = 0 + else + @tip_all_attachments = Attachment.where(:container_id => params[:course_id], :container_type => "Course").count + @tip_all_private_attachments = Attachment.where(:container_id => params[:course_id], :container_type => "Course", :is_public => 0).count + end + end + end + end + def quote_resource_show @file = Attachment.find(params[:id]) @can_quote = attachment_candown @file @@ -883,6 +918,7 @@ class FilesController < ApplicationController end @all_attachments = @result + get_attachment_for_tip(@all_attachments) @limit = 10 @feedback_count = @all_attachments.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 63ef30b35..b0c83e869 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -189,6 +189,15 @@ class IssuesController < ApplicationController # 给该issue在它所在的项目中所有的issues中所在的位置给一个序号 @issue.project_issues_index = @issue.project.issues.last.nil? ? 1 : @issue.project.issues.last.project_issues_index + 1 if @issue.save + + senduser = User.find(params[:issue][:assigned_to_id]) + issue_id = @issue.id + issue_title = params[:issue][:subject] + priority_id = params[:issue][:priority_id] + + ps = ProjectsService.new + ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id + call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) respond_to do |format| format.html { @@ -581,6 +590,18 @@ class IssuesController < ApplicationController end end @issue.safe_attributes = issue_attributes + + senduser = User.find(params[:issue][:assigned_to_id]) + + if senduser.id != User.current.id + issue_id = @issue.id + issue_title = params[:issue][:subject] + priority_id = params[:issue][:priority_id] + + ps = ProjectsService.new + ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id + end + @priorities = IssuePriority.active @allowed_statuses = @issue.new_statuses_allowed_to(User.current) true diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index d661350c6..97222f0bd 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -229,7 +229,7 @@ class MembersController < ApplicationController user_ids.each do |user_id| member = Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) - role_ids = attrs.delete(:role_ids) + role_ids = params[:membership][:role_ids] #role = Role.find(params[:membership][:role_ids]) # 这里的判断只能通过角色名,可以弄成常量 if role_ids && role_ids.include?("10") diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 858c7e5c3..c4935a1af 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -134,9 +134,15 @@ class MyController < ApplicationController applied_message.update_attribute(:viewed, true) end + # 基本资料不完善 @force为false, 完善 @force为true + @force = false + if params[:tip] + @force = true + end + @user = User.current - lg=@user.login + lg = @user.login @pref = @user.pref diskfile = disk_filename('User', @user.id) diskfile1 = diskfile + 'temp' @@ -159,8 +165,10 @@ class MyController < ApplicationController @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') #@user.login = params[:login] unless @user.user_extensions.nil? - if @user.user_extensions.identity == 2 + # 如果用户是从业者,将单位名称保存至学校id字段 + if @user.user_extensions.identity == 3 # @user.firstname = params[:enterprise_name] + @user.user_extensions.school_id = params[:occupation] end end @@ -171,7 +179,6 @@ class MyController < ApplicationController # @se.occupation = params[:occupation] # end @se.school_id = params[:occupation] - @se.gender = params[:sex] @se.location = params[:province] if params[:province] @se.location_city = params[:city] if params[:city] @@ -194,11 +201,17 @@ class MyController < ApplicationController @user.login = lg end end + # 不管前面是否有异常,如果文件已存在就删除 ensure File.delete(diskfile1) if File.exist?(diskfile1) end - render :layout=>'new_base_user' + # 基本资料不完善,无法使用其他功能,完善着可继续使用 + if @force + render :layout => 'new_base_user_show' + else + render :layout => 'new_base_user' + end end # Destroys user's account diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 5e21f9af0..b67a74439 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,8 +1,10 @@ class PullRequestsController < ApplicationController + before_filter :authorize_logged before_filter :find_project_and_repository before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pull_request, :pull_request_commits, :pull_request_changes, :new, :update_pull_request, :pull_request_comments, :create_pull_request_comment] + layout "base_projects" include PullRequestsHelper include ApplicationHelper @@ -235,6 +237,13 @@ class PullRequestsController < ApplicationController end private + def authorize_logged + if !User.current.logged? + redirect_to signin_path + return + end + end + def connect_gitlab @g = Gitlab.client end diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index a0b275dc7..9fbe5bc3c 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -241,6 +241,19 @@ class QualityAnalysisController < ApplicationController complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=#{filter}").read @complexity =JSON.parse(complexity_date).first + # 获取排名结果 + @g = Gitlab.client + author_infos = @g.rep_user_stats(@project.gpid, :rev => @branch) + @user_quality_infos = [] + author_infos.each do |author_info| + email = author_info.email + changes = author_info.changes.to_i + user_issues = open(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}&resolved=false").read + issue_count = JSON.parse(user_issues)["total"].to_i + ratio = (changes == 0 ? 0 : format("%0.4f",issue_count.to_f/changes.to_f)) + @user_quality_infos << {:email => email, :changes => changes, :issue_count => issue_count, :ratio => ratio} + end + # 按名称转换成hash键值对 @ha = {} @complexity["msr"].each do |com| diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 6ccfbcce1..54486221e 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -418,10 +418,15 @@ class WechatsController < ActionController::Base logger.info "user_activities!!!!!!!!!!!!!!" logger.info params + + #保证下面的redirect_to "/wechat/user_activities##{@path}?id=...不会往下走 + if params[:state] == nil + return + end - # unless (user_binded?(open_id) || params[:state] == "invite_code" || params[:state] == "project_invite_code" || params[:state] == "blog_comment" || params[:state] == "course_notice" || params[:state] == "project_discussion" || params[:state] == "course_discussion" || params[:state] == "homework" || params[:state] == "issues" || params[:state] == "journal_for_message") - # @path = '/login' - # else + unless (user_binded?(open_id) || params[:state] == "invite_code" || params[:state] == "project_invite_code" || params[:state] == "blog_comment" || params[:state] == "course_notice" || params[:state] == "project_discussion" || params[:state] == "course_discussion" || params[:state] == "homework" || params[:state] == "issues" || params[:state] == "journal_for_message") + @path = '/login' + else if params[:state] == 'myclass' @course_id = params[:id]; elsif params[:state] == 'myproject' @@ -430,8 +435,12 @@ class WechatsController < ActionController::Base session[:wechat_openid] = open_id if params[:code] - if params[:userid] - redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}&userid=#{params[:userid]}" and return + # if params[:state].match("review_class_member") || params[:state].match("review_project_member") + @path = params[:state].split('/')[0] + useridstr = params[:state].split('/')[1] + # end + if useridstr + redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}{useridstr}" and return elsif params[:id] redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return else @@ -439,7 +448,7 @@ class WechatsController < ActionController::Base end # redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return end - # end + end render 'wechats/user_activities', layout: nil end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 304194e6e..2d6e84762 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -820,6 +820,11 @@ module ApplicationHelper return @result end + def show_attachment_tip container_id, container_type + atts = Attachment.where(:container_id => container_id, :container_type => container_type, :is_public => 0) + atts.count > 0 ? true :false + end + # 必须是项目成,项目必须提交过代码 def allow_pull_request project return false if project.gpid.nil? @@ -2169,7 +2174,7 @@ module ApplicationHelper candown= User.current.member_of_course?(course) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2 elsif attachment.container.is_a?(OrgSubfield) org = attachment.container.organization - candown = User.current.member_of_org?(org) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2 + candown = User.current.member_of_org?(org) || ((attachment.is_public == 1 || attachment.get_status_by_attach(User.current.id) == 2) && org.allow_guest_download == true) elsif attachment.container.is_a?(OrgDocumentComment) org = attachment.container.organization candown = org.allow_guest_download || User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1) @@ -3453,3 +3458,10 @@ def create_works_list homework ActiveRecord::Base.connection.execute sql end end + +# 获取项目动态更新时间 +def get_forge_act_message(act, type) + forge_act = ForgeActivity.where(:forge_act_id => act.id, :forge_act_type => type).first + format_time(forge_act.nil? ? act.created_on : forge_act.try(:updated_at)) +end + diff --git a/app/models/member.rb b/app/models/member.rb index cb15e067b..bb336e936 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -52,6 +52,9 @@ class Member < ActiveRecord::Base ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id) new_role_ids = ids - role_ids + if (new_role_ids.include?(7) || new_role_ids.include?(9)) && role_ids.include?(10) + member_roles.where("role_id = 10").first.update_column('is_current', 0) + end # Add new roles if new_role_ids.include?(7) && new_role_ids.include?(10) member_roles << MemberRole.new(:role_id => 7) diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb index 56dfaceff..fc7f25d1f 100644 --- a/app/services/projects_service.rb +++ b/app/services/projects_service.rb @@ -331,4 +331,28 @@ class ProjectsService {:status => status,:message => message} end + def send_wechat_project_issue_notice user,project,issue_id,issue_title,priority_id + count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count + if count == 0 + title = "您有新的issue需要解决。" + remark = "点击详情查看issue。" + + case priority_id + when "1" + priority = "低" + when "2" + priority = "正常" + when "3" + priority = "高" + when "4" + priority = "紧急" + when "5" + priority = "立刻" + end + + ws = WechatService.new + ws.project_issue_notice user.id, "issues", issue_id,title, issue_title,priority, remark + end + end + end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 3b6cfe930..423676983 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -115,8 +115,8 @@ class WechatService # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s - # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+"/user_id="+uid.to_s+Wechat.config.auto_openid_url_3 end data = { touser:openid, @@ -149,8 +149,8 @@ class WechatService # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s - # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+"/user_id="+uid.to_s+Wechat.config.auto_openid_url_3 end data = { @@ -188,8 +188,8 @@ class WechatService # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s - # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+"/user_id="+uid.to_s+Wechat.config.auto_openid_url_3 end data = { @@ -417,8 +417,19 @@ class WechatService end Rails.logger.info "send over. #{req}" end + end - + def project_issue_notice(user_id, type, id, first, key1, key2,remark="",uid=0) + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = two_keys_template uw.openid,Wechat.config.project_issue_notice, type, id, first, key1, key2,remark,0 + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[project_issue_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end end end \ No newline at end of file diff --git a/app/views/at/show.json.erb b/app/views/at/show.json.erb index 767c23835..3e49496f9 100644 --- a/app/views/at/show.json.erb +++ b/app/views/at/show.json.erb @@ -1,11 +1,11 @@ [ - <% @users && @users.each_with_index do |person,index| %> - <% if index == 0 %> - {"id":<%=index%>, "userid": "<%=person.id%>", "name": "所有人", "login": "", "searchKey": ""} - <%= index != @users.size-1 ? ',' : '' %> - <% else %> - {"id":<%=index%>, "userid": "<%=person.id%>", "name": "<%=person.show_name%>", "login": "<%=person.login%>", "searchKey": "<%=person.get_at_show_name%>"} - <%= index != @users.size-1 ? ',' : '' %> - <% end %> - <% end %> + <% @users && @users.each_with_index do |person,index| %> + <% if index == 0 %> + {"id":<%=index%>, "userid": "<%=person.id%>", "name": "所有人", "login": "<%=person.name%>", "searchKey": "<%=person.name%>"} + <%= index != @users.size-1 ? ',' : '' %> + <% else %> + {"id":<%=index%>, "userid": "<%=person.id%>", "name": "<%=person.show_name%>", "login": "<%=person.login%>", "searchKey": "<%=person.get_at_show_name%>"} + <%= index != @users.size-1 ? ',' : '' %> + <% end %> + <% end %> ] diff --git a/app/views/attachments/_activity_attach.html.erb b/app/views/attachments/_activity_attach.html.erb index 3cc429185..b37c80dad 100644 --- a/app/views/attachments/_activity_attach.html.erb +++ b/app/views/attachments/_activity_attach.html.erb @@ -3,7 +3,7 @@