[NEW] [ENTERPRISE] Restrict the permissions configuration for guest users (#17333)
Co-authored-by: Diego Sampaio <chinello@gmail.com>pull/17378/head
parent
f1d1951633
commit
0a769744d5
@ -0,0 +1,10 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
export const AuthorizationUtils = class { |
||||
static isRoleReadOnly(roleId: string): boolean { |
||||
if (!roleId) { |
||||
throw new Meteor.Error('invalid-param'); |
||||
} |
||||
return false; |
||||
} |
||||
}; |
||||
@ -0,0 +1,10 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
export const AuthorizationUtils = class { |
||||
static isRoleReadOnly(roleId: string): boolean { |
||||
if (!roleId) { |
||||
throw new Meteor.Error('invalid-param'); |
||||
} |
||||
return false; |
||||
} |
||||
}; |
||||
@ -0,0 +1,12 @@ |
||||
import { AuthorizationUtils } from '../../../../app/authorization/client/lib/AuthorizationUtils'; |
||||
import { isEnterprise } from '../../license/client'; |
||||
|
||||
const { isRoleReadOnly: oldIsRoleReadOnly } = AuthorizationUtils; |
||||
|
||||
AuthorizationUtils.isRoleReadOnly = function(roleId: string): boolean { |
||||
if (isEnterprise() && roleId === 'guest') { |
||||
return true; |
||||
} |
||||
|
||||
return oldIsRoleReadOnly(roleId); |
||||
}; |
||||
@ -0,0 +1 @@ |
||||
import './AuthorizationUtils'; |
||||
@ -0,0 +1,12 @@ |
||||
import { AuthorizationUtils } from '../../../../app/authorization/server/lib/AuthorizationUtils'; |
||||
import { isEnterprise } from '../../license/server'; |
||||
|
||||
const { isRoleReadOnly: oldIsRoleReadOnly } = AuthorizationUtils; |
||||
|
||||
AuthorizationUtils.isRoleReadOnly = function(roleId: string): boolean { |
||||
if (isEnterprise() && roleId === 'guest') { |
||||
return true; |
||||
} |
||||
|
||||
return oldIsRoleReadOnly(roleId); |
||||
}; |
||||
@ -0,0 +1 @@ |
||||
import './AuthorizationUtils'; |
||||
@ -0,0 +1,29 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { isEnterprise, getMaxGuestUsers } from '../../license/server'; |
||||
import { Users } from '../../../../app/models/server'; |
||||
|
||||
export const validateUserRoles = function(userId, userData) { |
||||
if (!isEnterprise()) { |
||||
return; |
||||
} |
||||
|
||||
if (!userData.roles.includes('guest')) { |
||||
return; |
||||
} |
||||
|
||||
if (userData.roles.length >= 2) { |
||||
throw new Meteor.Error('error-guests-cant-have-other-roles', "Guest users can't receive any other role", { |
||||
method: 'insertOrUpdateUser', |
||||
field: 'Assign_role', |
||||
}); |
||||
} |
||||
|
||||
const guestCount = Users.getActiveLocalGuestCount(userData._id); |
||||
if (guestCount >= getMaxGuestUsers()) { |
||||
throw new Meteor.Error('error-max-guests-number-reached', 'Maximum number of guests reached.', { |
||||
method: 'insertOrUpdateUser', |
||||
field: 'Assign_role', |
||||
}); |
||||
} |
||||
}; |
||||
@ -0,0 +1,16 @@ |
||||
import { Migrations } from '../../../app/migrations/server'; |
||||
import { Permissions } from '../../../app/models/server'; |
||||
|
||||
const newRolePermissions = [ |
||||
'view-d-room', |
||||
'view-p-room', |
||||
]; |
||||
|
||||
const roleName = 'guest'; |
||||
|
||||
Migrations.add({ |
||||
version: 188, |
||||
up() { |
||||
Permissions.update({ _id: { $in: newRolePermissions } }, { $addToSet: { roles: roleName } }, { multi: true }); |
||||
}, |
||||
}); |
||||
Loading…
Reference in new issue