Skip to content

Commit

Permalink
feat: add Researcher Classes landing page, controller, routes, policy…
Browse files Browse the repository at this point in the history
…, and policy spec [PT-187185134]
  • Loading branch information
pjanik committed Mar 20, 2024
1 parent fd1ce82 commit 32c9af8
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
7 changes: 7 additions & 0 deletions rails/app/controllers/admin/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def edit
# renders edit.html.haml
end

# GET /admin/projects/1/classes
def classes
@project = Admin::Project.find(params[:id])
authorize @project
# renders classes.html.haml
end

# POST /admin/projects
def create
authorize Admin::Project
Expand Down
2 changes: 1 addition & 1 deletion rails/app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def researcher_project_links
links << {
id: "/researcher_projects/#{project.id}",
label: project.name,
url: url_for(project),
url: url_for([:classes, project]),
}
end

Expand Down
4 changes: 4 additions & 0 deletions rails/app/policies/admin/project_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ def assign_to_material?
def api_show?
teacher? || admin?
end

def classes?
update_or_edit? || user.is_project_researcher?(record)
end
end
2 changes: 2 additions & 0 deletions rails/app/views/admin/projects/classes.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%div
%h1 Research Classes: #{@project.name}
3 changes: 3 additions & 0 deletions rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@
resources :projects do
resources :cohorts
resources :project_links
member do
get :classes
end
end
resources :cohorts
resources :project_links
Expand Down
33 changes: 32 additions & 1 deletion rails/spec/policies/admin/project_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,39 @@
end
end

describe 'classes' do
describe 'a regular user' do
it 'should not permit access to classes page' do
expect(policy.classes?).to be false
end
end

end
describe 'as site admin' do
before(:each) do
allow(user).to receive(:has_role?).with('admin').and_return(true)
end
it 'should permit access to classses page' do
expect(policy.classes?).to be true
end
end

describe 'as a project admin' do
before(:each) do
allow(user).to receive(:is_project_admin?).with(project).and_return(true)
end
it 'should permit access to classses page' do
expect(policy.classes?).to be true
end
end

describe 'as a project researcher' do
before(:each) do
allow(user).to receive(:is_project_researcher?).with(project).and_return(true)
end
it 'should permit access to classses page' do
expect(policy.classes?).to be true
end
end
end
end
end

0 comments on commit 32c9af8

Please sign in to comment.