Skip to content

Commit

Permalink
Add check for user authentication in NewsFlash (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaked-hayek committed Dec 26, 2023
1 parent f659f41 commit 72d2e3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/components/molecules/NewsFlashComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import LocationApprove from 'components/organisms/LocationApproveWindow';
import {locationQualificationOptions} from 'components/organisms/LocationApproveWindow';
import { INewsFlash } from 'models/NewFlash';
import {useParams} from 'react-router-dom'
import { observer } from "mobx-react-lite";

const ICON_HEIGHT = 18

Expand All @@ -38,7 +39,6 @@ const NewsFlashComp: FC<IProps> = ({ news }) => {
const locale = useLocale();
const { userStore, settingsStore } = store;
const { t } = useTranslation();
const userAllowedChange = userStore.isUserAuthenticated && userStore.isAdmin;

function getVerificationIcon(verificationText: string) {
if (verificationText === locationQualificationOptions.REJECTED) {
Expand All @@ -57,17 +57,19 @@ const NewsFlashComp: FC<IProps> = ({ news }) => {
const verificationIcon = getVerificationIcon(news.newsflash_location_qualification);
const criticalIcon = news.critical && <CriticalIcon className={classes.icon} />;
const {newsId} = useParams()
const newsID = newsId ? parseInt(newsId) : ''
const newsID = newsId ? parseInt(newsId) : ''

const className = news.id === newsID ? classes.activeNewsFlash : '';

const date = news.date == null ? '' : dateFormat(new Date(news.date.replace(/-/g, '/')), locale);
const handleLocationEditorOpen = () => setOpen(true);
const handleLocationEditorClose = () => setOpen(false);
const locationChangeButton = userAllowedChange &&

const locationChangeButton = userStore.isUserAdmin &&
<Button.Small onClick={handleLocationEditorOpen} buttonHeight={ICON_HEIGHT}>
{t('changeLocationButton')}
</Button.Small>

return (
<Link key={news.id} to={`${settingsStore.currentLanguageRouteString}/newsflash/${news.id}`}>
<Box border={1} borderColor={silverSmokeColor} p={1} className={className}>
Expand All @@ -84,8 +86,8 @@ const NewsFlashComp: FC<IProps> = ({ news }) => {
<LocationApprove isOpen={isOpen} onClose={handleLocationEditorClose}
newFlashTitle={date.concat(", ", news.display_source)} news={news} />
</Link>

);
}

export default NewsFlashComp;
export default observer(NewsFlashComp);
4 changes: 4 additions & 0 deletions src/store/user.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export default class UserStore {
return this.userInfo?.data.organizations;
}

get isUserAdmin(){
return this.isUserAuthenticated && this.isAdmin;
}

get usersManagementTableData(): any {
return this.usersInfoList?.map((user) => ({
name: `${user.first_name} ${user.last_name}`,
Expand Down

0 comments on commit 72d2e3f

Please sign in to comment.