Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Intercept redirection to /settings/clients/limit-exceeded page #955

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/app/domain/limits/OauthClientsLimitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { navigate, navigationRef } from '/libs/RootNavigation'

const log = Minilog('⛔ OAuth Clients Limit Service')

export const OAUTH_CLIENTS_LIMIT_EXCEEDED_URL_PATH =
'/settings/clients/limit-exceeded'

export const OAUTH_CLIENTS_LIMIT_EXCEEDED = 'OAUTH_CLIENTS_LIMIT_EXCEEDED'

export const oauthClientLimitEventHandler = new EventEmitter()
Expand All @@ -26,6 +29,10 @@ export const showOauthClientsLimitExceeded = (href: string): void => {
oauthClientLimitEventHandler.emit(OAUTH_CLIENTS_LIMIT_EXCEEDED, href)
}

export const isOauthClientLimitExceededUrl = (url: string): boolean => {
return url.includes(OAUTH_CLIENTS_LIMIT_EXCEEDED_URL_PATH)
}

export const interceptNavigation =
(
initialUrl: string,
Expand Down
9 changes: 9 additions & 0 deletions src/app/domain/navigation/webviews/UrlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
previewFileFromDownloadUrl
} from '/libs/functions/filePreviewHelper'
import { safePromise } from '/utils/safePromise'
import {
isOauthClientLimitExceededUrl,
showOauthClientsLimitExceeded
} from '/app/domain/limits/OauthClientsLimitService'
import {
InterceptNavigationProps,
InterceptOpenWindowProps,
Expand Down Expand Up @@ -49,6 +53,11 @@ export const interceptNavigation = ({
client,
setDownloadProgress
}: InterceptNavigationProps): boolean => {
if (isOauthClientLimitExceededUrl(initialRequest.url)) {
showOauthClientsLimitExceeded(targetUri)
return false
}

const isPreviewableLink = checkIsPreviewableLink(initialRequest.url, client)
// We don't want to intecerpt iframe navigation excepts for iOS and the download
// Since we can download file from an iframe (intents)
Expand Down
3 changes: 1 addition & 2 deletions src/app/view/Limits/hooks/useOAuthClientsLimitExceeded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import Minilog from 'cozy-minilog'

import {
OAUTH_CLIENTS_LIMIT_EXCEEDED,
OAUTH_CLIENTS_LIMIT_EXCEEDED_URL_PATH,
interceptNavigation,
interceptOpenWindow,
oauthClientLimitEventHandler
} from '/app/domain/limits/OauthClientsLimitService'

const log = Minilog('⛔ OAuth Clients Limit Exceeded')

const OAUTH_CLIENTS_LIMIT_EXCEEDED_URL_PATH = '/settings/clients/limit-exceeded'

interface OAuthClientsLimitExceededState {
popupUrl: string | null
interceptNavigation: (request: WebViewNavigation) => boolean
Expand Down
Loading