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

Commit

Permalink
I just want to push wtf is going on
Browse files Browse the repository at this point in the history
  • Loading branch information
ctevans committed Mar 18, 2016
1 parent 0fab891 commit d14994c
Show file tree
Hide file tree
Showing 68 changed files with 2,163 additions and 864 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@

Relevant documentation can be found in the [wiki](https://github.com/401ChemistryGenealogy/ChemistryGenealogy/wiki). Don't forget to check the 'pages' section on the right.

# running instructions for backend
### auto-generated docs

_assuming dependencies have been installed etc_
These can be found [online](http://401chemistrygenealogy.github.io/) or in the [docs folder](https://github.com/401ChemistryGenealogy/ChemistryGenealogy/tree/master/backend/doc)

1) in the `backend` folder run `chmod +x reloadDB.sh`, and then `./reloadDB.sh` this will run migrations, load schema and buil test + development db

2) to run tests: make sure `RAILS_ENV=test` and run `rake spec`, otherwise the testing framework can't access the database

3) to live demo: make sure `RAILS_ENV=development` and run `rails s`
51 changes: 28 additions & 23 deletions backend/.yardoc/checksums
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
app/lib/search.rb 009de4b8a28901f2c7436495a4abbcb1db1dfc69
app/lib/search.rb 641aeb729fc6e5e1f4e9c317afc48f37b52f4a5a
app/models/user.rb d3c9dedf945d625674077a30bf2f2cbb6409fdb1
app/lib/deleter.rb 35ea32167a4221c52c9149b7e3babebcef121db2
app/lib/find_id.rb aa8bfd0ed4df0e35548d78d0bd7ffd8ed49f61a4
app/models/admin.rb 619c9860fd009f905a3c46c3d0d97d9fc7aa1e62
app/lib/notifier.rb 4dbd59e8d0f0ba3a4688f5adaa1224834e02269d
app/models/person.rb 54c8e4d8c29aea76a736cd0e84e59678266faf67
app/models/degree.rb 27a138a7125cd65d37ed72cd5d78fc171867a5ad
app/lib/auth_token.rb c39d411dd19f9c380fd31fe38a8f8ba83b61285f
app/lib/find_detail.rb fd3fa869d315b712aa3e94ee4c5adf0a5c6b0106
app/models/mentorship.rb ae689710839b206c144f6671e1bd9968361ada65
app/lib/auto_complete.rb bbdb027e4c2292a986578f9f01e35db14984e730
app/models/supervision.rb b541dff3c87c20dc29fce31ba42516f420667cac
app/models/institution.rb 487af31b2b4390188d7bf0218fb629159b064253
app/lib/notifier.rb a9f713a84d8fa05b20e88ae7a514e041dfb08807
app/lib/verifier.rb 7f1f2e80ef565f0cb6998c8eed710a288343da1b
app/models/person.rb 214df9d48749eac7c4e6335da7008be3579ce20c
app/models/degree.rb cd5a2c48725f9e8ea90e2b480a81e0c0de42f968
app/lib/auth_token.rb 4fe2ba5cc707a564a5da3709e6f81bb30bf3b82f
app/lib/information.rb 44817aeba505f7477087cb8a7f1f769b2f40b56d
app/lib/find_detail.rb 1edc0d8e0562c51fe0a3f92cbd5eb40e19d8e815
app/models/mentorship.rb 156f0976315ec3f85b3c9bc8b6b3cf0ee1898903
app/lib/auto_complete.rb af4a0eee76a76a6cb7a6474bba1887e8f929d3cf
app/models/supervision.rb 9a9b51ff812b4bff2091ffb04b20897b1c869c54
app/models/institution.rb fde2fd1345388aef4ea09f11067cca4c3bd94522
app/models/audit_trail.rb 0ce06729b003a9150ee8f5d019beca55abdb6a66
app/controllers/api_controller.rb c410401db882d5af75cb0ef93ed16b9bd661ae4d
app/controllers/api_controller.rb 439079430f75c5ee36083463c9622caf5b76e1c0
app/serializers/user_serializer.rb 3e2275741192602828a96ed0bd399c2c4bc1f9f9
app/controllers/auth_controller.rb 440f4c10764a54012395e8e7ab21252eb5669a0b
app/controllers/user_controller.rb f9e3ad506ab6a42b9d040ee45aa1e23b8127275c
app/controllers/auth_controller.rb f87eda4c62d55a8316476802d6866b17a18bc78d
app/controllers/user_controller.rb 279c1a49fd694ecb8316dd4894720d3b6828f72c
app/serializers/admin_serializer.rb ade50ceaf1d63c7f528fc887300b4aff58bef003
app/controllers/admin_controller.rb 1019fa7c700c93112a9dccb6fdbad538c8117527
app/controllers/admin_controller.rb c766d1575bf70d3e6cfe63f5a96cb6fed1f3649e
app/serializers/search_serializer.rb 6dc86c5cbc82b9c3d7748349c14aee4d0f05b668
app/controllers/errors_controller.rb 1cbe908cb905b37e9b969d96d8df4f5b83fac8d2
app/controllers/search_controller.rb 49816061ce185069a5cc8b4be643498d182c464b
app/controllers/errors_controller.rb 2fde7d97e22d9e9a7655aa76cbefb06177d59aef
app/controllers/search_controller.rb 09f2930f31161dfabccd75bb32e1e23ac033eb5a
app/serializers/api/degree_serializer.rb 5de6f60042b88a3535917d58d6fb878155f40934
app/serializers/api/person_serializer.rb fc6cd532f8b97954b63cd72e7fbe0b44d8700d0b
app/serializers/api/mentor_serializer.rb 4ac428fbe51b0210d5147ca2a8df617210c6504a
app/serializers/api/person_serializer.rb 1769202ae6e349e8edb45d9be3cc2cce8c1e8fdd
app/controllers/api/admins_controller.rb b176a597dad8e26790c4373478e002f3460bd5e0
app/controllers/api/people_controller.rb 5820c0f4ed3cd7afcd75494b2c15a54ce3acabd8
app/serializers/api/postdoc_serializer.rb b1a393f46ec51efa52333339fa2dc228ba87cc98
app/controllers/application_controller.rb 5929e07351b3b97d7750f38bd1ae404784564be9
app/controllers/application_controller.rb 50904503abc5d2481c22a8f0edda9c7ca90e8350
app/controllers/api/degrees_controller.rb ad31dd8b09048fb7b4b9146c19af54adbb1f0a3f
app/controllers/auto_complete_controller.rb 202d7df112dcf6125ebb8fdabac92fbdaeb6b35f
app/serializers/api/supervisor_serializer.rb 62df2aa2907be83fb5f664d5685d9b03243c2887
app/controllers/api/aggregated_controller.rb aaec5023668cc6e967e0118ebf758bd379cd2c7b
app/serializers/api/mentorship_serializer.rb 4ac428fbe51b0210d5147ca2a8df617210c6504a
app/serializers/api/supervisor_serializer.rb 4d5231576e7501f61e04aa2aec76349146e92cca
app/controllers/api/aggregated_controller.rb fa9988656ffef891705847f02dc3aa878908519e
app/serializers/api/supervision_serializer.rb 4d5231576e7501f61e04aa2aec76349146e92cca
app/serializers/api/institution_serializer.rb 574178e98f1a52d5fb771187154d6f1a12c41e86
app/controllers/api/mentorships_controller.rb f6432d45654930656cca8cc498534c5d7321c7c2
app/controllers/api/audit_trail_controller.rb 43de4c695c9992216d41efc1e4798e6a240745a7
app/controllers/api/audit_trail_controller.rb 946558ff78057781001760dec6b9ccbcb22412a2
app/controllers/api/supervisions_controller.rb 9b119c65b20ecfe893cc9002ff69cd7583e4d7c0
app/controllers/api/notification_controller.rb b076b8eaff36609753c36128a2ece398de4db7db
app/controllers/api/institutions_controller.rb 6299bb48caef66a71d9580065d7d8f04439a80b1
app/controllers/api/verification_controller.rb ff649486c7ddbd94060a854ca3aede62321cbefc
app/controllers/api/verification_controller.rb 30756a39440a5c2d39e3b6cd69df6aab979846a4
Binary file modified backend/.yardoc/object_types
Binary file not shown.
Binary file modified backend/.yardoc/objects/root.dat
Binary file not shown.
39 changes: 10 additions & 29 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
Remember to "bundle install" to download the gem files.
### database loading script
There is a script `reloadDB.sh` that will load both the test database and the development database.
It tears everything down though, so if you're using it frequently you'll want to remove a few lines.

