From cb118cb9ffbfbb0b21530676a24abb42a7d36a86 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 17:37:15 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b3d944f5..74f74f9a 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3043,6 +3043,7 @@ end user.grade = 0 user.password = "12345678" user.phone = list[5].blank? ? nil : list[5] + user.mail = nil if user.save ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 From dbb19cf335cf24380cf98db549aec6e9acd0733b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 17:41:30 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index dbb77124..9e8dd2bb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -308,7 +308,7 @@ class User < Principal #validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false - validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false + #validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false validates_uniqueness_of :phone, :if => Proc.new { |user| user.phone_changed? && user.phone.present? }, :case_sensitive => false # Login must contain letters, numbers, underscores only #validates_format_of :login, :with => /\A[a-z0-9_\-]*\z/i From 61877443e3fb7d77de4ca31cac50fb4ac34e048e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 17:52:21 +0800 Subject: [PATCH 03/16] 1 --- app/controllers/managements_controller.rb | 3 +-- app/models/user.rb | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 74f74f9a..7d30f136 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3043,8 +3043,7 @@ end user.grade = 0 user.password = "12345678" user.phone = list[5].blank? ? nil : list[5] - user.mail = nil - if user.save + if user.save(validate: false) ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 ue.technical_title = ["教授", "副教授", "讲师", "助教"].include?(list[4]) ? list[4] : "讲师" diff --git a/app/models/user.rb b/app/models/user.rb index 9e8dd2bb..9eca3c1b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -315,8 +315,8 @@ class User < Principal validates_length_of :login, :maximum => LOGIN_LENGTH_LIMIT validates_length_of :firstname, :maximum => 30 validates_length_of :lastname, :maximum => 30 - validates_format_of :mail, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true - validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true + #validates_format_of :mail, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true + #validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true validates_confirmation_of :password, :allow_nil => true # validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true validate :validate_password_length From 1b36c29a904a300bdc2af1e576f80d84955394da Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 17:59:37 +0800 Subject: [PATCH 04/16] 1 --- app/controllers/managements_controller.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 7d30f136..15647eb2 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3032,17 +3032,10 @@ end # 用户不存在则创建账号 if !user.present? && school.present? department = school.departments.where(:name => list[2]).first - user = User.new - user.admin = false - user.activate - user.login = prefix + list[0].to_s.strip - user.lastname = list[1].to_s.strip - user.nickname = list[1].to_s.strip - user.professional_certification = 1 - user.certification = 1 - user.grade = 0 - user.password = "12345678" - user.phone = list[5].blank? ? nil : list[5] + user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, + nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, + password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} + user = User.create(user_params) if user.save(validate: false) ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 From 6bc5c90f1474bb2ad47b9724a6b5b56137f6d780 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 18:02:50 +0800 Subject: [PATCH 05/16] 1 --- app/controllers/managements_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 15647eb2..3f16995b 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3036,7 +3036,7 @@ end nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} user = User.create(user_params) - if user.save(validate: false) + if user ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 ue.technical_title = ["教授", "副教授", "讲师", "助教"].include?(list[4]) ? list[4] : "讲师" From 5b7e86a8d36b74cfa4a692c190e82b3f9f8cf93e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 30 Aug 2019 18:06:08 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 3f16995b..9fecfc28 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3036,6 +3036,7 @@ end nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} user = User.create(user_params) + user = User.find(prefix + list[0].to_s.strip) if user ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 From 9ecd755745bd51eb2bcef3ac5b0b1ac01b3061da Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 18:07:21 +0800 Subject: [PATCH 07/16] 1 --- app/controllers/managements_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 9fecfc28..7fc0a632 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3035,8 +3035,8 @@ end user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} - user = User.create(user_params) - user = User.find(prefix + list[0].to_s.strip) + user = User.create!(user_params) + # user = User.find(prefix + list[0].to_s.strip) if user ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 From 4d59d3c3890cc505c2eaa3a693910950c47cf73a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 30 Aug 2019 18:12:05 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 9fecfc28..1ba1564b 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3035,7 +3035,7 @@ end user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} - user = User.create(user_params) + user = User.create!(user_params) user = User.find(prefix + list[0].to_s.strip) if user ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) From b986f0572f377527c1fcc6f694fcde4e23228f03 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 18:12:12 +0800 Subject: [PATCH 09/16] 1 --- app/controllers/managements_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 7fc0a632..26ca4076 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3035,6 +3035,7 @@ end user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} + logger.info("########{user_params}") user = User.create!(user_params) # user = User.find(prefix + list[0].to_s.strip) if user From 5de5df74894c010d78250935104358e74d5e05f2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 30 Aug 2019 18:14:23 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 7b797fe0..9fecfc28 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3035,7 +3035,8 @@ end user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} - user = User.create!(user_params) + user = User.create(user_params) + user = User.find(prefix + list[0].to_s.strip) if user ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 From 081298a5561028dfe2c84f51cebf99aab0730b82 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 18:27:29 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 9eca3c1b..10b6a14d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -300,7 +300,7 @@ class User < Principal attr_accessor :password, :password_confirmation attr_accessor :last_before_login_on # Prevents unauthorized assignments - attr_protected :login, :admin, :password, :password_confirmation, :hashed_password + # attr_protected :login, :admin, :password, :password_confirmation, :hashed_password LOGIN_LENGTH_LIMIT = 30 MAIL_LENGTH_LIMIT = 60 From 3c5fdcde08415607518dfb172fbd6ea11b6e4e0c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 18:37:16 +0800 Subject: [PATCH 12/16] 1 --- app/models/user.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 10b6a14d..58f293d6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -673,9 +673,9 @@ class User < Principal base_reload(*args) end - def mail=(arg) - write_attribute(:mail, arg.to_s.strip) - end + # def mail=(arg) + # write_attribute(:mail, arg.to_s.strip) + # end def identity_url=(url) if url.blank? From 4db4970c1ffda64807c60e2de38e68ec1c27c5f8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 18:42:48 +0800 Subject: [PATCH 13/16] 1 --- app/controllers/managements_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 9fecfc28..b0307ae3 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3034,7 +3034,7 @@ end department = school.departments.where(:name => list[2]).first user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, - password: "12345678", phone: list[5].blank? ? nil : list[5], mail: nil} + password: "12345678", phone: list[5].blank? ? nil : list[5], mail: "#{list[0].to_s.strip}@qq.com", profile_completed: 1} user = User.create(user_params) user = User.find(prefix + list[0].to_s.strip) if user From 974dad2a5d34f5407a88a93e903d69c7b6e7c7e7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 30 Aug 2019 18:44:30 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b0307ae3..8f15d572 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3034,7 +3034,7 @@ end department = school.departments.where(:name => list[2]).first user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, - password: "12345678", phone: list[5].blank? ? nil : list[5], mail: "#{list[0].to_s.strip}@qq.com", profile_completed: 1} + password: "12345678", phone: list[5].blank? ? nil : list[5], mail: "#{prefix+list[0].to_s.strip}@qq.com", profile_completed: 1} user = User.create(user_params) user = User.find(prefix + list[0].to_s.strip) if user From cce0dba89aff8f0d06cac6d07ade9f1a2d2b8f21 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 30 Aug 2019 18:53:18 +0800 Subject: [PATCH 15/16] tiaoz --- app/models/course_group.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/course_group.rb b/app/models/course_group.rb index c5b66d87..d158e68f 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -1,6 +1,6 @@ class CourseGroup < ActiveRecord::Base # attr_accessible :title, :body - belongs_to :course + belongs_to :course, counter_cache: true has_many :course_members has_many :members has_many :memberships, :class_name => 'Member' From cfebe9746f04ca2baccff559979abcebca3722dd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 30 Aug 2019 19:01:04 +0800 Subject: [PATCH 16/16] tiaoz --- app/controllers/managements_controller.rb | 6 +++--- app/models/course_group.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 8f15d572..8f851e53 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -2967,7 +2967,7 @@ end member = course.course_members.where(:user_id => user.id, :role => member_role).first # 如果已是课堂成员且是学生身份and不在指定的分班则移动到该分班 if member.present? && member.role == 4 && member.course_group_id != course_group.try(:id).to_i - member.update_column("course_group_id", course_group.try(:id).to_i) + member.update_attributes(course_group_id: course_group.try(:id).to_i) member_count += 1 elsif !member.present? member = CourseMember.new(:role => member_role, :user_id => user.id) @@ -2988,9 +2988,9 @@ end @status = 1 @message = "已导入/更新#{member_count}个成员" end - rescue + rescue Exception => e @status = 0 - @message = "文件内容无法读取" + @message = e.message end else @status = 0 diff --git a/app/models/course_group.rb b/app/models/course_group.rb index d158e68f..2986e6ac 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -1,6 +1,6 @@ class CourseGroup < ActiveRecord::Base # attr_accessible :title, :body - belongs_to :course, counter_cache: true + belongs_to :course, :counter_cache => true has_many :course_members has_many :members has_many :memberships, :class_name => 'Member'