mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-23 04:02:19 -05:00
add role validation from a set list
This commit is contained in:
2 files changed
+15
No files matched your search
@@ -1,4 +1,11 @@
|
||||
class Role < ApplicationRecord
|
||||
ROLES = [
|
||||
:administrator, # Can do everything
|
||||
:editor, # Can edit any models
|
||||
:contributor, # Can upload models and edit their own
|
||||
:viewer # Can view models; read only access
|
||||
]
|
||||
|
||||
has_many :users, through: :users_roles
|
||||
|
||||
belongs_to :resource,
|
||||
@@ -9,5 +16,8 @@ class Role < ApplicationRecord
|
||||
inclusion: {in: Rolify.resource_types},
|
||||
allow_nil: true
|
||||
|
||||
validates :name,
|
||||
inclusion: {in: ROLES.map(&:to_s)}
|
||||
|
||||
scopify
|
||||
end
|
||||
@@ -7,4 +7,9 @@ RSpec.describe Role do
|
||||
user.add_role :administrator
|
||||
expect(user.is_administrator?).to be true
|
||||
end
|
||||
|
||||
it "must be from the allowed list" do # rubocop:disable RSpec/MultipleExpectations
|
||||
expect { user.add_role :batman }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
expect(user.is_batman?).to be false
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user