Skip to content
Merged
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
6 changes: 4 additions & 2 deletions app/models/taxonomy.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
class Taxonomy < ApplicationRecord
validates_lengths_from_database

after_create :assign_taxonomy_to_user

include Authorizable
include NestedAncestryCommon
include TopbarCacheExpiry

serialize :ignore_types, Array

before_create :assign_default_templates
after_create :assign_taxonomy_to_user
before_validation :sanitize_ignored_types

has_many :taxable_taxonomies, :dependent => :destroy
Expand Down Expand Up @@ -246,7 +245,10 @@ def hash_key_to_class(key)

def assign_taxonomy_to_user
return if User.current.nil? || User.current.admin

User.current.public_send(self.class.to_s.downcase.pluralize) << self
User.current.reload
User.current.invalidate_cache
end

def parent_id_does_not_escalate
Expand Down
26 changes: 26 additions & 0 deletions test/integration/location_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ def setup
assert page.has_link? "Raleigh"
end

test "create a location with an unprivileged user with admin usergroup" do
ug = FactoryBot.create(:usergroup, :admin => true)
user = FactoryBot.create(:user, :usergroups => [ug])

set_request_user(user)
assert_new_button(locations_path, "New Location", new_location_path)
fill_in "location_name", :with => "Raleigh"
click_button "Submit"
assert_current_path step2_location_path(Location.unscoped.order(:id).last)
end

test "create a location with an unprivileged user with create_locations permission" do
user = setup_user('view', 'locations')
setup_user('create', 'locations', 'name ~ "R*"')
set_request_user(user)
assert_new_button(locations_path, "New Location", new_location_path)
fill_in "location_name", :with => "aleigh2"
click_button "Submit"
error = find('div.alert')
assert_match "You don't have permission create_locations", error.text

fill_in "location_name", :with => "Raleigh2"
click_button "Submit"
assert_current_path edit_location_path(Location.unscoped.order(:id).last)
end

# PENDING
# test "mismatches report" do
# end
Expand Down
Loading