February 10, 2016:

* Initialized the backend with rails-api
* Followed most of #17 on https://github.com/mefeghhi/poll-api
* Haven't been able to do #18 yet
* Created a User model and controller
* Created a temporary model and controller for Contact Us (when receiving information for a concern)
* Honestly, haven't been able to do anything too solid for both
### test database location/initialization

`/backend/lib/tasks/test_data.rake` is where test data is loaded from. This is the
data that is tested against in the tests. This data is automatically loaded with `./reloadDB.sh`

## example test for authentication route -- when it works it should return some token provided username/password combo
### test location

http://stackoverflow.com/questions/6885990/rails-params-explained
tests are located in the `/backend/spec` folder. You can run these with `rake spec`.

```
curl -X POST -H 'Content-Length: 0' \
'http://localhost:3000/authenticate/?username=testUser&password=testPassword'
```
response:
### futher documentation

```
{"auth_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE0NTc4MjQ0OTR9.AplIW545pEZCSXb3BtBu2j4svTriNuRPs6_imIkO_aQ","user":{"id":1,"username":"testUser"}}
```

## sources

http://adamalbrecht.com/2015/07/20/authentication-using-json-web-tokens-using-rails-and-react/

http://adamalbrecht.com/2014/12/04/add-json-web-token-authentication-to-your-angular-rails-app/


