mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
refactor(ui): move user-related settings out of "General Settings" (#1143)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { hasPermission } from '../../../server/lib/permissions';
|
||||
import { Permission, User } from '../../hooks/useUser';
|
||||
import useSettings from '../../hooks/useSettings';
|
||||
|
||||
export interface PermissionItem {
|
||||
id: string;
|
||||
@@ -33,6 +34,8 @@ const PermissionOption: React.FC<PermissionOptionProps> = ({
|
||||
onUpdate,
|
||||
parent,
|
||||
}) => {
|
||||
const settings = useSettings();
|
||||
|
||||
const autoApprovePermissions = [
|
||||
Permission.AUTO_APPROVE,
|
||||
Permission.AUTO_APPROVE_MOVIE,
|
||||
@@ -42,34 +45,70 @@ const PermissionOption: React.FC<PermissionOptionProps> = ({
|
||||
Permission.AUTO_APPROVE_4K_TV,
|
||||
];
|
||||
|
||||
let disabled = false;
|
||||
let checked = hasPermission(option.permission, currentPermission);
|
||||
|
||||
if (
|
||||
// Permissions for user ID 1 (Plex server owner) cannot be changed
|
||||
(currentUser && currentUser.id === 1) ||
|
||||
// Admin permission automatically bypasses/grants all other permissions
|
||||
(option.permission !== Permission.ADMIN &&
|
||||
hasPermission(Permission.ADMIN, currentPermission)) ||
|
||||
// Manage Requests permission automatically grants all Auto-Approve permissions
|
||||
(autoApprovePermissions.includes(option.permission) &&
|
||||
hasPermission(Permission.MANAGE_REQUESTS, currentPermission)) ||
|
||||
// Selecting a parent permission automatically selects all children
|
||||
(!!parent?.permission &&
|
||||
hasPermission(parent.permission, currentPermission))
|
||||
) {
|
||||
disabled = true;
|
||||
checked = true;
|
||||
}
|
||||
|
||||
if (
|
||||
// Non-Admin users cannot modify the Admin permission
|
||||
(actingUser &&
|
||||
!hasPermission(Permission.ADMIN, actingUser.permissions) &&
|
||||
option.permission === Permission.ADMIN) ||
|
||||
// Users without the Manage Settings permission cannot modify/grant that permission
|
||||
(actingUser &&
|
||||
!hasPermission(Permission.MANAGE_SETTINGS, actingUser.permissions) &&
|
||||
option.permission === Permission.MANAGE_SETTINGS)
|
||||
) {
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
if (
|
||||
// Some permissions are dependent on others; check requirements are fulfilled
|
||||
(option.requires &&
|
||||
!option.requires.every((requirement) =>
|
||||
hasPermission(requirement.permissions, currentPermission, {
|
||||
type: requirement.type ?? 'and',
|
||||
})
|
||||
)) ||
|
||||
// Request 4K and Auto-Approve 4K require both 4K movie & 4K series requests to be enabled
|
||||
((option.permission === Permission.REQUEST_4K ||
|
||||
option.permission === Permission.AUTO_APPROVE_4K) &&
|
||||
(!settings.currentSettings.movie4kEnabled ||
|
||||
!settings.currentSettings.series4kEnabled)) ||
|
||||
// Request 4K Movie and Auto-Approve 4K Movie require 4K movie requests to be enabled
|
||||
((option.permission === Permission.REQUEST_4K_MOVIE ||
|
||||
option.permission === Permission.AUTO_APPROVE_4K_MOVIE) &&
|
||||
!settings.currentSettings.movie4kEnabled) ||
|
||||
// Request 4K Series and Auto-Approve 4K Series require 4K series requests to be enabled
|
||||
((option.permission === Permission.REQUEST_4K_TV ||
|
||||
option.permission === Permission.AUTO_APPROVE_4K_TV) &&
|
||||
!settings.currentSettings.series4kEnabled)
|
||||
) {
|
||||
disabled = true;
|
||||
checked = false;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={`relative flex items-start first:mt-0 mt-4 ${
|
||||
(currentUser && currentUser.id === 1) ||
|
||||
(option.permission !== Permission.ADMIN &&
|
||||
hasPermission(Permission.ADMIN, currentPermission)) ||
|
||||
(autoApprovePermissions.includes(option.permission) &&
|
||||
hasPermission(Permission.MANAGE_REQUESTS, currentPermission)) ||
|
||||
(!!parent?.permission &&
|
||||
hasPermission(parent.permission, currentPermission)) ||
|
||||
(actingUser &&
|
||||
!hasPermission(Permission.ADMIN, actingUser.permissions) &&
|
||||
option.permission === Permission.ADMIN) ||
|
||||
(actingUser &&
|
||||
!hasPermission(
|
||||
Permission.MANAGE_SETTINGS,
|
||||
actingUser.permissions
|
||||
) &&
|
||||
option.permission === Permission.MANAGE_SETTINGS) ||
|
||||
(option.requires &&
|
||||
!option.requires.every((requirement) =>
|
||||
hasPermission(requirement.permissions, currentPermission, {
|
||||
type: requirement.type ?? 'and',
|
||||
})
|
||||
))
|
||||
? 'opacity-50'
|
||||
: ''
|
||||
disabled ? 'opacity-50' : ''
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center h-6">
|
||||
@@ -77,30 +116,7 @@ const PermissionOption: React.FC<PermissionOptionProps> = ({
|
||||
id={option.id}
|
||||
name="permissions"
|
||||
type="checkbox"
|
||||
disabled={
|
||||
(currentUser && currentUser.id === 1) ||
|
||||
(option.permission !== Permission.ADMIN &&
|
||||
hasPermission(Permission.ADMIN, currentPermission)) ||
|
||||
(autoApprovePermissions.includes(option.permission) &&
|
||||
hasPermission(Permission.MANAGE_REQUESTS, currentPermission)) ||
|
||||
(!!parent?.permission &&
|
||||
hasPermission(parent.permission, currentPermission)) ||
|
||||
(actingUser &&
|
||||
!hasPermission(Permission.ADMIN, actingUser.permissions) &&
|
||||
option.permission === Permission.ADMIN) ||
|
||||
(actingUser &&
|
||||
!hasPermission(
|
||||
Permission.MANAGE_SETTINGS,
|
||||
actingUser.permissions
|
||||
) &&
|
||||
option.permission === Permission.MANAGE_SETTINGS) ||
|
||||
(option.requires &&
|
||||
!option.requires.every((requirement) =>
|
||||
hasPermission(requirement.permissions, currentPermission, {
|
||||
type: requirement.type ?? 'and',
|
||||
})
|
||||
))
|
||||
}
|
||||
disabled={disabled}
|
||||
onChange={() => {
|
||||
onUpdate(
|
||||
hasPermission(option.permission, currentPermission)
|
||||
@@ -108,22 +124,7 @@ const PermissionOption: React.FC<PermissionOptionProps> = ({
|
||||
: currentPermission + option.permission
|
||||
);
|
||||
}}
|
||||
checked={
|
||||
(hasPermission(option.permission, currentPermission) ||
|
||||
(!!parent?.permission &&
|
||||
hasPermission(parent.permission, currentPermission)) ||
|
||||
(autoApprovePermissions.includes(option.permission) &&
|
||||
hasPermission(
|
||||
Permission.MANAGE_REQUESTS,
|
||||
currentPermission
|
||||
))) &&
|
||||
(!option.requires ||
|
||||
option.requires.every((requirement) =>
|
||||
hasPermission(requirement.permissions, currentPermission, {
|
||||
type: requirement.type ?? 'and',
|
||||
})
|
||||
))
|
||||
}
|
||||
checked={checked}
|
||||
/>
|
||||
</div>
|
||||
<div className="ml-3 text-sm leading-6">
|
||||
|
Reference in New Issue
Block a user