Skip to content
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
7 changes: 6 additions & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ def initialize(user)
private

def define_common_non_student_abilities(user)
return if user&.student?
if user&.student?
# Allow students to view the Experience CS preview starter template.
can :show, Project, user_id: nil, school_id: nil, project_type: Project::Types::CODE_EDITOR_SCRATCH
can :show, Component, project: { user_id: nil, school_id: nil, project_type: Project::Types::CODE_EDITOR_SCRATCH }
return
Comment thread
DNR500 marked this conversation as resolved.
end

# Anyone can view projects not owned by a user or a school.
can :show, Project, user_id: nil, school_id: nil
Expand Down
28 changes: 28 additions & 0 deletions spec/models/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@
end
end

context 'with a persisted school student' do
let(:school) { create(:school) }
let(:user) { create(:user, id: user_id) }
let(:public_scratch_starter) do
build(:project,
user_id: nil,
school_id: nil,
project_type: Project::Types::CODE_EDITOR_SCRATCH)
end
let(:public_python_starter) do
build(:project,
user_id: nil,
school_id: nil,
project_type: Project::Types::PYTHON)
end
let(:public_scratch_component) { build(:component, project: public_scratch_starter) }
let(:public_python_component) { build(:component, project: public_python_starter) }

before do
create(:student_role, user_id: user.id, school:)
end

it { is_expected.to be_able_to(:show, public_scratch_starter) }
it { is_expected.not_to be_able_to(:show, public_python_starter) }
it { is_expected.to be_able_to(:show, public_scratch_component) }
it { is_expected.not_to be_able_to(:show, public_python_component) }
end

context 'with an experience-cs admin' do
let(:user) { build(:experience_cs_admin_user, id: user_id) }
let(:another_project) { build(:project) }
Expand Down
Loading