mirror of
https://github.com/sct/overseerr.git
synced 2025-12-30 17:49:17 +01:00
feat: disable plex login if owner doesnt have plex linked
This commit is contained in:
@@ -37,6 +37,7 @@ export interface PublicSettingsResponse {
|
||||
locale: string;
|
||||
emailEnabled: boolean;
|
||||
newPlexLogin: boolean;
|
||||
plexLoginEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface CacheItem {
|
||||
|
||||
@@ -110,7 +110,7 @@ interface PublicSettings {
|
||||
initialized: boolean;
|
||||
}
|
||||
|
||||
interface FullPublicSettings extends PublicSettings {
|
||||
export interface FullPublicSettings extends PublicSettings {
|
||||
applicationTitle: string;
|
||||
applicationUrl: string;
|
||||
hideAvailable: boolean;
|
||||
@@ -126,6 +126,7 @@ interface FullPublicSettings extends PublicSettings {
|
||||
locale: string;
|
||||
emailEnabled: boolean;
|
||||
newPlexLogin: boolean;
|
||||
plexLoginEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface NotificationAgentConfig {
|
||||
@@ -512,6 +513,7 @@ class Settings {
|
||||
locale: this.data.main.locale,
|
||||
emailEnabled: this.data.notifications.agents.email.enabled,
|
||||
newPlexLogin: this.data.main.newPlexLogin,
|
||||
plexLoginEnabled: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@ import type {
|
||||
} from '@server/api/themoviedb/interfaces';
|
||||
import { getRepository } from '@server/datasource';
|
||||
import DiscoverSlider from '@server/entity/DiscoverSlider';
|
||||
import { User } from '@server/entity/User';
|
||||
import type { StatusResponse } from '@server/interfaces/api/settingsInterfaces';
|
||||
import { Permission } from '@server/lib/permissions';
|
||||
import { getSettings } from '@server/lib/settings';
|
||||
import { getSettings, type FullPublicSettings } from '@server/lib/settings';
|
||||
import logger from '@server/logger';
|
||||
import { checkUser, isAuthenticated } from '@server/middleware/auth';
|
||||
import { mapWatchProviderDetails } from '@server/models/common';
|
||||
@@ -95,16 +96,23 @@ router.get('/status/appdata', (_req, res) => {
|
||||
});
|
||||
|
||||
router.use('/user', isAuthenticated(), user);
|
||||
router.get('/settings/public', async (req, res) => {
|
||||
router.get<never, FullPublicSettings>('/settings/public', async (req, res) => {
|
||||
const settings = getSettings();
|
||||
const userRepository = getRepository(User);
|
||||
|
||||
const fullPublicSettings: FullPublicSettings = settings.fullPublicSettings;
|
||||
|
||||
if (!(req.user?.settings?.notificationTypes.webpush ?? true)) {
|
||||
return res
|
||||
.status(200)
|
||||
.json({ ...settings.fullPublicSettings, enablePushRegistration: false });
|
||||
} else {
|
||||
return res.status(200).json(settings.fullPublicSettings);
|
||||
fullPublicSettings.enablePushRegistration = false;
|
||||
}
|
||||
|
||||
const admin = await userRepository.findOneBy({ id: 1 });
|
||||
|
||||
if (admin && admin.plexId) {
|
||||
fullPublicSettings.plexLoginEnabled = true;
|
||||
}
|
||||
|
||||
return res.status(200).json(fullPublicSettings);
|
||||
});
|
||||
router.get('/settings/discover', isAuthenticated(), async (_req, res) => {
|
||||
const sliderRepository = getRepository(DiscoverSlider);
|
||||
|
||||
@@ -26,7 +26,7 @@ const Login = () => {
|
||||
const [error, setError] = useState('');
|
||||
const [isProcessing, setProcessing] = useState(false);
|
||||
const [authToken, setAuthToken] = useState<string | undefined>(undefined);
|
||||
const { user, revalidate } = useUser();
|
||||
const { revalidate } = useUser();
|
||||
const router = useRouter();
|
||||
const settings = useSettings();
|
||||
|
||||
@@ -40,7 +40,11 @@ const Login = () => {
|
||||
const response = await axios.post('/api/v1/auth/plex', { authToken });
|
||||
|
||||
if (response.data?.id) {
|
||||
revalidate();
|
||||
const user = await revalidate();
|
||||
|
||||
if (user) {
|
||||
router.push('/');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e.response.data.message);
|
||||
@@ -51,15 +55,7 @@ const Login = () => {
|
||||
if (authToken) {
|
||||
login();
|
||||
}
|
||||
}, [authToken, revalidate]);
|
||||
|
||||
// Effect that is triggered whenever `useUser`'s user changes. If we get a new
|
||||
// valid user, we redirect the user to the home page as the login was successful.
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
router.push('/');
|
||||
}
|
||||
}, [user, router]);
|
||||
}, [authToken, revalidate, router]);
|
||||
|
||||
const { data: backdrops } = useSWR<string[]>('/api/v1/backdrops', {
|
||||
refreshInterval: 0,
|
||||
@@ -118,26 +114,30 @@ const Login = () => {
|
||||
<Accordion single atLeastOne>
|
||||
{({ openIndexes, handleClick, AccordionContent }) => (
|
||||
<>
|
||||
<button
|
||||
className={`w-full cursor-default bg-gray-800 bg-opacity-70 py-2 text-center text-sm font-bold text-gray-400 transition-colors duration-200 focus:outline-none sm:rounded-t-lg ${
|
||||
openIndexes.includes(0) && 'text-indigo-500'
|
||||
} ${
|
||||
settings.currentSettings.localLogin &&
|
||||
'hover:cursor-pointer hover:bg-gray-700'
|
||||
}`}
|
||||
onClick={() => handleClick(0)}
|
||||
disabled={!settings.currentSettings.localLogin}
|
||||
>
|
||||
{intl.formatMessage(messages.signinwithplex)}
|
||||
</button>
|
||||
<AccordionContent isOpen={openIndexes.includes(0)}>
|
||||
<div className="px-10 py-8">
|
||||
<PlexLoginButton
|
||||
isProcessing={isProcessing}
|
||||
onAuthToken={(authToken) => setAuthToken(authToken)}
|
||||
/>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
{settings.currentSettings.plexLoginEnabled && (
|
||||
<>
|
||||
<button
|
||||
className={`w-full cursor-default bg-gray-800 bg-opacity-70 py-2 text-center text-sm font-bold text-gray-400 transition-colors duration-200 focus:outline-none sm:rounded-t-lg ${
|
||||
openIndexes.includes(0) && 'text-indigo-500'
|
||||
} ${
|
||||
settings.currentSettings.localLogin &&
|
||||
'hover:cursor-pointer hover:bg-gray-700'
|
||||
}`}
|
||||
onClick={() => handleClick(0)}
|
||||
disabled={!settings.currentSettings.localLogin}
|
||||
>
|
||||
{intl.formatMessage(messages.signinwithplex)}
|
||||
</button>
|
||||
<AccordionContent isOpen={openIndexes.includes(0)}>
|
||||
<div className="px-10 py-8">
|
||||
<PlexLoginButton
|
||||
isProcessing={isProcessing}
|
||||
onAuthToken={(authToken) => setAuthToken(authToken)}
|
||||
/>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</>
|
||||
)}
|
||||
{settings.currentSettings.localLogin && (
|
||||
<div>
|
||||
<button
|
||||
|
||||
@@ -213,7 +213,11 @@ const UserGeneralSettings = () => {
|
||||
</label>
|
||||
<div className="flex items-center rounded sm:col-span-2">
|
||||
<div className="mr-4 flex h-7 w-7 items-center justify-center rounded-full border border-gray-700 bg-gray-800">
|
||||
<CheckCircleIcon className="w-full text-green-500" />
|
||||
<CheckCircleIcon
|
||||
className={`w-full ${
|
||||
user?.isPlexUser ? 'text-green-500' : 'text-gray-700'
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
<PlexLogo className="h-8 border-r border-gray-700 pr-4" />
|
||||
{!user?.isPlexUser ? (
|
||||
@@ -223,6 +227,7 @@ const UserGeneralSettings = () => {
|
||||
onComplete={() => {
|
||||
revalidateUser();
|
||||
}}
|
||||
textOverride="Connect Plex Account"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -24,6 +24,7 @@ const defaultSettings = {
|
||||
locale: 'en',
|
||||
emailEnabled: false,
|
||||
newPlexLogin: true,
|
||||
plexLoginEnabled: false,
|
||||
};
|
||||
|
||||
export const SettingsContext = React.createContext<SettingsContextProps>({
|
||||
|
||||
@@ -9,7 +9,7 @@ export type { PermissionCheckOptions };
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
plexUsername?: string;
|
||||
plexUsername?: string | null;
|
||||
username?: string;
|
||||
displayName: string;
|
||||
email: string;
|
||||
|
||||
@@ -228,6 +228,7 @@ CoreApp.getInitialProps = async (initialProps) => {
|
||||
locale: 'en',
|
||||
emailEnabled: false,
|
||||
newPlexLogin: true,
|
||||
plexLoginEnabled: false,
|
||||
};
|
||||
|
||||
if (ctx.res) {
|
||||
|
||||
Reference in New Issue
Block a user