Skip to content

Tenant block list #2514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
55 changes: 50 additions & 5 deletions src/views/cipp/app-settings/components/SettingsCustomRoles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import {
import { Field, Form, FormSpy } from 'react-final-form'
import { RFFCFormRadioList, RFFSelectSearch } from 'src/components/forms'
import { useGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app'
import { CippPage } from 'src/components/layout'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import Skeleton from 'react-loading-skeleton'
import { TenantSelectorMultiple, ModalService, CippOffcanvas } from 'src/components/utilities'
import PropTypes from 'prop-types'
import { OnChange } from 'react-final-form-listeners'
import { useListTenantsQuery } from 'src/store/api/tenants'
import CippListOffcanvas, { OffcanvasListSection } from 'src/components/utilities/CippListOffcanvas'
import { OffcanvasListSection } from 'src/components/utilities/CippListOffcanvas'
import CippButtonCard from 'src/components/contentcards/CippButtonCard'

const SettingsCustomRoles = () => {
const [genericPostRequest, postResults] = useLazyGenericPostRequestQuery()
const [selectedTenant, setSelectedTenant] = useState([])
const [blockedTenants, setBlockedTenants] = useState([])
const tenantSelectorRef = useRef()
const blockedTenantSelectorRef = useRef()
const { data: tenants = [], tenantsFetching } = useListTenantsQuery({
showAllTenantSelector: true,
})
Expand Down Expand Up @@ -57,13 +57,21 @@ const SettingsCustomRoles = () => {
alltenant = true
}
})
if (alltenant) {
if (alltenant && blockedTenants.length === 0) {
setAllTenantSelected(true)
} else {
setAllTenantSelected(false)
}
setSelectedTenant(e)
}

const handleBlockedTenantChange = (e) => {
setBlockedTenants(e)
if (e.length > 0) {
setAllTenantSelected(false)
}
}

const handleSubmit = async (values) => {
//filter on only objects that are 'true'
genericPostRequest({
Expand All @@ -72,6 +80,7 @@ const SettingsCustomRoles = () => {
RoleName: values.RoleName.value,
Permissions: values.Permissions,
AllowedTenants: selectedTenant.map((tenant) => tenant.value),
BlockedTenants: blockedTenants.map((tenant) => tenant.value),
},
}).then(() => {
refetchCustomRoleList()
Expand Down Expand Up @@ -130,6 +139,19 @@ const SettingsCustomRoles = () => {
})

tenantSelectorRef.current.setValue(selectedTenants)
} else if (set === 'BlockedTenants') {
setBlockedTenants(customRole[0][set])
var blockedTenants = []
tenants.map((tenant) => {
if (customRole[0][set].includes(tenant.customerId)) {
blockedTenants.push({
label: tenant.displayName,
value: tenant.customerId,
})
}
})

blockedTenantSelectorRef.current.setValue(blockedTenants)
} else {
onChange(customRole[0][set])
}
Expand Down Expand Up @@ -277,6 +299,7 @@ const SettingsCustomRoles = () => {
/>
<WhenFieldChanges field="RoleName" set="Permissions" />
<WhenFieldChanges field="RoleName" set="AllowedTenants" />
<WhenFieldChanges field="RoleName" set="BlockedTenants" />
{cippApiRoleSelected && (
<CCallout color="info">
This role will limit access for the CIPP-API integration. It is not
Expand All @@ -299,6 +322,18 @@ const SettingsCustomRoles = () => {
</CCallout>
)}
</div>
{selectedTenant.find((tenant) => tenant.value === 'AllTenants') && (
<div className="mb-3">
<h5>Blocked Tenants</h5>
<TenantSelectorMultiple
ref={blockedTenantSelectorRef}
values={blockedTenants}
AllTenants={false}
valueIsDomain={true}
onChange={(e) => handleBlockedTenantChange(e)}
/>
</div>
)}
<h5>API Permissions</h5>
<CRow className="mt-4 px-2">
<CCol md={4}>
Expand Down Expand Up @@ -366,14 +401,24 @@ const SettingsCustomRoles = () => {
<>
{values['RoleName'] && selectedTenant.length > 0 && (
<>
<h5>Selected Tenants</h5>
<h5>Allowed Tenants</h5>
<ul>
{selectedTenant.map((tenant, idx) => (
<li key={idx}>{tenant.label}</li>
))}
</ul>
</>
)}
{values['RoleName'] && blockedTenants.length > 0 && (
<>
<h5>Blocked Tenants</h5>
<ul>
{blockedTenants.map((tenant, idx) => (
<li key={idx}>{tenant.label}</li>
))}
</ul>
</>
)}
{values['RoleName'] && values['Permissions'] && (
<>
<h5>Selected Permissions</h5>
Expand Down