-
Notifications
You must be signed in to change notification settings - Fork 14
Feature/whitelist #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ysiad
wants to merge
69
commits into
AgileVentures:develop
Choose a base branch
from
junyu-w:feature/whitelist
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
dbc148b
updated travis ci badges & iter0 doc
junyu-w 79445f8
updated code climate badge & iter0 doc
junyu-w 089e1eb
added pivotal tracker project url
junyu-w 703b0be
iter 1: cucumber
Shuotong cc649b2
Merge remote-tracking branch 'upstream/develop' into develop
junyu-w ac82d6f
added status of both main repo and forked repo to readme
junyu-w 982f2a3
Merge branch 'cucumber' into develop
junyu-w a3ada8b
added heroku staging url
junyu-w acad466
added github login functionality
junyu-w e594d45
removed copied sample code
junyu-w 65dee30
added bootstrap gems
junyu-w aeb22e1
added annotate gem and better error gem
junyu-w a59f53d
added role attr to users
junyu-w 210605a
added migration to create root user
junyu-w 7abeb4d
changed omniauth github path
junyu-w d78f7b1
added updated application.yml.asc file
junyu-w b94d7fd
added credential for test env
junyu-w d71c2da
added whitelist authorized user checking during login
junyu-w 5c127d4
fixed root user migration & added success msg for github signing in
junyu-w fa7c364
updated env file
junyu-w 3d0caf7
passed tests assumed no whitelist functionality
junyu-w bab3832
removed test from env file
junyu-w a70594d
fixed bug in user login feature
junyu-w 1a1b511
removed duplicated notice msg
junyu-w f99a57d
updated env file to include staging environment
junyu-w d9eba9a
removed whitelist checking
junyu-w 8e3e1bd
added user uid validation
junyu-w 327480a
removed uid validation because of conflict with admin
junyu-w f9959ab
front-end added
junyu-w 76378af
added user authentication
junyu-w c47f8dd
updated schema & staging env encryption key
junyu-w d816160
Add whitelist feature
ysiad 3a2ce5e
fixed old tests except for view metric sample with secrets & removed …
junyu-w 10790f9
removed redundant user session check
junyu-w a1f8e70
add createe user in whitelist
ysiad de004bd
add feature: delete accounts from whitelist
ysiad 65ce3df
add feature: delete accounts from whitelist
ysiad 51f6f83
Merge conflicts
ysiad 263c8ac
Fix bugs for whitelist
ysiad b36fe48
Merge branch 'feature/login-with-github' of https://github.com/DrakeW…
ysiad 0153f32
Fix bugs
ysiad 45bb9f5
Fix migration issues
ysiad 3615568
Fix features as the pull request comments suggested
ysiad b81d931
Fix issues in previous pull request
ysiad ec69272
Fix issues in migration file
ysiad 4293e63
Deleted unused files
ysiad d1c233e
Fix issues
ysiad 8285af4
pull
ysiad 0907a2f
adjust whitelist
ysiad 04b2603
Merge branch 'develop' of https://github.com/DrakeW/projectscope into…
ysiad 077a0cf
functionality complete
ysiad 2e5118b
Change the whitelist to contain github username
ysiad c0fefcc
modify the description for feature test
ysiad 47a7c62
Fix issues as the comments suggested
ysiad effd2c2
Add session destroy for whitelist
ysiad 2e6a5da
Fix whitelist delete identity issues
ysiad 753c59f
Fix conflict with develop branch
ysiad 14a16f1
Fix issues in readme
ysiad 87d53e7
Add the line back in Readme
ysiad ce6ad7b
better formatting
ysiad b6315dd
Merge branch 'feature/whitelist' of https://github.com/DrakeW/project…
ysiad fbc4f30
change the order of the link
ysiad 82ac558
Modified column name
ysiad fddb6a1
set attr_accessible
ysiad 644302a
fix accessor
ysiad 4849a2b
pull from dev branch
ysiad 7fb3aae
1. set role default to student; 2.change whitelist to privilege contr…
ysiad 5a81b40
change the prompt sentence
ysiad 8410cbe
modified the prompt message
ysiad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| class WhitelistsController < ApplicationController | ||
| before_action :check_if_coach | ||
|
|
||
| # GET /whitelists | ||
| def index | ||
| @permitted_users = User.all | ||
| end | ||
|
|
||
| # GET /whitelists/new | ||
| def new | ||
| @authorized_user = Whitelist.new(user_params) | ||
| end | ||
|
|
||
| # POST /whitelists/ | ||
| def create | ||
| username = params[:username] | ||
| if Whitelist.has_username?(username) | ||
| flash[:notice] = "User #{username} already exists in whitelist. " | ||
| else | ||
| begin | ||
| Whitelist.create!(username: username) | ||
| flash[:notice] = "Add user #{username} successfully." | ||
| rescue ActiveRecord::RecordInvalid | ||
| flash[:notice] = "Invalid username format." | ||
| end | ||
| end | ||
| redirect_to whitelists_path | ||
| end | ||
|
|
||
| # DELETE /whitelists/ | ||
| def destroy | ||
| user = Whitelist.find(params[:id]) | ||
| if user.username.eql?(current_user.provider_username) | ||
| flash[:notice] = "Delete yourself from the whitelist is not allowed. " | ||
| else | ||
| user.destroy! | ||
| flash[:notice] = "User is deleted successfully." | ||
| end | ||
| redirect_to whitelists_path | ||
| end | ||
|
|
||
| def check_if_coach | ||
| unless current_user.role.eql?("admin") or current_user.role.eql?("coach") | ||
| flash[:notice] = "You have no privilege to manipulate privilege control." | ||
| redirect_to projects_url | ||
| end | ||
| end | ||
|
|
||
| def upgrade | ||
| unless current_user.role.eql?("admin") or current_user.role.eql?("coach") | ||
| flash[:alert] = "You do not have privilege to change other user's role. " | ||
| redirect_to whitelists_path | ||
| return | ||
| end | ||
| user = User.find(params[:id]) | ||
| if user.role.eql?("admin") | ||
| flash[:alert] = "Admin role cannot be changed." | ||
| end | ||
| if user.role.eql?("student") | ||
| user.change_role("coach") | ||
| end | ||
| redirect_to whitelists_path | ||
| end | ||
|
|
||
| def downgrade | ||
| unless current_user.role.eql?("admin") or current_user.role.eql?("coach") | ||
| flash[:alert] = "You do not have privilege to change other user's role. " | ||
| redirect_to whitelists_path | ||
| return | ||
| end | ||
| user = User.find(params[:id]) | ||
| if user.role.eql?("admin") | ||
| flash[:alert] = "Admin role cannot be changed." | ||
| end | ||
| if user.role.eql?("coach") | ||
| user.change_role("student") | ||
| end | ||
| redirect_to whitelists_path | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def user_params | ||
| params.require(:whitelist).permit(:username) | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # == Schema Information | ||
| # | ||
| # Table name: whitelists | ||
| # | ||
| # id :integer not null, primary key | ||
| # username :string | ||
| # | ||
|
|
||
| class Whitelist < ActiveRecord::Base | ||
| validates_format_of :username,:with => /\A[a-z0-9\-_]+\z/i | ||
|
|
||
| def self.has_username?(username) | ||
| return !Whitelist.find_by_username(username).nil? | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| = form_tag whitelists_path do | ||
| = field_set_tag do | ||
| = label_tag :username, 'GitHub username' | ||
| = text_field_tag :username | ||
| = submit_tag 'Add' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| :css | ||
| #Users{ | ||
| border-collapse: collapse; | ||
| width: 80%; | ||
| margin-right: auto; | ||
| } | ||
|
|
||
| #Users td, #Users th { | ||
| border: 1px solid #ddd; | ||
| padding: 8px; | ||
| } | ||
|
|
||
| #Users tr:nth-child(even){background-color: #f2f2f2;} | ||
|
|
||
| #Users tr:hover {background-color: #ddd;} | ||
|
|
||
| #Users th { | ||
| padding-top: 12px; | ||
| padding-bottom: 12px; | ||
| text-align: left; | ||
| background-color: #337ab7; | ||
| color: white; | ||
| } | ||
| #Users tr { | ||
| text-align: left; | ||
| } | ||
|
|
||
| %h1 Privilege Control | ||
|
|
||
| %table#Users | ||
| %thead | ||
| %tr | ||
| %th GitHub Account | ||
| %th Role | ||
| %th Action | ||
|
|
||
| %tbody | ||
| - @permitted_users.each do |user| | ||
| %tr | ||
| %td= user.provider_username | ||
| %td= user.role | ||
| -if user.role.eql?("coach") | ||
| %td= link_to "Downgrade to student", downgrade_user_path(user), :method => :get, data: { confirm: "Do you want to downgrade user #{user.provider_username} from the whitelist?" }, :user => user | ||
| -elsif user.role.eql?("student") | ||
| %td= link_to "Upgrade to coach", upgrade_user_path(user), :method => :get, data: { confirm: "Do you want to upgrade user #{user.provider_username} from the whitelist?" }, :user => user | ||
| -else | ||
| %td | ||
|
|
||
| %br/ | ||
| = link_to 'Back to project page', projects_url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <h1>Authorize Users to have access to ProjectScope</h1> | ||
|
|
||
| <%= render 'add' %> | ||
|
|
||
| <input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden"> | ||
| <%= link_to 'Back', whitelists_path %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| Rails.application.routes.draw do | ||
| resources :users, :only => [:show, :update], :path => "u" | ||
| devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }, :skip => [:password] | ||
|
|
||
| resources :projects | ||
| root 'projects#index' | ||
| resources :whitelists | ||
|
|
||
| get '/whitelists/upgrade/:id', :to => 'whitelists#upgrade', :as => 'upgrade_user' | ||
| get '/whitelists/downgrade/:id', :to => 'whitelists#downgrade', :as => 'downgrade_user' | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| class AddRoleToUsers < ActiveRecord::Migration | ||
| def change | ||
| add_column :users, :role, :string, null: false, default: "coach" | ||
| add_column :users, :role, :string, null: false, default: "student" | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class CreateWhitelists < ActiveRecord::Migration | ||
| def change | ||
| create_table :whitelists, :force => true do |t| | ||
| t.string :username # default: "", null: false | ||
| end | ||
| add_index :whitelists, :username | ||
| end | ||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class CreateAuthorizedUser < ActiveRecord::Migration | ||
| def up | ||
| Whitelist.create!(username: "DrakeW") | ||
| Whitelist.create!(username: "armandofox") | ||
| end | ||
|
|
||
| def down | ||
| Whitelist.where(username: "DrakeW").first.destroy | ||
| Whitelist.where(username: "armandofox").first.destroy | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| Given(/^"([^"]*)" is in the whitelist$/) do |username| | ||
| Whitelist.create!(username: username) | ||
| end | ||
|
|
||
| Then /^I should be admin$/ do | ||
| expect(current_user.role).to eq "admin" | ||
| end | ||
|
|
||
| Given /^I enter the whitelist page$/ do | ||
| visit path_to("the whitelist page") | ||
| sleep(1) | ||
| end | ||
|
|
||
| When /^I follow the first "Delete"$/ do | ||
| first(:link, "Delete").click | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we generally try and avoid manipulating data in our migrations - maybe put this in seed file?
https://robots.thoughtbot.com/data-migrations-in-rails