mirror of
https://github.com/Sevichecc/m-oauth.git
synced 2025-04-30 06:59:29 +08:00
feat: add admin read all and write all scopes
This commit is contained in:
parent
7efd707860
commit
86661e518a
2 changed files with 22 additions and 4 deletions
|
@ -10,12 +10,24 @@ interface ScopeCheckboxProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ScopeItem: React.FC<ScopeCheckboxProps> = ({ scope, method, field }) => {
|
const ScopeItem: React.FC<ScopeCheckboxProps> = ({ scope, method, field }) => {
|
||||||
|
const scopes = scope.split(":");
|
||||||
|
const adminIsReadAll =
|
||||||
|
field.value?.includes("admin:read") &&
|
||||||
|
method === "admin" &&
|
||||||
|
scopes[1] === "read" &&
|
||||||
|
scopes.length !== 2;
|
||||||
|
const adminIsWriteAll =
|
||||||
|
field.value?.includes("admin:write") &&
|
||||||
|
method === "admin" &&
|
||||||
|
scopes[1] === "write" &&
|
||||||
|
scopes.length !== 2;
|
||||||
|
|
||||||
const isCovered = field.value?.includes(method);
|
const isCovered = field.value?.includes(method);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="items-top 'hover:cursor-pointer flex space-x-2 hover:cursor-pointer">
|
<div className="items-top 'hover:cursor-pointer flex space-x-2 hover:cursor-pointer">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
disabled={isCovered}
|
disabled={isCovered || adminIsReadAll || adminIsWriteAll}
|
||||||
id={scope}
|
id={scope}
|
||||||
checked={field.value?.includes(scope)}
|
checked={field.value?.includes(scope)}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
|
@ -37,10 +49,14 @@ const ScopeItem: React.FC<ScopeCheckboxProps> = ({ scope, method, field }) => {
|
||||||
: "hover:cursor-pointer"
|
: "hover:cursor-pointer"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{method == "admin" && (
|
{method === "admin" && (
|
||||||
<span className="text-slate-500">{scope.split(":")[1]} : </span>
|
<span className="text-slate-500">{scopes[1]} : </span>
|
||||||
|
)}
|
||||||
|
{scope === "admin:read" || scope === "admin:write" ? (
|
||||||
|
<span className="text-slate-500">All </span>
|
||||||
|
) : (
|
||||||
|
scopes.slice(-1)
|
||||||
)}
|
)}
|
||||||
{scope.split(":").slice(-1)}
|
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -30,6 +30,7 @@ export const WRITE_SCOPES = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ADMIN_READ_SCOPES = [
|
export const ADMIN_READ_SCOPES = [
|
||||||
|
"admin:read",
|
||||||
"admin:read:account",
|
"admin:read:account",
|
||||||
"admin:read:reports",
|
"admin:read:reports",
|
||||||
"admin:read:domain_allows",
|
"admin:read:domain_allows",
|
||||||
|
@ -40,6 +41,7 @@ export const ADMIN_READ_SCOPES = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ADMIN_WRITE_SCOPES = [
|
export const ADMIN_WRITE_SCOPES = [
|
||||||
|
"admin:write",
|
||||||
"admin:write:account",
|
"admin:write:account",
|
||||||
"admin:write:reports",
|
"admin:write:reports",
|
||||||
"admin:write:domain_allows",
|
"admin:write:domain_allows",
|
||||||
|
|
Loading…
Reference in a new issue