Skip to content

Commit

Permalink
Merge pull request #1018 from ElixirTeSS/lp-curator-role
Browse files Browse the repository at this point in the history
Learning Path curator role
  • Loading branch information
fbacall committed Sep 2, 2024
2 parents 7b44523 + 1340468 commit 379b8fe
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/policies/learning_path_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def update?
end

def manage?
curators_and_admin
curators_and_admin || @user&.has_role?(:learning_path_curator)
end

def create?
curators_and_admin
manage?
end

class Scope < Scope
Expand Down
4 changes: 3 additions & 1 deletion config/data/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ default_user:
basic_user: # Cannot create content
title: Basic user
unverified_user: # Content requires approval before being visible
title: New user
title: New user
learning_path_curator:
title: Learning path curator
24 changes: 21 additions & 3 deletions test/controllers/learning_paths_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class LearningPathsControllerTest < ActionController::TestCase
get :new
assert_response :success

sign_in users(:learning_path_curator)
get :new
assert_response :success

sign_in users(:admin)
get :new
assert_response :success
Expand All @@ -82,6 +86,12 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_response :success
end

test 'should get edit for learning path curator' do
sign_in users(:learning_path_curator)
get :edit, params: { id: @learning_path }
assert_response :success
end

test 'should get edit for admin' do
#Owner of learning_path logged in = SUCCESS
sign_in users(:admin)
Expand All @@ -105,6 +115,14 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_redirected_to learning_path_path(assigns(:learning_path))
end

test 'should create learning_path for learning_path_curator' do
sign_in users(:learning_path_curator)
assert_difference('LearningPath.count') do
post :create, params: { learning_path: { title: @learning_path.title, description: @learning_path.description } }
end
assert_redirected_to learning_path_path(assigns(:learning_path))
end

test 'should create learning_path for admin' do
sign_in users(:admin)
assert_difference('LearningPath.count') do
Expand Down Expand Up @@ -339,8 +357,8 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 #No Edit
end

test 'show action buttons when curator' do
sign_in users(:curator)
test 'show action buttons when learning_path_curator' do
sign_in users(:learning_path_curator)

get :show, params: { id: @learning_path }

Expand All @@ -365,7 +383,7 @@ class LearningPathsControllerTest < ActionController::TestCase
end

test 'should allow access to private learning_paths if privileged' do
sign_in users(:curator)
sign_in users(:learning_path_curator)
get :show, params: { id: learning_paths(:in_development_learning_path) }
assert_response :success
end
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ basic_user:
unverified_user: # Content requires approval before being visible
name: unverified_user
title: New user

learning_path_curator:
name: learning_path_curator
title: Learning path curator
8 changes: 7 additions & 1 deletion test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ banned_user:
role: user
authentication_token: <%= Devise.friendly_token %>


shadowbanned_user:
username: Chad O'Band
email: 'sbanned@notarealdomain.org'
Expand Down Expand Up @@ -151,3 +150,10 @@ upcase_username_and_email:
email: 'MixedCaseEmail@example.com'
encrypted_password: <%= Devise::Encryptor.digest(User, 'private') %>
confirmed_at: <%= Time.zone.now %>

learning_path_curator:
username: 'lp_cur8r'
email: 'lpc@example.com'
encrypted_password: 'learning_paths_curator_encrypted_password'
confirmed_at: <%= Time.zone.now %>
role: learning_path_curator

0 comments on commit 379b8fe

Please sign in to comment.