diff --git a/app/controllers/grades_controller.rb b/app/controllers/grades_controller.rb index 1823b04..9f7ed59 100644 --- a/app/controllers/grades_controller.rb +++ b/app/controllers/grades_controller.rb @@ -9,7 +9,7 @@ class GradesController < ApplicationController end before_action only: [:show, :update] do - validate_grade(:id, 0) + validate_grade_and_release(:id, 0, "grade") end def index diff --git a/app/controllers/releases_controller.rb b/app/controllers/releases_controller.rb index 3b10f44..1fcfd57 100644 --- a/app/controllers/releases_controller.rb +++ b/app/controllers/releases_controller.rb @@ -9,7 +9,7 @@ class ReleasesController < ApplicationController end before_action only: [:show, :edit, :update, :destroy] do - validate_release(:id, 0) + validate_grade_and_release(:id, 0, "release") end def index diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index c82535a..1a5ebb5 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -8,7 +8,7 @@ class SprintsController < ApplicationController before_action :set_sprint, only: [:show, :update, :destroy, :get_burndown] before_action only: [:index, :create] do - validate_release(0, :release_id) + validate_grade_and_release(0, :release_id, "release") end before_action only: [:show, :update, :destroy, :get_velocity, :get_metrics] do diff --git a/app/helpers/validations_helper.rb b/app/helpers/validations_helper.rb index 76f37b9..389ea80 100644 --- a/app/helpers/validations_helper.rb +++ b/app/helpers/validations_helper.rb @@ -86,24 +86,14 @@ def validate_project(id, project_id) end end - - def validate_grade(id, grade_id) + def validate_grade_and_release(id, element_id, component_type) current_user - verifies_id(id, grade_id, "grade") - project_grade - user - - if @current_user.id == @user.id - return true + verifies_id(id, element_id, component_type) + if component_type == "grade" + project_grade else - render json: { error: "Not Authorized" }, status: 401 + project end - end - - def validate_release(id, release_id) - current_user - verifies_id(id, release_id, "release") - project user if @current_user.id == @user.id