forked from AdaGold/media-ranker-revisited
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Edges Chantelle MediaRanker_Revisited #21
Open
BASIC-Belic
wants to merge
25
commits into
Ada-C10:master
Choose a base branch
from
BASIC-Belic:master
base: master
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
25 commits
Select commit
Hold shift + click to select a range
3e9d835
added Oauth login
BASIC-Belic 4938e3e
temp solution for resolving if username does not exist in User.build_…
BASIC-Belic cdfb2d2
changed sessionscontroller#create to match the flash logic in layouts…
BASIC-Belic 33b633e
changed sessions#destroy flash to flash instead of flash.now bc styli…
BASIC-Belic e76ecaf
also changed sessions#create else statement from flash.now to flash
BASIC-Belic 590f875
replaced User.find(session[:user_id]) with @login_user in application…
BASIC-Belic 154f990
changed users.yml file to include uid and provider
BASIC-Belic e23cb4a
root test working, first test for work#index
BASIC-Belic c606b74
added new and create workscontroller tests
BASIC-Belic e298e80
added workscontroller edit test
BASIC-Belic 8542b50
added test for workscontroller #update
BASIC-Belic da50420
destroy testing done
BASIC-Belic 67722b1
changed else in User self.build_from_github(auth_hash) method
BASIC-Belic eceafc0
changed application html to show logged in username not name
BASIC-Belic c24d05e
uncommented read me
BASIC-Belic 06a926e
added uid and provider to failing model test
BASIC-Belic 4e897b9
fixed typos in omniauth
BASIC-Belic 403012c
added authorization, flash not working
BASIC-Belic 9371420
got works test to green again with auth
BASIC-Belic 6849579
upvote controller tests
BASIC-Belic 1c19d40
user controller tests
BASIC-Belic 6bb24d8
sessions controller test #create
BASIC-Belic a518c65
sessions #destro
BASIC-Belic 2a9a6c8
more works controller testing for guest
BASIC-Belic 53b48de
Modified the edit and delete functionality to ensure that users can o…
BASIC-Belic 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 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 |
---|---|---|
|
@@ -15,3 +15,6 @@ | |
|
||
# Ignore Byebug command history file. | ||
.byebug_history | ||
|
||
#Storing Credentials | ||
.env |
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ class WorksController < ApplicationController | |
# We should always be able to tell what category | ||
# of work we're dealing with | ||
before_action :category_from_work, except: [:root, :index, :new, :create] | ||
before_action :require_login, except: [:root, :show, :upvote] | ||
|
||
def root | ||
@albums = Work.best_albums | ||
|
@@ -21,6 +22,7 @@ def new | |
def create | ||
@work = Work.new(media_params) | ||
@media_category = @work.category | ||
|
||
if @work.save | ||
flash[:status] = :success | ||
flash[:result_text] = "Successfully created #{@media_category.singularize} #{@work.id}" | ||
|
@@ -38,6 +40,11 @@ def show | |
end | ||
|
||
def edit | ||
if session[:user_id] != @work.user_id | ||
redirect_back fallback_location: root_path | ||
flash[:status] = :error | ||
flash[:result_text] = "Sorry, can't edit a work that you don't own." | ||
end | ||
end | ||
|
||
def update | ||
|
@@ -50,11 +57,16 @@ def update | |
flash.now[:status] = :failure | ||
flash.now[:result_text] = "Could not update #{@media_category.singularize}" | ||
flash.now[:messages] = @work.errors.messages | ||
render :edit, status: :not_found | ||
render :edit, status: :bad_request | ||
end | ||
end | ||
|
||
def destroy | ||
if session[:user_id] != @work.user_id | ||
redirect_back fallback_location: root_path | ||
flash[:status] = :error | ||
flash[:result_text] = "Sorry, can't edit a work that you don't own." | ||
end | ||
@work.destroy | ||
flash[:status] = :success | ||
flash[:result_text] = "Successfully destroyed #{@media_category.singularize} #{@work.id}" | ||
|
@@ -81,7 +93,7 @@ def upvote | |
redirect_back fallback_location: work_path(@work) | ||
end | ||
|
||
private | ||
private | ||
def media_params | ||
params.require(:work).permit(:title, :category, :creator, :description, :publication_year) | ||
end | ||
|
@@ -91,4 +103,12 @@ def category_from_work | |
render_404 unless @work | ||
@media_category = @work.category.downcase.pluralize | ||
end | ||
|
||
def require_login | ||
unless session[:user_id] | ||
|
||
flash[:error] = "You must be logged in to do that." | ||
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. I like that this is a controller filter, but you've got much the same code both here and in the |
||
redirect_to root_path | ||
end | ||
end | ||
end |
This file contains 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 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,4 @@ | ||
# config/initializers/omniauth.rb | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" | ||
end |
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.
You
redirect
but don'treturn
here, and thenredirect
again on line 40. This is a bug, and will cause Rails to throw an error! Your test coverage probably should have caught this...