Skip to content

Commit

Permalink
Merge pull request #2817 from JohnDuprey/dev
Browse files Browse the repository at this point in the history
Permission Builder tweaks
  • Loading branch information
JohnDuprey authored Aug 14, 2024
2 parents 7298c05 + f22f756 commit dbb45bc
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 6 deletions.
94 changes: 92 additions & 2 deletions src/components/utilities/CippAppPermissionBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@coreui/react'
import { Field, Form, FormSpy } from 'react-final-form'
import { RFFCFormRadioList, RFFSelectSearch } from 'src/components/forms'
import { useGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app'
import { useGenericGetRequestQuery, useLazyGenericGetRequestQuery } from 'src/store/api/app'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
TenantSelectorMultiple,
Expand Down Expand Up @@ -53,6 +53,8 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
path: 'api/ExecServicePrincipals',
})

const [createServicePrincipal, createResult] = useLazyGenericGetRequestQuery()

const removeServicePrincipal = (appId) => {
var servicePrincipal = selectedApp.find((sp) => sp?.appId === appId)
var newServicePrincipals = selectedApp.filter((sp) => sp?.appId !== appId)
Expand Down Expand Up @@ -91,6 +93,15 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
}
}

const onCreateServicePrincipal = (appId) => {
createServicePrincipal({
path: 'api/ExecServicePrincipals?Action=Create&AppId=' + appId,
}).then(() => {
refetchSpList()
setCalloutMessage(createResult?.data?.Results)
})
}

const addPermissionRow = (servicePrincipal, permissionType, permission) => {
var updatedPermissions = JSON.parse(JSON.stringify(newPermissions))

Expand Down Expand Up @@ -683,7 +694,7 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
refreshFunction={() => refetchSpList()}
allowCreate={true}
onCreateOption={(newSp) => {
console.log(newSp)
onCreateServicePrincipal(newSp)
}}
placeholder="(Advanced) Select a Service Principal"
/>
Expand Down Expand Up @@ -810,6 +821,85 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
</CCol>
</CRow>
)}

{newPermissions?.MissingPermissions &&
newPermissions?.Type === 'Table' &&
Object.keys(newPermissions?.MissingPermissions).length > 0 && (
<CRow>
<CCol>
<CCallout color="warning">
<CRow>
<CCol xl={10} sm={12}>
<FontAwesomeIcon icon="exclamation-triangle" className="me-2" />
<b>New Permissions Available</b>
{Object.keys(newPermissions?.MissingPermissions).map((perm) => {
// translate appid to display name
var sp = servicePrincipals?.Results?.find(
(sp) => sp.appId === perm,
)
return (
<div key={`missing-${perm}`}>
{sp?.displayName}:{' '}
{Object.keys(newPermissions?.MissingPermissions[perm]).map(
(type) => {
return (
<>
{newPermissions?.MissingPermissions[perm][type]
.length > 0 && (
<span key={`missing-${perm}-${type}`}>
{type == 'applicationPermissions'
? 'Application'
: 'Delegated'}{' '}
-{' '}
{newPermissions?.MissingPermissions[perm][type]
.map((p) => {
return p.value
})
.join(', ')}
</span>
)}
</>
)
},
)}
</div>
)
})}
</CCol>
<CCol xl={2} sm={12} className="my-auto">
<CTooltip content="Add Missing Permissions">
<CButton
onClick={() => {
var updatedPermissions = JSON.parse(
JSON.stringify(newPermissions),
)
Object.keys(newPermissions?.MissingPermissions).map(
(perm) => {
Object.keys(
newPermissions?.MissingPermissions[perm],
).map((type) => {
newPermissions?.MissingPermissions[perm][type].map(
(p) => {
updatedPermissions.Permissions[perm][type].push(p)
},
)
})
},
)
updatedPermissions.MissingPermissions = {}
setNewPermissions(updatedPermissions)
}}
className={`circular-button float-end`}
>
<FontAwesomeIcon icon="wrench" />
</CButton>
</CTooltip>
</CCol>
</CRow>
</CCallout>
</CCol>
</CRow>
)}
<CAccordion>
<>
{selectedApp?.length > 0 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ const SettingsAppPermissions = () => {
genericPostRequest({
path: 'api/ExecSAMAppPermissions?Action=Update',
values: values,
}).then(() => {
refetchSam()
})
}

const { data: samAppPermissions = [], isFetching: samAppPermissionsFetching } =
useGenericGetRequestQuery({
path: 'api/ExecSAMAppPermissions',
})
const {
data: samAppPermissions = [],
isFetching: samAppPermissionsFetching,
refetch: refetchSam,
} = useGenericGetRequestQuery({
path: 'api/ExecSAMAppPermissions',
})

return (
<CippButtonCard title="CIPP-SAM API Permissions" titleType="big">
Expand Down

0 comments on commit dbb45bc

Please sign in to comment.