### work on error repsonses... shouldn't be responding with HTML

https://wyeworks.com/blog/2016/1/12/improvements-to-error-responses-in-rails-5-api-mode
There is further documentation on the [project wiki](https://github.com/401ChemistryGenealogy/ChemistryGenealogy/wiki#documentation).
4 changes: 4 additions & 0 deletions backend/app/controllers/api/notification_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# @author Steven Myers
# this is the notification endpoint. It will call the Notifier to gather and
# bundle all unapproved entries in the database, and deliver them to the
# frontend.
class Api::NotificationController < ApplicationController
before_action :authenticate_request!, :is_admin?

Expand Down
5 changes: 5 additions & 0 deletions backend/app/controllers/api/verification_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# @author Steven Myers
# This controller needs administrator token to access.
# it is repsonsible for calling Notifier or Deleter to appropriately
# deal with the information verification story.
class Api::VerificationController < ApplicationController
before_action :authenticate_request!, :is_admin?
respond_to :json
Expand Down Expand Up @@ -50,6 +54,7 @@ def update
end
end

# this is the endpoint for rejecting new entries into the database
def destroy
if params.has_key?(:user)
@res = Deleter.delete_user(params[:user])
Expand Down
3 changes: 3 additions & 0 deletions backend/app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# @author Steven Myers
# will authenticate every request besides GETs for everything
# inheriting from the ApiController
class ApiController < ApplicationController
before_action :authenticate_request!, except: [:index, :show]
end
2 changes: 2 additions & 0 deletions backend/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class NotAuthenticatedError < StandardError
class AuthenticationTimeoutError < StandardError
end

# @author Steven Myers
# contains errors related to authentication and token parsing methods
class ApplicationController < ActionController::API
self.responder = ApplicationResponder
respond_to :html, :json
Expand Down
4 changes: 4 additions & 0 deletions backend/app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# @author Steven Myers
# This class has authentication methods that will generate a JWT for the
# client to hold
class AuthController < ApplicationController

def authenticate
user = User.find_by_credentials(params[:email], params[:password])
if user
Expand Down
3 changes: 3 additions & 0 deletions backend/app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# @author Steven Myers
# this class handles 404 errors, so we don't get a HTML dump in the
# developer console at the frontend.
class ErrorsController < ApplicationController
def routing
render_404
Expand Down
2 changes: 2 additions & 0 deletions backend/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# @author Steven Myers
# this is the search endpoint calls the Search class to handle reqest
class SearchController < ApplicationController
def index
if params.has_key?(:name) && params.has_key?(:id)
Expand Down
7 changes: 5 additions & 2 deletions backend/app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# @author Steven Myers
# this controller is used when registering a user
class UserController < ApplicationController
respond_to :json

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

# too much logic in here
# this is the registration endpoint
# maybe too much logic here
def create
Rails.logger.info(params)
if params.has_key?(:password) && params.has_key?(:email) && params.has_key?(:first_name) && params.has_key?(:last_name)
unless User.exists?(email: params[:email])
@user = User.new_user(params[:password], params[:email], params[:first_name], params[:last_name])
if @user != nil && @user.save
render json: @user.as_json, status: :created
return
return
end
else
render json: {error: 'user exists'}, status: :bad_request
Expand Down
2 changes: 2 additions & 0 deletions backend/app/lib/auth_token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# @author Steven Myers
# this class generates the JWT using this gem https://github.com/jwt/ruby-jwt/
class AuthToken
# Encode a hash in a json web token
# token stays valid for a month
Expand Down
5 changes: 5 additions & 0 deletions backend/app/lib/auto_complete.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
require 'set'
# @author Steven Myers
# this class runs a simple like query against the database in order to
# generate autocomplete (typeahead) items for the frontend.
# there is questionable scalability of this class, so it's suggested to
# either debounce or throttle client requests.
class AutoComplete
def self.find_names(name)
@name = "%#{name}%".downcase
Expand Down
10 changes: 10 additions & 0 deletions backend/app/lib/deleter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# @author Steven Myers
# 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.
class Deleter

def self.delete_user(user_id)
Expand Down Expand Up @@ -36,6 +44,8 @@ def self.delete_supervision(supervision_id)
return {"error" => 'unable to delete'}
end

# TODO: I'm sure this is leaving "ghost rows" as described at the
# begining of this class
def self.delete_person(person_id)
@person = Search.person_info(person_id)

Expand Down
21 changes: 20 additions & 1 deletion backend/app/lib/search.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require 'set'
# @author Steven Myers
# This class is used to find all relations with respect to a person.
# That is to find the: postdocs mentored by the person, the postdoc mentors for
# the person, the degrees supervised by the person and the supervisors for the
# persons degrees. There is also the case where it finds ALL available information
# about a person and also the people related to the person's information.
class Search

# if called will find the id associated with the name and then call
# self.relations_by_id
def self.relations_by_name(name)
if Person.exists?(name: name)
@person_id = Person.find_by(name: name).id
Expand All @@ -10,7 +18,10 @@ def self.relations_by_name(name)
end

# returns a hash that contains the relations to a person
# and the person/institution records
# and the person/institution records.
# it is used in conjunction with autocomplete on the frontend, and it is likely
# that this class can be optimized
# TODO: investigate optimizations
def self.relations_by_id(person_id)
@persons = Set.new
@institutions = Set.new
Expand Down Expand Up @@ -64,6 +75,10 @@ def self.relations_by_id(person_id)
}
end

# this function was extracted from self.person(id) and is called by
# Notifier and Deleter. It is used to retrieve the relationships w.r.t
# @param id
# @return hash contating the relationships
def self.person_info(id)
unless Person.exists?(id) then return nil end

Expand All @@ -87,6 +102,10 @@ def self.person_info(id)
}
end

# this class is different from relations_by_id, because it not only gathers
# the relations, but also the information required to "fill" out these relations.
# used to detail or "view" a person on the frontend.
# TODO: take out the begining of the function and call self.person_info instead.
def self.person(id)
unless Person.exists?(id) then return nil end

Expand Down
9 changes: 9 additions & 0 deletions backend/app/lib/verifier.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @author Steven Myers
# this class is used to verify unapproved information, basically all the
# methods just turn approved = true for respective entries
class Verifier

# yeah it does what you think
def self.verify_user(user_id)
@user = User.find_by_id(user_id)

Expand Down Expand Up @@ -68,6 +72,11 @@ def self.verify_supervision(supervision_id)
end
end

# 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.
def self.verify_person(person_id)
@person = Search.person_info(person_id)

Expand Down
6 changes: 6 additions & 0 deletions backend/cshellscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
bundle exec rake db:drop
bundle exec rake db:migrate
bundle exec rake db:schema:load
RAILS_ENV=development bundle exec rake db:seed
RAILS_ENV=test bundle exec rake app:load_demo_data
2 changes: 1 addition & 1 deletion backend/doc/AccessDeniedError.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
</div>

<div id="footer">
Generated on Wed Mar 16 03:22:46 2016 by
Generated on Fri Mar 18 09:09:32 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
</div>
Expand Down
2 changes: 1 addition & 1 deletion backend/doc/Admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ <h3 class="signature first" id="as_json-instance_method">
</div>

<div id="footer">
Generated on Wed Mar 16 03:22:46 2016 by
Generated on Fri Mar 18 09:09:32 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
</div>
Expand Down
Loading

0 comments on commit d14994c

Please sign in to comment.