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

Fix code duplication #253

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/controllers/grades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/releases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sprints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 5 additions & 15 deletions app/helpers/validations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down