Skip to content
This repository has been archived by the owner on Aug 12, 2018. It is now read-only.

Commit

Permalink
approval working
Browse files Browse the repository at this point in the history
  • Loading branch information
slmyers committed Mar 18, 2016
1 parent 6ced432 commit d52761a
Show file tree
Hide file tree
Showing 23 changed files with 346 additions and 41 deletions.
28 changes: 26 additions & 2 deletions backend/app/controllers/api/verification_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Api::VerificationController < ApplicationController
before_action :authenticate_request!, :is_admin?
respond_to :json

def index
Expand All @@ -21,12 +22,35 @@ def create
render json: {warning: 'not implemented'}, status: 200
end

# this is the endpoint for all types of information verification (approval)
# TODO:should check for multiple parameters
def update
render json: {warning: 'not implemented'}, status: 200
if params.has_key?(:user)
@res = Verifier.verify_user(params[:user])
render :json => @res.to_json
return
elsif params.has_key?(:admin)
@res = Verifier.verify_admin(params[:admin])
render :json => @res.to_json
return
elsif params.has_key?(:mentorship)
@res = Verifier.verify_mentorship(params[:mentorship])
render :json => @res.to_json
return
elsif params.has_key?(:supervision)
@res = Verifier.verify_supervision(params[:supervision])
render :json => @res.to_json
return
elsif params.has_key?(:person)
@res = Verifier.verify_person(params[:person])
render :json => @res.to_json
return
else
render json: { errors: ['missing parameter'] }, status: :bad_request
end
end

def destroy
render json: {warning: 'not implemented'}, status: 200
end
end

4 changes: 0 additions & 4 deletions backend/app/lib/auto_complete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ def self.find_names(name)
@name = "%#{name}%".downcase
@response = Person.where("name LIKE ?", @name).includes(:institution)
@institutions = Set.new
#@response.each do |p|
# unless p.institution.blank? then @institutions.add(p.institution) end
#end

return @response
end

Expand Down
49 changes: 49 additions & 0 deletions backend/app/lib/deleter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Deleter

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

def self.delete_admin(admin_id)
@admin = Admin.includes(:user)
.where(:id => admin_id).first
if @admin.user.destroy
return {"success" => true}
end
return {"error" => 'unable to delete'}
end

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

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

def self.delete_person(person_id)
@person = Person.find_by_id(person_id)

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

end
3 changes: 1 addition & 2 deletions backend/app/lib/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ def self.user_notifications
def self.admin_notifications
@unapproved_admins = Admin.where({:approved => false})
.includes(:user)

@res_array = Array.new

@unapproved_admins.each do |a|
unless a.user.blank?
if a.approved == false
@admin = {
'id' => a.id,
'user' => a.user
Expand Down
31 changes: 24 additions & 7 deletions backend/app/lib/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def self.relations_by_name(name)
# returns a hash that contains the relations to a person
# and the person/institution records
def self.relations_by_id(person_id)
if !person_id.is_a? Integer
return {}
end

@persons = Set.new
@institutions = Set.new

Expand Down Expand Up @@ -68,10 +64,31 @@ def self.relations_by_id(person_id)
}
end

def self.person_info(id)
unless Person.exists?(id) then return nil end

@person = Person.includes(:institution)
.includes( {mentorships: [:institution, {mentor: [:institution]}] })
.includes( {supervisions: [ {degree: [:institution] }, {supervisor: [:institution]}] })
.where(:id => id).first

@mentored = Mentorship.where(:mentor_id => id)
.includes(:institution)
.includes(person: :institution)

@supervised = Supervision.where(:supervisor_id => id)
.includes(degree: :institution)
.includes(person: :institution)

return {
'person' => @person,
'mentored' => @mentored,
'supervised' => @supervised
}
end

def self.person(id)
unless Person.exists?(id)
return nil
end
unless Person.exists?(id) then return nil end

@person = Person.includes(:institution)
.includes( {mentorships: [:institution, {mentor: [:institution]}] })
Expand Down
135 changes: 135 additions & 0 deletions backend/app/lib/verifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
class Verifier

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

