Skip to content

Commit

Permalink
feat: implemented an ability to reject the authorisation opt-out flag
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Nov 8, 2023
1 parent 4dee74a commit b9f1929
Show file tree
Hide file tree
Showing 10 changed files with 537 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const tags = ['WorkspacePreferences'];
export function registerWorkspacePreferencesRoute(instance: FastifyInstance) {
instance.register(async server => {
server.get(
`${baseApiPath}/workspacepreferences/:namespace`,
`${baseApiPath}/workspacepreferences/namespace/:namespace`,
getSchema({ tags, params: namespacedSchema }),
async function (request: FastifyRequest) {
const { namespace } = request.params as restParams.INamespacedParams;
Expand All @@ -35,7 +35,7 @@ export function registerWorkspacePreferencesRoute(instance: FastifyInstance) {
);

server.delete(
`${baseApiPath}/workspacepreferences/:namespace/skip-authorisation/:provider`,
`${baseApiPath}/workspacepreferences/namespace/:namespace/skip-authorisation/:provider`,
getSchema({
tags,
params: namespacedWorkspacePreferencesSchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { api } from '@eclipse-che/common';
import { Tooltip, TooltipPosition } from '@patternfly/react-core';
import {
CheckCircleIcon,
ExclamationTriangleIcon,
ResourcesEmptyIcon,
} from '@patternfly/react-icons';
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';

import { AppState } from '@/store';
import * as GitOauthConfig from '@/store/GitOauthConfig';
import {
selectProvidersWithToken,
selectSkipOauthProviders,
} from '@/store/GitOauthConfig/selectors';

type State = {
hasOauthToken: boolean;
isSkipOauth: boolean;
};

type Props = MappedProps & {
gitProvider: api.GitOauthProvider;
};

export class ProviderIcon extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
const hasOauthToken = this.hasOauthToken(this.props.gitProvider);
const isSkipOauth = this.isSkipOauth(this.props.gitProvider);
this.state = {
hasOauthToken,
isSkipOauth,
};
}

public async componentDidMount(): Promise<void> {
const hasOauthToken = this.hasOauthToken(this.props.gitProvider);
const isSkipOauth = this.isSkipOauth(this.props.gitProvider);
this.setState({
hasOauthToken,
isSkipOauth,
});
}

public async componentDidUpdate(): Promise<void> {
const hasOauthToken = this.hasOauthToken(this.props.gitProvider);
const isSkipOauth = this.isSkipOauth(this.props.gitProvider);
this.setState({
hasOauthToken,
isSkipOauth,
});
}

private isSkipOauth(providerName: api.GitOauthProvider): boolean {
return this.props.skipOauthProviders.includes(providerName);
}

private hasOauthToken(providerName: api.GitOauthProvider): boolean {
return this.props.providersWithToken.includes(providerName);
}

public render(): React.ReactElement {
const { hasOauthToken, isSkipOauth } = this.state;
if (hasOauthToken) {
return (
<Tooltip
exitDelay={3000}
isContentLeftAligned={true}
position={TooltipPosition.right}
content={<span>Successfully authenticated.</span>}
style={{ border: '1px solid', borderRadius: '3px', opacity: '0.9' }}
>
<CheckCircleIcon
color="var(--pf-global--success-color--100)"
style={{ verticalAlign: 'text-top', marginTop: '2px' }}
/>
</Tooltip>
);
} else if (isSkipOauth) {
return (
<Tooltip
exitDelay={3000}
isContentLeftAligned={true}
position={TooltipPosition.right}
content={
<span>Authentication&nbsp;request&nbsp;has&nbsp;been rejected&nbsp;by&nbsp;user.</span>
}
style={{ border: '1px solid', borderRadius: '3px', opacity: '0.9' }}
>
<ExclamationTriangleIcon
color="var(--pf-global--warning-color--100)"
style={{ verticalAlign: 'text-top', marginTop: '2px' }}
/>
</Tooltip>
);
}

return (
<ResourcesEmptyIcon
color="var(--pf-global--disabled-color--100)"
style={{ verticalAlign: 'text-top', marginTop: '2px' }}
/>
);
}
}

const mapStateToProps = (state: AppState) => ({
providersWithToken: selectProvidersWithToken(state),
skipOauthProviders: selectSkipOauthProviders(state),
});

const connector = connect(mapStateToProps, GitOauthConfig.actionCreators);

type MappedProps = ConnectedProps<typeof connector>;
export default connector(ProviderIcon);
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,18 @@ exports[`GitServices should correctly render the component which contains four g
>
Server
</th>
<td
<th
className=""
data-key={3}
data-label="Authentication"
onMouseEnter={[Function]}
scope="col"
>
Authentication
</th>
<td
className=""
data-key={4}
data-label=""
onMouseEnter={[Function]}
scope={null}
Expand Down Expand Up @@ -170,8 +179,34 @@ exports[`GitServices should correctly render the component which contains four g
</a>
</td>
<td
className="pf-c-table__action"
className=""
data-key={3}
data-label="Authentication"
onMouseEnter={[Function]}
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="var(--pf-global--success-color--100)"
height="1em"
role="img"
style={
{
"marginTop": "2px",
"verticalAlign": "text-top",
}
}
viewBox="0 0 512 512"
width="1em"
>
<path
d="M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"
/>
</svg>
</td>
<td
className="pf-c-table__action"
data-key={4}
data-label={null}
onMouseEnter={[Function]}
style={
Expand Down Expand Up @@ -252,22 +287,6 @@ exports[`GitServices should correctly render the component which contains four g
onMouseEnter={[Function]}
>
GitLab
<span>
Provided API does not support the automatic token revocation. You can revoke it manually on  
<a
href="https://gitlab.dummy.endpoint.com"
rel="noreferrer"
style={
{
"color": "var(--pf-global--info-color--100)",
}
}
target="_blank"
>
https://gitlab.dummy.endpoint.com
</a>
.
</span>
</td>
<td
className=""
Expand All @@ -284,8 +303,34 @@ exports[`GitServices should correctly render the component which contains four g
</a>
</td>
<td
className="pf-c-table__action"
className=""
data-key={3}
data-label="Authentication"
onMouseEnter={[Function]}
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="var(--pf-global--disabled-color--100)"
height="1em"
role="img"
style={
{
"marginTop": "2px",
"verticalAlign": "text-top",
}
}
viewBox="0 0 1024 1024"
width="1em"
>
<path
d="M512,896 C300.2,896 128,723.9 128,512 C128,300.3 300.2,128 512,128 C723.7,128 896,300.2 896,512 C896,723.8 723.7,896 512,896 L512,896 Z M512.1,0 C229.7,0 0,229.8 0,512 C0,794.3 229.8,1024 512.1,1024 C794.4,1024 1024,794.3 1024,512 C1024,229.7 794.4,0 512.1,0 L512.1,0 Z"
/>
</svg>
</td>
<td
className="pf-c-table__action"
data-key={4}
data-label={null}
onMouseEnter={[Function]}
style={
Expand Down Expand Up @@ -366,22 +411,6 @@ exports[`GitServices should correctly render the component which contains four g
onMouseEnter={[Function]}
>
Bitbucket Server (OAuth 1.0)
<span>
Provided API does not support the automatic token revocation. You can revoke it manually on  
<a
href="https://bitbucket.dummy.endpoint.org"
rel="noreferrer"
style={
{
"color": "var(--pf-global--info-color--100)",
}
}
target="_blank"
>
https://bitbucket.dummy.endpoint.org
</a>
.
</span>
</td>
<td
className=""
Expand All @@ -398,8 +427,34 @@ exports[`GitServices should correctly render the component which contains four g
</a>
</td>
<td
className="pf-c-table__action"
className=""
data-key={3}
data-label="Authentication"
onMouseEnter={[Function]}
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="var(--pf-global--disabled-color--100)"
height="1em"
role="img"
style={
{
"marginTop": "2px",
"verticalAlign": "text-top",
}
}
viewBox="0 0 1024 1024"
width="1em"
>
<path
d="M512,896 C300.2,896 128,723.9 128,512 C128,300.3 300.2,128 512,128 C723.7,128 896,300.2 896,512 C896,723.8 723.7,896 512,896 L512,896 Z M512.1,0 C229.7,0 0,229.8 0,512 C0,794.3 229.8,1024 512.1,1024 C794.4,1024 1024,794.3 1024,512 C1024,229.7 794.4,0 512.1,0 L512.1,0 Z"
/>
</svg>
</td>
<td
className="pf-c-table__action"
data-key={4}
data-label={null}
onMouseEnter={[Function]}
style={
Expand Down Expand Up @@ -480,22 +535,6 @@ exports[`GitServices should correctly render the component which contains four g
onMouseEnter={[Function]}
>
Microsoft Azure DevOps
<span>
Provided API does not support the automatic token revocation. You can revoke it manually on  
<a
href="https://azure.dummy.endpoint.com/"
rel="noreferrer"
style={
{
"color": "var(--pf-global--info-color--100)",
}
}
target="_blank"
>
https://azure.dummy.endpoint.com/
</a>
.
</span>
</td>
<td
className=""
Expand All @@ -512,8 +551,34 @@ exports[`GitServices should correctly render the component which contains four g
</a>
</td>
<td
className="pf-c-table__action"
className=""
data-key={3}
data-label="Authentication"
onMouseEnter={[Function]}
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="var(--pf-global--disabled-color--100)"
height="1em"
role="img"
style={
{
"marginTop": "2px",
"verticalAlign": "text-top",
}
}
viewBox="0 0 1024 1024"
width="1em"
>
<path
d="M512,896 C300.2,896 128,723.9 128,512 C128,300.3 300.2,128 512,128 C723.7,128 896,300.2 896,512 C896,723.8 723.7,896 512,896 L512,896 Z M512.1,0 C229.7,0 0,229.8 0,512 C0,794.3 229.8,1024 512.1,1024 C794.4,1024 1024,794.3 1024,512 C1024,229.7 794.4,0 512.1,0 L512.1,0 Z"
/>
</svg>
</td>
<td
className="pf-c-table__action"
data-key={4}
data-label={null}
onMouseEnter={[Function]}
style={
Expand Down
Loading

0 comments on commit b9f1929

Please sign in to comment.