Skip to content

Commit cc338f7

Browse files
authored
Merge pull request #78 from data-for-change/dev
Dev
2 parents 3133bd6 + f27ce02 commit cc338f7

6 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/components/organisms/RiskHotspotModel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const RiskHotspotModel = observer(() => {
3232
if (userStore.isLoading) {
3333
return <Loader />;
3434
}
35-
const hasPermission = userStore.isAuthenticated && userStore.hasEditPermission;
35+
const hasPermission = userStore.isAuthenticated && userStore.isHotSpotGrants;
3636

3737
if (hasPermission) {
3838
return (

src/components/templates/Header/Header.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ const Header: React.FC<IProps> = observer(({ title }) => {
8181
>
8282
{loginText}
8383
{isAuthenticated && user?.oauth_provider_user_picture_url ? (
84-
<img src={user?.oauth_provider_user_picture_url || ''}
85-
alt='user'
86-
style={{ width: 18, height: 18, borderRadius: '5%' }}
84+
<img
85+
src={user?.oauth_provider_user_picture_url || ''}
86+
alt='user'
87+
style={{ width: 18, height: 18, borderRadius: '50%' }}
8788
/>
8889
) : (
8990
<UserIcon />

src/components/templates/TabsTemplate.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useStore } from '../../stores/storeConfig';
88
import { useDispatch, useSelector } from 'react-redux';
99
import { AppDispatch, RootState } from '../../stores/store';
1010
import { setCurrentTab } from '../../stores';
11+
import { FeatureFlags, isFeatureEnabled } from '../../utils/featureFlags';
1112

1213
// import MapPage from '../../pages/MapPage';
1314
interface IProps {
@@ -19,7 +20,7 @@ const GroupByTablesPanel = lazy(() => import('../groupTable/GroupByTablesPanel')
1920
const MapAccidents = lazy(() => import('../map/AccidentsMap'));
2021
const AccidentsTable = lazy(() => import('../detailsTable/AccidentsTable'));
2122
const MyImageGallery = lazy(() => import('../organisms/MyImageGallery'));
22-
//const RiskHotspotModel = lazy(() => import('../organisms/RiskHotspotModel'));
23+
const RiskHotspotModel = lazy(() => import('../organisms/RiskHotspotModel'));
2324

2425
const styles = {
2526
tab: { marginTop: '0.5rem' },
@@ -86,7 +87,7 @@ export const TabsTemplate: FunctionComponent<IProps> = observer(({ type }) => {
8687
</Suspense>
8788
</ErrorBoundary>
8889
</Tab>
89-
{/* {isFeatureEnabled(FeatureFlags.RISK_MODEL) && (
90+
{isFeatureEnabled(FeatureFlags.RISK_MODEL) && (
9091
<Tab style={styles.tab} eventKey='riskModel' title={t('RiskModel')}>
9192
<ErrorBoundary>
9293
<Suspense fallback={<Loader />}>
@@ -96,7 +97,7 @@ export const TabsTemplate: FunctionComponent<IProps> = observer(({ type }) => {
9697
</Suspense>
9798
</ErrorBoundary>
9899
</Tab>
99-
)} */}
100+
)}
100101
</Tabs>
101102
);
102103
});

src/services/AuthService.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import axios, { AxiosResponse } from 'axios';
2-
import { API_URL } from '../utils/globalEnvs';
2+
import { API_ANYWAY_URL } from '../utils/globalEnvs';
33
import { IUserLoggedIn, IUser } from '../types/User';
44

55
class AuthService {
6-
apiUrl = API_URL;
6+
apiUrl = API_ANYWAY_URL;
77

88
// Safety Data session-based endpoints
99
isLoggedIn = async (): Promise<AxiosResponse<IUserLoggedIn>> => {
@@ -23,8 +23,11 @@ class AuthService {
2323
* Redirect the user to the authorization endpoint:
2424
* GET /sd-authorize/google
2525
*/
26-
getAuthorizeUrl = (redirectUrl?: string) => {
27-
const url = new URL(`${this.apiUrl}/sd-authorize/google?redirect_url=${redirectUrl}`);
26+
getAuthorizeUrl = (redirectUrl: string) => {
27+
const url = new URL(`${this.apiUrl}/sd-authorize/google`);
28+
if (redirectUrl) {
29+
url.searchParams.append('redirect_url', redirectUrl);
30+
}
2831
return url.toString();
2932
};
3033
}

src/stores/user/UserStore.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { makeAutoObservable, runInAction } from 'mobx';
22
import RootStore from '../RootStore';
33
import AuthService from '../../services/AuthService';
44
import { isFeatureEnabled, FeatureFlags } from '../../utils/featureFlags';
5-
import { IUser } from '../../types/User';
5+
import { EUserGrants, IUser } from '../../types/User';
66

77
export default class UserStore {
88
user: IUser | null = null;
@@ -151,11 +151,7 @@ export default class UserStore {
151151
return this.user?.roles?.includes('admins') || this.user?.role === 'admin';
152152
}
153153

154-
get isEditor() {
155-
return this.user?.roles?.includes('editor') || this.user?.role === 'editor';
156-
}
157-
158-
get hasEditPermission() {
159-
return this.isAdmin || this.isEditor;
154+
get isHotSpotGrants() {
155+
return this.user?.grants?.includes(EUserGrants.hot_spots_tab_grant);
160156
}
161157
}

src/types/User.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ export interface IUser {
2424
full_name: string | null;
2525
role: string | null;
2626
}
27+
28+
export enum EUserGrants {
29+
hot_spots_tab_grant = 'hot_spots_tab_grant',
30+
}

0 commit comments

Comments
 (0)