Class: Deleter

Inherits:
Object
  • Object
show all
Defined in:
app/lib/deleter.rb

Overview

This class is used for rejecting user information (unapproved) entries that the administrator has decided against accepting. The method names, arguements and returns are self explanatory. TODO: investigate whether or not information is left “dangling” and destroy unrefrenced and unapproved table rows, ie, an unapproved mentorship occured at an unapproved institution. After the unapproved mentorship is deleted, the unapproved institution should also be removed.

Author:

Class Method Summary (collapse)

Class Method Details

+ (Object) delete_admin(admin_id)



19
20
21
22
23
24
25
# File 'app/lib/deleter.rb', line 19

def self.delete_admin(admin_id)
  @admin = Admin.find_by_id(admin_id)
  if @admin.destroy
    return {"success" => true}
  end
  return {"error" => 'unable to delete'}
end

+ (Object) delete_mentorship(mentorship_id)



27
28
29
30
31
32
33
34
35
# File 'app/lib/deleter.rb', line 27

def self.delete_mentorship(mentorship_id)
  @mentorship = Mentorship.includes(:institution)
                .where(:id => mentorship_id).first

  if @mentorship.destroy
    return {"success" => true}
  end
  return {"error" => 'unable to delete'}
end

+ (Object) delete_person(person_id)

TODO: I'm sure this is leaving “ghost rows” as described at the begining of this class



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/lib/deleter.rb', line 49

def self.delete_person(person_id)
  @person = Search.person_info(person_id, false)

  @person["person"].mentorships.each do |m|
    m.destroy
  end

  @person["person"].supervisions.each do |s|
    s.destroy
  end

  @person["mentored"].each do |m|
    m.destroy
  end

  @person["supervised"].each do |s|
    s.destroy
  end

  if @person["person"].destroy
    return {"success" => true}
  end
  return {"error" => 'unable to delete'}
end

+ (Object) delete_supervision(supervision_id)



37
38
39
40
41
42
43
44
45
# File 'app/lib/deleter.rb', line 37

def self.delete_supervision(supervision_id)
  @supervision = Supervision.includes(degree: :institution)
                  .where(:id => supervision_id).first

  if @supervision.destroy
    return {"success" => true}
  end
  return {"error" => 'unable to delete'}
end

+ (Object) delete_user(user_id)



11
12
13
14
15
16
17
# File 'app/lib/deleter.rb', line 11

def self.delete_user(user_id)
  @user = User.find_by_id(user_id)
  if @user.destroy
    return {"success" => true}
  end
  return {"error" => 'unable to delete'}
end