Class: Verifier
- Inherits:
-
Object
- Object
- Verifier
- Defined in:
- app/lib/verifier.rb
Overview
this class is used to verify unapproved information, basically all the methods just turn approved = true for respective entries
Class Method Summary (collapse)
-
+ (Object) verify_admin(admin_id)
verifies an admin by their id.
- + (Object) verify_mentorship(mentorship_id)
-
+ (Object) verify_person(person_id)
goes through every single thing related to a person and approves it if a user approves a person, they also approve everything related to that person.
- + (Object) verify_supervision(supervision_id)
-
+ (Object) verify_user(user_id)
verifies a user by their id.
Class Method Details
+ (Object) verify_admin(admin_id)
verifies an admin by their id
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/lib/verifier.rb', line 19 def self.verify_admin(admin_id) @admin = Admin.find_by_id(admin_id) @admin.approved = true @user = User.find_by_id(@admin.user_id) @user.approved = true if @admin.save && @user.save return {'admin' => @admin} else return nil end end |
+ (Object) verify_mentorship(mentorship_id)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/lib/verifier.rb', line 31 def self.verify_mentorship(mentorship_id) @mentorship = Mentorship.includes(:institution) .where(:id => mentorship_id).first if @mentorship.institution.approved == false @mentorship.institution.approved = true end @mentorship.approved = true if @mentorship.save && @mentorship.institution.save return { 'mentorship' => @mentorship, 'institution' => @mentorship.institution } else return nil end end |
+ (Object) verify_person(person_id)
goes through every single thing related to a person and approves it if a user approves a person, they also approve everything related to that person. So, if you see something funny on an unapproved person's details, then you shouldn't improve. TODO: this method is very slow. Investigate optimizations.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/lib/verifier.rb', line 83 def self.verify_person(person_id) # false because we're using the search function to find unapproved person # information. False is handed to the :approved key in the where clause # for Search.person_info(id, approved) @person = Search.person_info(person_id) if @person["person"].approved == false @person["person"].approved = true #search/autocomplete is performed assuming all lower cases in name @person["person"].name = @person["person"].name.downcase @person["person"].save end if @person["person"].institution.approved == false @person["person"].institution.approved = true @person["person"].institution.save end @person["person"].mentorships.each do |m| m.approved = true m.institution.approved = true m.mentor.approved = true m.mentor.institution.approved = true m.mentor.institution.save m.mentor.save m.institution.save m.save end @person["person"].supervisions.each do |s| s.approved = true s.degree.approved = true s.degree.institution.approved = true s.supervisor.institution.approved = true s.supervisor.approved = true s.save s.degree.save s.degree.institution.save s.supervisor.institution.save s.supervisor.save end @person["mentored"].each do |m| m.approved = true m.institution.approved = true m.person.approved = true m.person.institution.approved = true m.person.institution.save m.person.save m.institution.save m.save end @person["supervised"].each do |s| s.approved = true s.degree.approved = true s.degree.institution.approved = true s.person.approved = true s.person.institution.approved = true s.save s.degree.save s.degree.institution.save s.person.save s.person.institution.save end return { 'warning' => "person approved, but with no error checking" } end |
+ (Object) verify_supervision(supervision_id)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/lib/verifier.rb', line 51 def self.verify_supervision(supervision_id) @supervision = Supervision.includes(degree: :institution) .where(:id => supervision_id).first if @supervision.degree.approved == false @supervision.degree.approved = true end if @supervision.degree.institution.approved == false @supervision.degree.institution.approved = true end @supervision.approved = true if @supervision.save && @supervision.degree.save && @supervision.degree.institution.save return { 'supervision' => @supervision, 'degree' => { 'data' => @supervision.degree, 'institution' => @supervision.degree.institution } } else return nil end end |
+ (Object) verify_user(user_id)
verifies a user by their id
7 8 9 10 11 12 13 14 15 16 |
# File 'app/lib/verifier.rb', line 7 def self.verify_user(user_id) @user = User.find_by_id(user_id) @user.approved = true if @user.save return {'user' => @user} else return nil end end |