Skip to content
Snippets Groups Projects
Commit d2ce01e8 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Allow observers to preview data

parent b6c3e771
No related branches found
No related tags found
No related merge requests found
import React, { ReactElement, useEffect } from "react";
import React, { ReactElement, useEffect, useContext } from "react";
import { Container, Row } from "react-bootstrap";
import { Link } from "react-router-dom";
import OrganizationSidebar from "./sidebar/OrganizationSidebar";
import PageHeader from "../components/global/PageHeader"
......@@ -14,6 +15,7 @@ import ConnectedUsersSidebar from "./sidebar/ConnectedUsersSidebar";
import ServicesSidebar from "./sidebar/ServicesSidebar";
import DownloadContainer from "./download/DownloadContainer";
import useMatomo from "../matomo/UseMatomo";
import { PreviewContext } from "@/providers/PreviewProvider";
import { NrenAndYearDatapoint } from "../Schema";
......@@ -32,6 +34,7 @@ interface inputProps {
}
function DataPage({ title, description, filter, children, category, data, filename }: inputProps): ReactElement {
const { setPreview } = useContext(PreviewContext);
const preview = usePreview();
const locationWithoutPreview = window.location.origin + window.location.pathname;
......@@ -52,7 +55,7 @@ function DataPage({ title, description, filter, children, category, data, filena
{category === Sections.Services && <ServicesSidebar />}
<PageHeader type={'data'} />
{preview && <Row className="preview-banner">
<span>You are viewing a preview of the website which includes pre-published survey data. <a href={locationWithoutPreview}>Click here</a> to deactivate preview mode.</span>
<span>You are viewing a preview of the website which includes pre-published survey data. <Link to={locationWithoutPreview} onClick={() => setPreview(false)}>Click here</Link> to deactivate preview mode.</span>
</Row>}
<SectionNavigation activeCategory={category} />
<Container className="mb-5 grow">
......
......
import React, { ReactElement, useContext } from "react";
import { Link } from "react-router-dom";
import { useLocation } from "react-router-dom";
import { Col, Container, Row } from "react-bootstrap";
import GeantLogo from "../../images/geant_logo_f2020_new.svg";
......@@ -30,7 +31,7 @@ function ExternalPageNavBar(): ReactElement {
<li><a className="nav-link-entry" href="https://about.geant.org/">ABOUT</a></li>
<li><a className="nav-link-entry" href="https://connect.geant.org/community-news">NEWS</a></li>
<li><a className="nav-link-entry" href="https://resources.geant.org/">RESOURCES</a></li>
<li><a className="nav-link-entry" href="/">COMPENDIUM</a></li>
<li><Link className="nav-link-entry" to="/">COMPENDIUM</Link></li>
</ul>
</nav>
......@@ -38,7 +39,7 @@ function ExternalPageNavBar(): ReactElement {
</Col>
<Col xs={2}>
{user.permissions.admin && !pathname.includes('survey') && <div className='nav-link' style={{ float: 'right' }}><a className='nav-link-entry' href="/survey">Go to Survey</a></div>}
{user.permissions.admin && !pathname.includes('survey') && <div className='nav-link' style={{ float: 'right' }}><Link className='nav-link-entry' to="/survey"><span>Go to Survey</span></Link></div>}
</Col>
</Row>
</Container>
......
......
......@@ -79,6 +79,10 @@ class User(UserMixin, db.Model):
def is_observer(self):
return self.roles == ROLES.observer
@property
def can_preview(self):
return self.roles in [ROLES.admin, ROLES.observer]
@property
def nren(self):
if len(self.nrens) == 0:
......
......
......@@ -21,8 +21,8 @@ def get_data(table_class: Type[T]) -> Sequence[T]:
return list(chain(*data))
select_statement = select(table_class).join(NREN).order_by(NREN.name.asc(), table_class.year.asc())
is_admin = (not current_user.is_anonymous) and current_user.is_admin
preview = is_admin and request.args.get('preview') is not None
can_preview = (not current_user.is_anonymous) and current_user.can_preview
preview = can_preview and request.args.get('preview') is not None
if not preview:
select_statement = select_statement.where(table_class.year.not_in(select(PreviewYear.year)))
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment