Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dbc148b
updated travis ci badges & iter0 doc
junyu-w Oct 8, 2016
79445f8
updated code climate badge & iter0 doc
junyu-w Oct 8, 2016
089e1eb
added pivotal tracker project url
junyu-w Oct 8, 2016
703b0be
iter 1: cucumber
Shuotong Oct 14, 2016
cc649b2
Merge remote-tracking branch 'upstream/develop' into develop
junyu-w Oct 15, 2016
ac82d6f
added status of both main repo and forked repo to readme
junyu-w Oct 15, 2016
982f2a3
Merge branch 'cucumber' into develop
junyu-w Oct 15, 2016
a3ada8b
added heroku staging url
junyu-w Oct 15, 2016
acad466
added github login functionality
junyu-w Oct 20, 2016
e594d45
removed copied sample code
junyu-w Oct 20, 2016
65dee30
added bootstrap gems
junyu-w Oct 20, 2016
aeb22e1
added annotate gem and better error gem
junyu-w Oct 20, 2016
a59f53d
added role attr to users
junyu-w Oct 20, 2016
210605a
added migration to create root user
junyu-w Oct 20, 2016
7abeb4d
changed omniauth github path
junyu-w Oct 20, 2016
d78f7b1
added updated application.yml.asc file
junyu-w Oct 20, 2016
b94d7fd
added credential for test env
junyu-w Oct 20, 2016
d71c2da
added whitelist authorized user checking during login
junyu-w Oct 20, 2016
5c127d4
fixed root user migration & added success msg for github signing in
junyu-w Oct 20, 2016
fa7c364
updated env file
junyu-w Oct 20, 2016
3d0caf7
passed tests assumed no whitelist functionality
junyu-w Oct 20, 2016
bab3832
removed test from env file
junyu-w Oct 20, 2016
a70594d
fixed bug in user login feature
junyu-w Oct 20, 2016
1a1b511
removed duplicated notice msg
junyu-w Oct 20, 2016
f99a57d
updated env file to include staging environment
junyu-w Oct 21, 2016
d9eba9a
removed whitelist checking
junyu-w Oct 21, 2016
8e3e1bd
added user uid validation
junyu-w Oct 21, 2016
327480a
removed uid validation because of conflict with admin
junyu-w Oct 21, 2016
f9959ab
front-end added
junyu-w Oct 21, 2016
76378af
added user authentication
junyu-w Oct 21, 2016
c47f8dd
updated schema & staging env encryption key
junyu-w Oct 21, 2016
3a2ce5e
fixed old tests except for view metric sample with secrets & removed …
junyu-w Oct 21, 2016
10790f9
removed redundant user session check
junyu-w Oct 21, 2016
687b040
Merge remote-tracking branch 'upstream/develop' into develop
junyu-w Oct 24, 2016
e720fd9
Merge branch 'develop' into feature/login-with-github
junyu-w Oct 24, 2016
800848a
removed username/password related stuff
junyu-w Oct 25, 2016
031c182
removed unused controller files
junyu-w Oct 26, 2016
edcaff0
added root user with github credentials
junyu-w Oct 26, 2016
4c274c5
test passing with intermittent db locking error after adding mocked o…
junyu-w Oct 26, 2016
fbbe572
fixed tests
junyu-w Oct 26, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ gem 'timecop'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'devise'
gem 'omniauth-github', github: 'intridea/omniauth-github'

gem 'bootstrap-sass', '~> 3.3.6'

group :development, :test do
gem 'sqlite3'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'dotenv-rails'
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
end

group :test do
Expand Down
54 changes: 53 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
GIT
remote: git://github.com/intridea/omniauth-github.git
revision: 45f2fc73d6d06f30863adac0e6aa112bcaaadf67
specs:
omniauth-github (1.1.2)
omniauth (~> 1.0)
omniauth-oauth2 (>= 1.1.1, < 2.0)

GIT
remote: https://github.com/AgileVentures/ProjectMetrics/
revision: 8ddb909abe2396cb2b9f454aa35821a5d1a6ff9c
Expand Down Expand Up @@ -80,15 +88,28 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
annotate (2.7.1)
activerecord (>= 3.2, < 6.0)
rake (>= 10.4, < 12.0)
arel (6.0.3)
attr_encrypted (3.0.3)
encryptor (~> 3.0.0)
autoprefixer-rails (6.5.1)
execjs
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.11)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (9.0.5)
capybara (2.8.1)
Expand All @@ -99,6 +120,7 @@ GEM
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coderay (1.1.1)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
coffee-rails (4.1.1)
Expand Down Expand Up @@ -136,6 +158,12 @@ GEM
uber (>= 0.0.15)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.1)
responders
warden (~> 1.2.3)
diff-lcs (1.2.5)
docile (1.1.5)
dotenv (2.1.1)
Expand Down Expand Up @@ -178,6 +206,7 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
jwt (1.5.6)
launchy (2.4.3)
addressable (~> 2.3)
loofah (2.0.3)
Expand All @@ -196,8 +225,21 @@ GEM
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
octokit (4.3.0)
sawyer (~> 0.7.0, >= 0.5.3)
omniauth (1.3.1)
hashie (>= 1.2, < 4)
rack (>= 1.0, < 3)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
orm_adapter (0.5.0)
pg (0.18.4)
phantomjs (2.1.1.0)
pkg-config (1.1.7)
Expand Down Expand Up @@ -246,6 +288,8 @@ GEM
representable (3.0.0)
declarative (~> 0.0.5)
uber (~> 0.0.15)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
rspec-core (3.5.3)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
Expand Down Expand Up @@ -325,6 +369,8 @@ GEM
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.6)
rack (>= 1.0)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
Expand All @@ -344,19 +390,25 @@ PLATFORMS
ruby

