mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-10-29 14:54:36 +00:00
fix access conditionals
This commit is contained in:
1 parent
e35c422e89
commit
93df766eb5
3 files changed
+45
-11
No files matched your search
@@ -177,7 +177,11 @@ export const Navi = ({
|
||||
{naviTop.map((item) => {
|
||||
if (item.label === "Settings") {
|
||||
return (
|
||||
<ScopedAccess scope={Scope.service_provider} user={user}>
|
||||
<ScopedAccess
|
||||
key={item.label}
|
||||
scope={Scope.service_provider}
|
||||
user={user}
|
||||
>
|
||||
<Item
|
||||
key={item.label}
|
||||
item={item}
|
||||
@@ -202,7 +206,11 @@ export const Navi = ({
|
||||
}
|
||||
if (item.label === "Accounts") {
|
||||
return (
|
||||
<ScopedAccess scope={Scope.service_provider} user={user}>
|
||||
<ScopedAccess
|
||||
key={item.label}
|
||||
scope={Scope.service_provider}
|
||||
user={user}
|
||||
>
|
||||
<Item
|
||||
key={item.label}
|
||||
item={item}
|
||||
|
||||
@@ -602,6 +602,21 @@ export const CarrierForm = ({
|
||||
}
|
||||
}
|
||||
|
||||
const checkOptions = () => {
|
||||
if (user?.scope === USER_ACCOUNT) {
|
||||
if (carrier && carrier.data?.account_sid) {
|
||||
return false;
|
||||
}
|
||||
if (!carrier) {
|
||||
return false;
|
||||
}
|
||||
if (carrier && !carrier.data?.account_sid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
return (
|
||||
<Section slim>
|
||||
<form className="form form--internal" onSubmit={handleSubmit}>
|
||||
@@ -706,7 +721,8 @@ export const CarrierForm = ({
|
||||
account={[accountSid, setAccountSid]}
|
||||
label="Used By"
|
||||
required={false}
|
||||
defaultOption={user?.scope !== USER_ACCOUNT}
|
||||
defaultOption={checkOptions()}
|
||||
disabled={!!checkOptions()}
|
||||
/>
|
||||
{accountSid && hasLength(applications) && (
|
||||
<>
|
||||
|
||||
@@ -95,7 +95,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (user?.scope === USER_ACCOUNT && user.account_sid === accountSid) {
|
||||
if (user?.scope === USER_ACCOUNT && user.account_sid !== accountSid) {
|
||||
toastError(
|
||||
"You do not have permissions to make changes to these Speech Credentials"
|
||||
);
|
||||
@@ -105,12 +105,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
|
||||
if (currentServiceProvider) {
|
||||
const payload: Partial<SpeechCredential> = {
|
||||
vendor,
|
||||
account_sid:
|
||||
user?.scope === USER_ACCOUNT
|
||||
? user?.account_sid
|
||||
: accountSid
|
||||
? accountSid
|
||||
: null,
|
||||
account_sid: accountSid || null,
|
||||
service_provider_sid:
|
||||
currentServiceProvider.service_provider_sid || null,
|
||||
use_for_tts: ttsCheck ? 1 : 0,
|
||||
@@ -175,6 +170,21 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
|
||||
}
|
||||
};
|
||||
|
||||
const checkOptions = () => {
|
||||
if (user?.scope === USER_ACCOUNT) {
|
||||
if (credential && credential.data?.account_sid) {
|
||||
return false;
|
||||
}
|
||||
if (!credential) {
|
||||
return false;
|
||||
}
|
||||
if (credential && !credential.data?.account_sid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (credential && credential.data) {
|
||||
if (credential.data.vendor) {
|
||||
@@ -285,7 +295,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
|
||||
}
|
||||
account={[accountSid, setAccountSid]}
|
||||
required={false}
|
||||
defaultOption={user?.scope !== USER_ACCOUNT}
|
||||
defaultOption={checkOptions()}
|
||||
disabled={credential ? true : false}
|
||||
/>
|
||||
</fieldset>
|
||||
|
||||
Reference in new issue
Block a user