Skip to content

Commit

Permalink
Correct authorization for programming_group new & create
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragrammel committed Aug 8, 2023
1 parent e9b10f3 commit 91ad81e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 8 additions & 5 deletions app/controllers/programming_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
class ProgrammingGroupsController < ApplicationController
include CommonBehavior

before_action :set_exercise_and_authorize, only: %i[new create]
before_action :set_exercise_and_authorize, only: MEMBER_ACTIONS + %i[create]
before_action :current_user_id_with_type, only: %i[new create]

def authorize!
authorize(@exercise || @exercises)
authorize(@programming_group || @programming_groups)
end

private :authorize!

def set_exercise_and_authorize
@exercise = Exercise.find(params[:exercise_id])
authorize!
policy(@exercise).implement?
end

private :set_exercise_and_authorize

def new
@programming_group = ProgrammingGroup.new(exercise: @exercise)
authorize!
set_exercise_and_authorize
end

def create
Expand All @@ -29,6 +29,7 @@ def create

unless programming_group_exists_for?(programming_partner_ids)
@programming_group = ProgrammingGroup.new(exercise: @exercise, programming_partner_ids:)
authorize!

unless programming_partner_ids.include? @current_user_id_with_type
@programming_group.external_users << current_user
Expand Down Expand Up @@ -71,6 +72,8 @@ def programming_group_exists_for?(user_ids_with_type)
flash.keep(:danger)
redirect_to new_exercise_programming_group_path
found_group = programming_group_id
@programming_group = ProgrammingGroup.find(found_group)
authorize!
break
end
break if found_group
Expand Down
6 changes: 5 additions & 1 deletion app/policies/programming_group_policy.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

class ProgrammingGroupPolicy < AdminOrAuthorPolicy
def new
def new?
everyone
end

def create?
everyone
end
end

0 comments on commit 91ad81e

Please sign in to comment.