-
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
base: develop
Are you sure you want to change the base?
Changes from 53 commits
dbc148b
79445f8
089e1eb
703b0be
cc649b2
ac82d6f
982f2a3
a3ada8b
acad466
e594d45
65dee30
aeb22e1
a59f53d
210605a
7abeb4d
d78f7b1
b94d7fd
d71c2da
5c127d4
fa7c364
3d0caf7
bab3832
a70594d
1a1b511
f99a57d
d9eba9a
8e3e1bd
327480a
f9959ab
76378af
c47f8dd
d816160
3a2ce5e
10790f9
a1f8e70
de004bd
65ce3df
51f6f83
263c8ac
b36fe48
0153f32
45bb9f5
3615568
b81d931
ec69272
4293e63
d1c233e
8285af4
0907a2f
04b2603
077a0cf
2e5118b
c0fefcc
47a7c62
effd2c2
2e6a5da
753c59f
14a16f1
87d53e7
ce6ad7b
b6315dd
fbc4f30
82ac558
fddb6a1
644302a
4849a2b
7fb3aae
5a81b40
8410cbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| class Users::ConfirmationsController < Devise::ConfirmationsController | ||
| # GET /resource/confirmation/new | ||
| # def new | ||
| # super | ||
| # end | ||
|
|
||
| # POST /resource/confirmation | ||
| # def create | ||
| # super | ||
| # end | ||
|
|
||
| # GET /resource/confirmation?confirmation_token=abcdef | ||
| # def show | ||
| # super | ||
| # end | ||
|
|
||
| # protected | ||
|
|
||
| # The path used after resending confirmation instructions. | ||
| # def after_resending_confirmation_instructions_path_for(resource_name) | ||
| # super(resource_name) | ||
| # end | ||
|
|
||
| # The path used after confirmation. | ||
| # def after_confirmation_path_for(resource_name, resource) | ||
| # super(resource_name, resource) | ||
| # end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| class Users::PasswordsController < Devise::PasswordsController | ||
| # GET /resource/password/new | ||
| # def new | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file was deleted on develop too
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted. |
||
| # super | ||
| # end | ||
|
|
||
| # POST /resource/password | ||
| # def create | ||
| # super | ||
| # end | ||
|
|
||
| # GET /resource/password/edit?reset_password_token=abcdef | ||
| # def edit | ||
| # super | ||
| # end | ||
|
|
||
| # PUT /resource/password | ||
| # def update | ||
| # super | ||
| # end | ||
|
|
||
| # protected | ||
|
|
||
| # def after_resetting_password_path_for(resource) | ||
| # super(resource) | ||
| # end | ||
|
|
||
| # The path used after sending reset password instructions | ||
| # def after_sending_reset_password_instructions_path_for(resource_name) | ||
| # super(resource_name) | ||
| # end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| class Users::RegistrationsController < Devise::RegistrationsController | ||
| # before_action :configure_sign_up_params, only: [:create] | ||
| # before_action :configure_account_update_params, only: [:update] | ||
|
|
||
| # GET /resource/sign_up | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for this one... :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted |
||
| # def new | ||
| # super | ||
| # end | ||
|
|
||
| # POST /resource | ||
| # def create | ||
| # super | ||
| # end | ||
|
|
||
| # GET /resource/edit | ||
| # def edit | ||
| # super | ||
| # end | ||
|
|
||
| # PUT /resource | ||
| # def update | ||
| # super | ||
| # end | ||
|
|
||
| # DELETE /resource | ||
| # def destroy | ||
| # super | ||
| # end | ||
|
|
||
| # GET /resource/cancel | ||
| # Forces the session data which is usually expired after sign | ||
| # in to be expired now. This is useful if the user wants to | ||
| # cancel oauth signing in/up in the middle of the process, | ||
| # removing all OAuth session data. | ||
| # def cancel | ||
| # super | ||
| # end | ||
|
|
||
| # protected | ||
|
|
||
| # If you have extra params to permit, append them to the sanitizer. | ||
| # def configure_sign_up_params | ||
| # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) | ||
| # end | ||
|
|
||
| # If you have extra params to permit, append them to the sanitizer. | ||
| # def configure_account_update_params | ||
| # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) | ||
| # end | ||
|
|
||
| # The path used after sign up. | ||
| # def after_sign_up_path_for(resource) | ||
| # super(resource) | ||
| # end | ||
|
|
||
| # The path used after sign up for inactive accounts. | ||
| # def after_inactive_sign_up_path_for(resource) | ||
| # super(resource) | ||
| # end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class Users::SessionsController < Devise::SessionsController | ||
| # before_action :configure_sign_in_params, only: [:create] | ||
|
|
||
| # GET /resource/sign_in | ||
| # def new | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted. |
||
| # super | ||
| # end | ||
|
|
||
| # POST /resource/sign_in | ||
| # def create | ||
| # super | ||
| # end | ||
|
|
||
| # DELETE /resource/sign_out | ||
| # def destroy | ||
| # super | ||
| # end | ||
|
|
||
| # protected | ||
|
|
||
| # If you have extra params to permit, append them to the sanitizer. | ||
| # def configure_sign_in_params | ||
| # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) | ||
| # end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| class Users::UnlocksController < Devise::UnlocksController | ||
| # GET /resource/unlock/new | ||
| # def new | ||
| # super | ||
| # end | ||
|
|
||
| # POST /resource/unlock | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleted
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted. Don't know why those files didn't get automatically deleted.. |
||
| # def create | ||
| # super | ||
| # end | ||
|
|
||
| # GET /resource/unlock?unlock_token=abcdef | ||
| # def show | ||
| # super | ||
| # end | ||
|
|
||
| # protected | ||
|
|
||
| # The path used after sending unlock password instructions | ||
| # def after_sending_unlock_instructions_path_for(resource) | ||
| # super(resource) | ||
| # end | ||
|
|
||
| # The path used after unlocking the resource | ||
| # def after_unlock_path_for(resource) | ||
| # super(resource) | ||
| # end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| class WhitelistsController < ApplicationController | ||
| before_action :check_if_in_whitelist | ||
|
|
||
| # GET /whitelists | ||
| def index | ||
| @permitted_users = Whitelist.all | ||
| end | ||
|
|
||
| # GET /whitelists/new | ||
| def new | ||
| @authorized_user = Whitelist.new | ||
| 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]) | ||
| user.destroy! | ||
| flash[:notice] = "User is deleted successfully. " | ||
| redirect_to whitelists_path | ||
| end | ||
|
|
||
| def check_if_in_whitelist | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we allowing anyone to edit whitelist or only admin?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the time our professor said, he meant for everyone in the whitelist. Still it's easy for us to change the privilege settings, however we might need to consider redesign the user model so that the privileges can be easily modified. |
||
| unless Whitelist.has_username?(current_user.provider_username) | ||
| flash[:notice] = "You are not authorized to manipulate whitelist." | ||
| redirect_to projects_url | ||
| end | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # == 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) | ||
| if Whitelist.find_by_username(username).nil? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the function body can be rewritten as
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| return false | ||
| else | ||
| return true | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,7 @@ | |
| %br/ | ||
|
|
||
| = link_to 'New Project', new_project_path | ||
|
|
||
| %br/ | ||
|
|
||
| = link_to 'Whitelist', whitelists_path | ||
| 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' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| %h1 Whitelist | ||
|
|
||
| %table | ||
| %thead | ||
| %tr | ||
| %th Authorized Users | ||
| %th Action | ||
|
|
||
| %tbody | ||
| - @permitted_users.each do |user| | ||
| %tr | ||
| %td= user.username | ||
| %td= link_to "Delete", whitelist_path(user), :method => :delete, data: { confirm: "Do you want to delete user #{user.username} from the whitelist?" }, :user => user | ||
|
|
||
| %br/ | ||
|
|
||
| = link_to 'Back to project page', projects_url | ||
|
|
||
| %br/ | ||
|
|
||
| = link_to 'Add user to whitelist', new_whitelist_path | ||
|
|
||
|
|
| 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 %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,10 @@ def change | |
| t.timestamps null: false | ||
| end | ||
|
|
||
| <<<<<<< HEAD | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. merge conflict left-over?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| ======= | ||
| add_index :users, :provider_username, unique: true | ||
| >>>>>>> bd78074f0cf5bfc8c5de0a81a4ecd57b3da8472f | ||
| add_index :users, :email, unique: true | ||
| add_index :users, :reset_password_token, unique: true | ||
| # add_index :users, :confirmation_token, unique: true | ||
|
|
||
| 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 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class CreateAuthorizedUser < ActiveRecord::Migration | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,4 +12,5 @@ | |
| ]) | ||
|
|
||
|
|
||
|
|
||
|
|
||
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.
this entire file was deleted in develop
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.
Deleted.