DEPENDENCIES
annotate
attr_encrypted
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
cucumber-rails
cucumber-rails-training-wheels
database_cleaner
devise
dotenv-rails
factory_girl_rails
figaro
haml
jbuilder (~> 2.0)
jquery-rails
launchy
omniauth-github!
pg
phantomjs
poltergeist
Expand Down Expand Up @@ -386,4 +438,4 @@ RUBY VERSION
ruby 2.3.1p112

BUNDLED WITH
1.12.5
1.13.3
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Main Repo Status:

<a href="https://codeclimate.com/github/AgileVentures/projectscope_mvp"><img src="https://codeclimate.com/github/AgileVentures/projectscope_mvp/badges/gpa.svg" /></a>
<a href="https://travis-ci.org/AgileVentures/projectscope_mvp"><img src="https://travis-ci.org/AgileVentures/projectscope_mvp.svg?branch=master"></a>

CS169 Group Forked Repo Status:

<a href="https://codeclimate.com/github/DrakeW/projectscope"><img src="https://codeclimate.com/github/DrakeW/projectscope/badges/gpa.svg" /></a>
<a href="https://travis-ci.org/DrakeW/projectscope"><img src="https://travis-ci.org/DrakeW/projectscope.svg?branch=develop"></a>

# MVP dashboard for ProjectScope

A dashboard to show project metrics such as those supported by gems like
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";
3 changes: 1 addition & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class ProjectsController < ApplicationController
before_action :set_project, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!

http_basic_authenticate_with name: "cs169", password: ENV['PROJECTSCOPE_PASSWORD']

# GET /projects
# GET /projects.json
def index
Expand Down
39 changes: 39 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]

# You should also create an action method in this controller like this:
# def twitter
# end

# More info at:
# https://github.com/plataformatec/devise#omniauth

# GET|POST /resource/auth/twitter
# def passthru
# super
# end

# GET|POST /users/auth/twitter/callback
# def failure
# super
# end

# protected

# The path used when OmniAuth fails
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end

def github
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.nil?
flash[:alert] = "You are not authorized."
redirect_to new_user_session_path
else
flash[:notice] = "Signed in successfully."
sign_in_and_redirect @user
end
end
end
13 changes: 13 additions & 0 deletions app/models/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# == Schema Information
#
# Table name: configs
#
# id :integer not null, primary key
# project_id :integer
# metric_name :string
# encrypted_options :text
# created_at :datetime not null
# updated_at :datetime not null
# encrypted_options_iv :string
#

class Config < ActiveRecord::Base
belongs_to :project
scope :for, ->(metric_name) { where(:metric_name => metric_name).first }
Expand Down
15 changes: 15 additions & 0 deletions app/models/metric_sample.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# == Schema Information
#
# Table name: metric_samples
#
# id :integer not null, primary key
# project_id :integer
# metric_name :string
# encrypted_raw_data :text
# created_at :datetime not null
# updated_at :datetime not null
# encrypted_raw_data_iv :string
# score :float
# image :text
#

class MetricSample < ActiveRecord::Base
belongs_to :project
scope :latest_for, ->(metric_name) { where(:metric_name => metric_name).last }
Expand Down
10 changes: 10 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#

class Project < ActiveRecord::Base
has_many :configs
has_many :metric_samples
Expand Down
49 changes: 49 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# last_sign_in_at :datetime
# current_sign_in_ip :string
# last_sign_in_ip :string
# created_at :datetime not null
# updated_at :datetime not null
# provider :string
# uid :string
# role :string default("coach"), not null
#

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :recoverable,
:rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:github]

ADMIN = "admin"
COACH = "coach"

def self.from_omniauth(auth)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is a bit long - I'll still pull in but it would be good to refactor to make it easier to see what the components are doing

email = auth.info.email.nil? ? auth.extra.raw_info.email : auth.info.email
login = auth.extra.raw_info.login
if !login.nil? and !email.nil?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block of code is ripe for pulling out as a separate method - we could also rewrite as unless login.nil or email.nil?

ah, I guess the method is not so huge because it's just block syntax on that first_or_create, but we could extract that as a separate method and self document like so:

unless login.nil or email.nil?
find_or_create_user_from(login, email, auth)
end

just some thoughts ...

User.where(provider: auth.provider, provider_username: login, email: email).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = email
user.provider_username = login
user.password = Devise.friendly_token[0,20]
end
end
end

def is_admin?
self.role == ADMIN
end
end
16 changes: 16 additions & 0 deletions app/views/devise/confirmations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h2>Resend confirmation instructions</h2>

<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>

<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>

<%= render "devise/shared/links" %>
5 changes: 5 additions & 0 deletions app/views/devise/mailer/confirmation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Welcome <%= @email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
3 changes: 3 additions & 0 deletions app/views/devise/mailer/password_change.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>Hello <%= @resource.email %>!</p>

<p>We're contacting you to notify you that your password has been changed.</p>
8 changes: 8 additions & 0 deletions app/views/devise/mailer/reset_password_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
7 changes: 7 additions & 0 deletions app/views/devise/mailer/unlock_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>

<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>

<p>Click the link below to unlock your account:</p>

<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
Loading