Skip to content
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

URL with name instead of id #318

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ DEPENDENCIES
newrelic_rpm
paperclip (~> 4.3)
pdfkit (~> 0.6.2)
paperclip (~> 4.3)
pg (~> 0.17.0)
pghero
poltergeist (~> 1.5.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/assistants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def destroy
private

def set_course
@course = Course.find_by id: params[:course_id]
@course = Course.find_by! name: params[:course_name]
end

def assistant_params
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/breadcrumb_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def add_course_breadcrumb

def add_exercise_breadcrumb
if @exercise
add_breadcrumb "Exercise #{@exercise.name}", exercise_path(@exercise)
add_breadcrumb "Exercise #{@exercise.name}", organization_course_exercise_path(@organization, @course, @exercise)
elsif @submission && @submission.exercise
add_breadcrumb "Exercise #{@submission.exercise.name}", exercise_path(@submission.exercise)
add_breadcrumb "Exercise #{@submission.exercise.name}", organization_course_exercise_path(@organization, @course, @submission.exercise)
elsif @submission && @submission.exercise_name
add_breadcrumb "(deleted exercise #{@submission.exercise_name}"
else
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/course_notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ class CourseNotificationsController < ApplicationController
before_action :set_organization

def new
course = Course.find(course_notification_params[:course_id])
course = Course.find_by!(name: course_notification_params[:course_name])
authorize! :send_mail_to_participants, course
@notifier ||= CourseNotification.new
@course = Course.find_by(id: params[:course_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
add_course_breadcrumb
add_breadcrumb 'Course notification'
end

def create
course = Course.find(course_notification_params[:course_id])
course = Course.find_by!(name: course_notification_params[:course_name])
authorize! :send_mail_to_participants, course

participants = User.course_students(course)
Expand Down Expand Up @@ -48,10 +48,10 @@ def create
private

def course_notification_params
params.permit(:commit, :course_id, course_notification: [:topic, :message])
params.permit(:commit, :course_name, course_notification: [:topic, :message])
end

def set_organization
@organization = Organization.find_by(slug: params[:organization_id])
@organization = Organization.find_by!(slug: params[:organization_id])
end
end
9 changes: 5 additions & 4 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def show

# Method for teacher to give a single course for students to select.
def show_json
course = [Course.find(params[:id])]
course = [Course.find_by!(name: params[:name])]
authorize! :read, course
return respond_access_denied('Authentication required') if current_user.guest?

Expand Down Expand Up @@ -166,7 +166,7 @@ def save_deadlines
end

def help
@course = Course.find(params[:course_id])
@course = Course.find_by!(name: params[:course_name])
authorize! :read, @course
add_course_breadcrumb
add_breadcrumb 'Help page'
Expand Down Expand Up @@ -245,11 +245,12 @@ def assign_show_view_vars
end

def set_organization
@organization = Organization.find_by(slug: params[:organization_id])
@organization ||= Organization.find_by!(slug: params[:organization_id])
end

def set_course
@course = Course.find(params[:id])
@organization ||= Organization.find_by!(slug: params[:organization_id])
@course = Course.find_by!(name: params[:name], organization: @organization)
end

def group_params
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
class EmailsController < ApplicationController
def index
organization_id = params[:organization_id]
course_id = params[:id]
course_name = params[:name]

if organization_id && course_id
if organization_id && course_name
index_course
else
index_global
Expand All @@ -26,8 +26,8 @@ def index_global
end

def index_course
@course = Course.find(params[:id])
@organization = @course.organization
@organization = Organization.find_by!(slug: params[:organization_id])
@course = Course.find_by!(name: params[:name], organization: @organization)

authorize! :list_user_emails, @course

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/exercise_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ class ExerciseStatusController < ApplicationController
skip_authorization_check

def show
course_id = params[:course_id]
course_name = params[:course_name]
user_id = params[:id]

course = Course.where(id: course_id).first || Course.where(name: course_id).first
course = Course.where(id: course_name).first || Course.where(name: course_name).first
user = User.where(id: user_id).first || User.where(login: user_id).first

return respond_access_denied unless course.visible_to?(Guest.new) || current_user.administrator?
Expand Down
17 changes: 12 additions & 5 deletions app/controllers/exercises_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class ExercisesController < ApplicationController
before_action :set_params, only: [:show]

def show
@exercise = Exercise.find(params[:id])
@course = Course.lock('FOR SHARE').find(@exercise.course_id)
@organization = @course.organization
authorize! :read, @course
authorize! :read, @exercise

Expand Down Expand Up @@ -55,8 +54,8 @@ def show
end

def set_disabled_statuses
@course = Course.find(params[:course_id])
@organization = @course.organization
@organization = Organization.find_by!(slug: params[:organization_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
authorize! :teach, @organization

selected_exercise_ids = params[:course][:exercises]
Expand All @@ -71,4 +70,12 @@ def set_disabled_statuses
redirect_to manage_exercises_organization_course_path(@organization, @course),
notice: 'Exercises successfully updated.'
end

private

def set_params
@organization = Organization.find_by!(slug: params[:organization_id])
@course = Course.lock('FOR SHARE').find_by!(name: params[:course_name], organization: @organization)
@exercise = Exercise.find_by!(name: params[:name], course: @course)
end
end
4 changes: 2 additions & 2 deletions app/controllers/feedback_answers_charts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class FeedbackAnswersChartsController < ApplicationController
def show
@course = Course.find(params[:course_id])
@organization = @course.organization
@organization = Organization.find_by!(slug: params[:organization_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)

authorize! :read_feedback_questions, @course
authorize! :read_feedback_answers, @course
Expand Down
15 changes: 8 additions & 7 deletions app/controllers/feedback_answers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
class FeedbackAnswersController < ApplicationController
def index
if params[:course_id]
@course = Course.find(params[:course_id])
@organization = Organization.find_by!(slug: params[:organization_id])

if params[:course_name] && !params[:exercise_name]
@course = Course.find_by!(name: params[:course_name], organization: @organization)
@parent = @course
@numeric_stats = @course.exercises.where(hidden: false).sort.map do |ex|
[ex, FeedbackAnswer.numeric_answer_averages(ex), ex.submissions_having_feedback.count]
end
@title = @course.name
elsif params[:exercise_id]
@exercise = Exercise.find(params[:exercise_id])
@course = @exercise.course
elsif params[:exercise_name]
@course = Course.find_by!(name: params[:course_name], organization: @organization)
@exercise = Exercise.find_by!(name: params[:exercise_name], course: @course)
@parent = @exercise
@numeric_stats = [[@exercise, FeedbackAnswer.numeric_answer_averages(@exercise), @exercise.submissions_having_feedback.count]]
@title = @exercise.name
else
return respond_not_found
end

@organization = @course.organization
add_course_breadcrumb
if @exercise
add_exercise_breadcrumb
add_breadcrumb 'Feedback', exercise_feedback_answers_path(@exercise)
add_breadcrumb 'Feedback', organization_course_exercise_feedback_answers_path(@organization, @course, @exercise)
else
add_breadcrumb 'Feedback', organization_course_feedback_answers_path
end
Expand Down
12 changes: 4 additions & 8 deletions app/controllers/feedback_questions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Handles the feedback question editing UI.
class FeedbackQuestionsController < ApplicationController
before_action :set_course
before_action :set_organization
before_action :set_params, only: [:index, :create, :new]

def index
add_course_breadcrumb
Expand Down Expand Up @@ -85,17 +84,14 @@ def feedback_question_params
params.permit({ feedback_question: [:question, :title, :kind] }, :intrange_min, :intrange_max, :commit, :course_id)
end

def set_course
@course = Course.find(params[:course_id]) if params[:course_id]
def set_params
@organization = Organization.find_by!(slug: params[:organization_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization) if params[:course_name]
authorize! :read, @course
end

def fix_question_kind(question)
return unless question.kind == 'intrange'
question.kind += "[#{params[:intrange_min]}..#{params[:intrange_max]}]"
end

def set_organization
@organization = Organization.find_by(slug: params[:organization_id])
end
end
3 changes: 1 addition & 2 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def percent_completed_hash(courses, user)
end

def set_organization
@organization = Organization.find_by(slug: params[:id])
fail ActiveRecord::RecordNotFound, 'Invalid organization id' if @organization.nil?
@organization = Organization.find_by!(slug: params[:id])
end

def organization_params
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/points_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PointsController < ApplicationController
before_action :set_organization

def index
@course = Course.find(params[:course_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
authorize! :see_points, @course
add_course_breadcrumb
add_breadcrumb 'Points'
Expand All @@ -27,13 +27,13 @@ def index
def refresh_gdocs
authorize! :refresh, @course
@sheetname = params[:id]
@course = Course.find(params[:course_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
@notifications = @course.refresh_gdocs_worksheet @sheetname
end

def show
@sheetname = params[:id]
@course = Course.find(params[:course_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
authorize! :see_points, @course

add_course_breadcrumb
Expand Down Expand Up @@ -110,6 +110,6 @@ def sort_summary(summary, sorting)
end

def set_organization
@organization = Organization.find_by(slug: params[:organization_id])
@organization = Organization.find_by!(slug: params[:organization_id])
end
end
4 changes: 2 additions & 2 deletions app/controllers/reviewed_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
class ReviewedSubmissionsController < ApplicationController

def index
@course = Course.find(params[:course_id])
@organization = @course.organization
@organization = Organization.find_by!(slug: params[:organization_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
authorize! :teach, @course
add_course_breadcrumb
add_breadcrumb 'Code reviews', organization_course_reviews_path(@organization, @course)
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/reviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ class ReviewsController < ApplicationController
before_action :set_organization, except: [:new, :create]

def index
if params[:course_id]
if params[:course_name]
fetch :course
@organization = @course.organization
@my_reviews = @course.submissions
.where(user_id: current_user.id)
.where('requests_review OR requires_review OR reviewed')
Expand Down Expand Up @@ -201,7 +200,7 @@ def mark_as_reviewed

def fetch(*stuff)
if stuff.include? :course
@course = Course.find(params[:course_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
authorize! :read, @course
end
if stuff.include? :submission
Expand Down Expand Up @@ -265,6 +264,6 @@ def award_points
private

def set_organization
@organization = Organization.find_by(slug: params[:organization_id])
@organization = Organization.find_by!(slug: params[:organization_id])
end
end
8 changes: 4 additions & 4 deletions app/controllers/solutions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Returns the suggestion solution as a ZIP.
class SolutionsController < ApplicationController
def show
@exercise = Exercise.find(params[:exercise_id])
@course = @exercise.course
@organization = @course.organization
@organization = Organization.find_by!(slug: params[:organization_id])
@course = Course.find_by!(name: params[:course_name], organization: @organization)
@exercise = Exercise.find_by!(name: params[:exercise_name], course: @course)

add_course_breadcrumb
add_exercise_breadcrumb
add_breadcrumb 'Suggested solution'
add_breadcrumb 'Suggested solution', organization_course_exercise_solution_path(@organization, @course, @exercise)

@solution = @exercise.solution
begin
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def show
private

def get_vars
if params[:course_id]
@course = Course.find(params[:course_id])
if params[:course_name]
@course = Course.find_by!(name: params[:course_name], organization: @organization)
end
end

Expand Down Expand Up @@ -168,6 +168,6 @@ def param_as_one_of(name, valid_values)
private

def set_organization
@organization = Organization.find_by(slug: params[:organization_id])
@organization = Organization.find_by!(slug: params[:organization_id])
end
end
Loading