forked from External/greenlight
GRN2-176: Create a role editor that allows admins to specify what permissions each role has (#709)
* Add roles editor * Add colour selection ability to roles * Add ability to assign roles to users in the UI * Remove rolify and replace it with our own custom roles implemenation * - Fix all existing roles functionality - Fix super admins * Fix bugs with new customers not have default roles * Add can't create room setting * Code improvements * Fix migration * Add tests for new methods * Translate reserved role names * Pull roles from saml/ldap * Fix rspec * Fix scrutinizer issues * Fix email promoted/demoted tests * Apply comments * Redirect directly to the main room * Add comments
This commit is contained in:
committed by
Jesus Federico
parent
02b342b157
commit
4fc1714db8
35
spec/models/role_spec.rb
Normal file
35
spec/models/role_spec.rb
Normal file
@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
|
||||
#
|
||||
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Lesser General Public License as published by the Free Software
|
||||
# Foundation; either version 3.0 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License along
|
||||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Role, type: :model do
|
||||
it "should return duplicate if role name is in reserved role names" do
|
||||
expect(Role.duplicate_name("admin", "greenlight")).to eq(true)
|
||||
end
|
||||
|
||||
it "should return duplicate if role name matched another" do
|
||||
Role.create(name: "test", provider: "greenlight")
|
||||
expect(Role.duplicate_name("test", "greenlight")).to eq(true)
|
||||
end
|
||||
|
||||
it "should return false role name doesn't exist" do
|
||||
Role.create(name: "test", provider: "greenlight")
|
||||
expect(Role.duplicate_name("test1", "greenlight")).to eq(false)
|
||||
end
|
||||
end
|
@ -158,6 +158,72 @@ describe User, type: :model do
|
||||
|
||||
expect(@admin.admin_of?(@user)).to be false
|
||||
end
|
||||
|
||||
it "should get the highest priority role" do
|
||||
@admin = create(:user, provider: @user.provider)
|
||||
@admin.add_role :admin
|
||||
|
||||
expect(@admin.highest_priority_role.name).to eq("admin")
|
||||
end
|
||||
|
||||
it "should skip adding the role if the user already has the role" do
|
||||
@admin = create(:user, provider: @user.provider)
|
||||
@admin.add_role :admin
|
||||
@admin.add_role :admin
|
||||
|
||||
expect(@admin.roles.count).to eq(2)
|
||||
end
|
||||
|
||||
it "should add the role if the user doesn't already have the role" do
|
||||
@admin = create(:user, provider: @user.provider)
|
||||
@admin.add_role :admin
|
||||
|
||||
expect(@admin.roles.count).to eq(2)
|
||||
end
|
||||
|
||||
it "should remove the role if the user has the role assigned to them" do
|
||||
@admin = create(:user, provider: @user.provider)
|
||||
@admin.add_role :admin
|
||||
@admin.remove_role :admin
|
||||
|
||||
expect(@admin.roles.count).to eq(1)
|
||||
end
|
||||
|
||||
it "has_role? should return false if the user doesn't have the role" do
|
||||
expect(@user.has_role?(:admin)).to eq(false)
|
||||
end
|
||||
|
||||
it "has_role? should return true if the user has the role" do
|
||||
@admin = create(:user, provider: @user.provider)
|
||||
@admin.add_role :admin
|
||||
|
||||
expect(@admin.has_role?(:admin)).to eq(true)
|
||||
end
|
||||
|
||||
it "with_role should return all users with the role" do
|
||||
@admin1 = create(:user, provider: @user.provider)
|
||||
@admin2 = create(:user, provider: @user.provider)
|
||||
@admin1.add_role :admin
|
||||
@admin2.add_role :admin
|
||||
|
||||
expect(User.with_role(:admin).count).to eq(2)
|
||||
end
|
||||
|
||||
it "without_role should return all users without the role" do
|
||||
@admin1 = create(:user, provider: @user.provider)
|
||||
@admin2 = create(:user, provider: @user.provider)
|
||||
@admin1.add_role :admin
|
||||
@admin2.add_role :admin
|
||||
|
||||
expect(User.without_role(:admin).count).to eq(1)
|
||||
end
|
||||
|
||||
it "all_users_with_roles should return all users with at least one role" do
|
||||
@admin1 = create(:user, provider: @user.provider)
|
||||
@admin2 = create(:user, provider: @user.provider)
|
||||
|
||||
expect(User.all_users_with_roles.count).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
context 'blank email' do
|
||||
|
Reference in New Issue
Block a user