From 8c6d0e3318c8cab20b1d63aab6942b98b62f4a2b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 15 Aug 2019 09:02:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AE=A1=E7=90=86url?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/partner.rb | 3 +++ app/models/user.rb | 3 +++ app/views/users/get_navigation_info.json.jbuilder | 3 +++ spec/models/partner_spec.rb | 5 +++++ 4 files changed, 14 insertions(+) create mode 100644 app/models/partner.rb create mode 100644 spec/models/partner_spec.rb diff --git a/app/models/partner.rb b/app/models/partner.rb new file mode 100644 index 000000000..f2f8cca2a --- /dev/null +++ b/app/models/partner.rb @@ -0,0 +1,3 @@ +class Partner < ApplicationRecord + has_many :users +end diff --git a/app/models/user.rb b/app/models/user.rb index 07b1a564f..2cd515261 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -138,6 +138,9 @@ class User < ApplicationRecord # 视频 has_many :videos, dependent: :destroy + # 客户管理 + belongs_to :partner + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } diff --git a/app/views/users/get_navigation_info.json.jbuilder b/app/views/users/get_navigation_info.json.jbuilder index 377913ccc..c7ff37e21 100644 --- a/app/views/users/get_navigation_info.json.jbuilder +++ b/app/views/users/get_navigation_info.json.jbuilder @@ -16,6 +16,9 @@ json.top do json.moop_cases_url "#{@old_domain}/moop_cases" json.crowdsourcing_url "/crowdsourcing" + # 客户管理 + json.customer_management_url "#{@old_domain}/cooperates/#{current_user.partner.try(:id)}/partner_list" if current_user.partner + json.career_url do json.array! @career.to_a do |c| if c[1].present? diff --git a/spec/models/partner_spec.rb b/spec/models/partner_spec.rb new file mode 100644 index 000000000..06cff9d9f --- /dev/null +++ b/spec/models/partner_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Partner, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 9922b5342588202788d788cba33db61569d6960f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 15 Aug 2019 09:42:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E4=BD=9C=E5=93=81=E5=A2=9E=E5=8A=A0=E7=BB=84=E9=95=BF?= =?UTF-8?q?=E7=9A=84=E7=9B=B8=E5=85=B3=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- .../homework_commons_controller.rb | 8 +++++ app/controllers/student_works_controller.rb | 35 +++++++++++-------- .../homework_commons/works_list.json.jbuilder | 2 ++ app/views/student_works/edit.json.jbuilder | 3 ++ app/views/student_works/show.json.jbuilder | 9 +++-- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d17059231..e7b4bdac6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -239,7 +239,7 @@ class ApplicationController < ActionController::Base uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) if !User.current.logged? && Rails.env.development? - User.current = User.find 8686 + User.current = User.find 1 end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ff1ee4e96..5d1733983 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -171,6 +171,14 @@ class HomeworkCommonsController < ApplicationController @student_works = @student_works.where(user_id: group_user_ids) end + if @homework.homework_type == "group" && !params[:member_work].blank? + if params[:member_work].to_i == 1 + @student_works = @student_works.where("user_id = commit_user_id") + elsif params[:member_work].to_i == 0 + @student_works = @student_works.where("user_id != commit_user_id") + end + end + # 输入姓名和学号搜索 # TODO user_extension 如果修改 请调整 unless params[:search].blank? diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 93f0fc586..92e60a71c 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -61,16 +61,21 @@ class StudentWorksController < ApplicationController end def delete_work - begin - work = @homework.student_works.find_by!(user_id: params[:user_id]) - work.update_attributes(description: nil, project_id: 0, - late_penalty: 0, work_status: 0, - commit_time: nil, update_time: nil, group_id: 0, - commit_user_id: nil, final_score: nil, work_score: nil, teacher_score: nil, teaching_asistant_score: nil) - normal_status("删除成功") - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) + ActiveRecord::Base.transaction do + begin + work = @homework.student_works.find_by!(user_id: params[:user_id]) + tip_exception("只有组长才能删除组员") if work.commit_user_id != current_user.id + work.update_attributes(description: nil, project_id: 0, + late_penalty: 0, work_status: 0, + commit_time: nil, update_time: nil, group_id: 0, + commit_user_id: nil, final_score: nil, work_score: nil, teacher_score: nil, teaching_asistant_score: nil) + work.attachments.destroy_all + work.tidings.destroy_all + normal_status("删除成功") + rescue Exception => e + uid_logger(e.message) + tip_exception(e.message) + end end end @@ -137,8 +142,9 @@ class StudentWorksController < ApplicationController @current_user = current_user if @homework.homework_type == "group" # todo user_extension + @commit_user_id = @work.commit_user_id @work_members = @course.students.where(user_id: @homework.student_works.where(group_id: @work.group_id).pluck(:user_id)). - order("course_members.id=#{@work.user_id} desc").includes(:course_group, user: :user_extension) + order("course_members.user_id=#{@work.commit_user_id} desc").includes(:course_group, user: :user_extension) end end @@ -150,7 +156,7 @@ class StudentWorksController < ApplicationController begin @work.description = params[:description] @work.update_time = Time.now - @work.commit_user_id = current_user.id + # @work.commit_user_id = current_user.id if @work.save! Attachment.associate_container(params[:attachment_ids], @work.id, @work.class) @@ -165,7 +171,8 @@ class StudentWorksController < ApplicationController # 原成员更新描述、更新时间以及附件 @homework.student_works.where(group_id: @work.group_id, user_id: (work_user_ids & params_user_ids)).each do |work| - work.update_attributes(update_time: Time.now, description: @work.description, commit_user_id: current_user.id) + # work.update_attributes(update_time: Time.now, description: @work.description, commit_user_id: current_user.id) + work.update_attributes(update_time: Time.now, description: @work.description) work.attachments.destroy_all @work.attachments.each do |attachment| att = attachment.copy @@ -193,7 +200,7 @@ class StudentWorksController < ApplicationController stu_work.update_attributes(user_id: user_id, description: @work.description, homework_common_id: @homework.id, project_id: @work.project_id, late_penalty: @work.late_penalty, work_status: @work.work_status, commit_time: Time.now, update_time: Time.now, - group_id: @work.group_id, commit_user_id: current_user.id) + group_id: @work.group_id, commit_user_id: @work.commit_user_id) @work.attachments.each do |attachment| att = attachment.copy att.author_id = attachment.author_id diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index bbe71661a..08c269670 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -69,6 +69,7 @@ elsif @user_course_identity == Course::STUDENT json.project_info project_info @work, @current_user, @user_course_identity end json.work_group @work.work_group_name + json.is_leader @work.user_id == @work.commit_user_id end end @@ -140,6 +141,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" if @homework.homework_detail_group.base_on_project json.project_info project_info work, @current_user, @user_course_identity end + json.is_leader work.user_id == work.commit_user_id json.work_group work.work_group_name end diff --git a/app/views/student_works/edit.json.jbuilder b/app/views/student_works/edit.json.jbuilder index ce9d9ff72..88e5354e4 100644 --- a/app/views/student_works/edit.json.jbuilder +++ b/app/views/student_works/edit.json.jbuilder @@ -1,12 +1,14 @@ json.partial! "homework_commons/homework_public_navigation", locals: {homework: @homework, course: @course, user: @current_user} json.work_id @work.id json.description @work.description +json. json.attachments @work.attachments do |atta| json.partial! "attachments/attachment_simple", locals: {attachment: atta, delete: @work.delete_atta(atta)} end if @homework.homework_type == "group" + json.is_leader_work @work.user_id == @commit_user_id json.min_num @homework.homework_detail_group.try(:min_num) json.max_num @homework.homework_detail_group.try(:max_num) @@ -15,5 +17,6 @@ if @homework.homework_type == "group" json.user_name member.user.real_name json.group_name member.course_group_name json.student_id member.user.student_id + json.is_leader member.user_id == @commit_user_id end end \ No newline at end of file diff --git a/app/views/student_works/show.json.jbuilder b/app/views/student_works/show.json.jbuilder index 653ed6450..5756ac9cb 100644 --- a/app/views/student_works/show.json.jbuilder +++ b/app/views/student_works/show.json.jbuilder @@ -3,6 +3,7 @@ json.(@work, :description, :commit_time, :update_time) json.is_evaluation @is_evaluation json.author_name @is_evaluation ? "匿名" : @work.user.real_name +json.is_leader_work @work.user_id == @work.commit_user_id if @homework.homework_type == "group" json.is_author @is_author json.update_user_name @is_evaluation ? "匿名" : @work.commit_user.try(:real_name) @@ -17,8 +18,10 @@ unless @is_evaluation json.project_info project_info @work, @current_user, @user_course_identity end - json.work_members @work_members.each do |member| - json.user_name member.user.real_name - json.user_login member.user.login + json.work_members @work_members.each do |work| + json.user_name work.user.real_name + json.user_login work.user.login + json.work_id work.id + json.is_leader work.user_id == work.commit_user_id end end