def self.verify_admin(admin_id)
@admin = Admin.find_by_id(admin_id)
@admin.approved = true
if @admin.save
return {'admin' => @admin}
else
return nil
end
end

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

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

def self.verify_person(person_id)
@person = Search.person_info(person_id)

if @person["person"].approved == false
@person["person"].approved = true
@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
end
1 change: 1 addition & 0 deletions backend/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
resources :auto_complete, except: [:new, :edit, :create, :show, :update, :destroy]
resources :admins, except: [:new, :edit]
namespace :api do
resources :verification
resources :notification, except: [:new, :edit, :create, :show, :update, :destroy], :defaults => {:format => :json}
resources :supervisions
resources :degrees
Expand Down
2 changes: 1 addition & 1 deletion backend/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# delete this next data when in production
# this is to test notifications while in development enviroment
Person.create!([
{name: 'Steven Myers', position: 'professor', institution_id: 1, approved: false},
{name: 'steven myers', position: 'professor', institution_id: 1, approved: false},
{name: 'steve supervised', position: 'prof', institution_id: 1, approved: true},
{name: "steve's mentor", position: 'professor', institution_id: 1, approved: true},
{name: "steve's mentored", position: 'professor', institution_id: 1, approved: true},
Expand Down
1 change: 0 additions & 1 deletion backend/lib/tasks/test_data.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# http://www.kbedell.com/2011/03/15/seed-data-versus-testing-data-and-custom-rake-tasks-for-ruby-on-rails/

# rake db:drop db:create db:migrate db:seed app:load_demo_data RAILS_ENV=test
namespace :app do
desc <<-DESC
Expand Down
26 changes: 24 additions & 2 deletions frontend/web/app/controllers/adminPanelController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('chemGeno')
.controller('adminPanelController', ['$scope', 'adminPanelService',
function($scope, adminPanelService) {
.controller('adminPanelController', ['$scope', 'adminPanelService', 'verificationService',
function($scope, adminPanelService, verificationService) {
$scope.loadData = function() {
var promise = adminPanelService.loadNotifications();
promise.then(function(resp){
Expand All @@ -12,5 +12,27 @@ function($scope, adminPanelService) {
};
$scope.loadData();

$scope.approveUser = function(index) {
var paramObj = {user: $scope.data.user_notifications[index].id};
var promise = verificationService.verifyInfo(paramObj);
promise.then(function(resp) {
console.log(resp);
$scope.data.user_notifications.splice(index, 1);
}, function (error) {
alert(error);
});
};

$scope.approveAdmin = function(index) {
var paramObj = {admin: $scope.data.admin_notifications[index].id};
var promise = verificationService.verifyInfo(paramObj);
promise.then(function(resp) {
console.log(resp);
$scope.data.admin_notifications.splice(index, 1);
}, function (error) {
alert(error);
});
}


}]);
16 changes: 14 additions & 2 deletions frontend/web/app/controllers/mentorshipNotificationController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
angular.module('chemGeno')
.controller('mentorshipNotificationController', ['$scope', '$stateParams', 'viewService', '$q',
function($scope, $stateParams, viewService, $q) {
'verificationService', '$state',
function($scope, $stateParams, viewService, $q, verificationService, $state) {
$scope.loadData = function() {
var promises = {
mentorPromise: viewService.getPerson($stateParams.mentorId),
Expand All @@ -12,7 +13,18 @@ function($scope, $stateParams, viewService, $q) {
console.log($scope.mentor);
console.log($scope.mentee);
});
}
};

$scope.approveMentorship = function() {
var paramObj = {mentorship: $stateParams.mentorshipId};
var promise = verificationService.verifyInfo(paramObj);
promise.then(function(resp) {
console.log(resp);
$state.go('main.admin');
}, function(error){
alert(error);
});
};
$scope.loadData();
// ui booleans for mentor info
$scope.mentor_mentorVisibility = false;
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/app/controllers/personAutoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function($scope, autoService, searchService, $state) {
* @instance
*/
$scope.selectedItemChange = function selectedItemChange(item) {
searchService.executeSearch(item.name);
searchService.executeSearch(item.id);
};

$scope.searchOnEnter = function searchOnEnter() {
Expand Down
Loading

0 comments on commit d52761a

Please sign in to comment.