Skip to content

Commit

Permalink
fix: hardcode isPublic value to True #329
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Feb 14, 2022
1 parent 8d0496d commit 64f62c2
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions datagateway_api/src/search_api/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from abc import ABC, abstractmethod
from datetime import datetime, timezone
from datetime import datetime
import sys
from typing import ClassVar, List, Optional, Union

from dateutil.relativedelta import relativedelta
from pydantic import BaseModel, Field, ValidationError, validator
from pydantic import BaseModel, Field, root_validator, ValidationError, validator
from pydantic.error_wrappers import ErrorWrapper

from datagateway_api.src.common.config import Config
from datagateway_api.src.common.date_handler import DateHandler
from datagateway_api.src.search_api.panosc_mappings import mappings


Expand Down Expand Up @@ -195,17 +192,12 @@ class Dataset(PaNOSCAttribute):
def set_pid(cls, value): # noqa: B902, N805
return f"pid:{value}" if isinstance(value, int) else value

@validator("is_public", pre=True, always=True)
def set_is_public(cls, value): # noqa: B902, N805
if not value:
return value

creation_date = DateHandler.str_to_datetime_object(value)
current_datetime = datetime.now(timezone.utc)
rd = relativedelta(
years=Config.config.search_api.num_of_years_determining_public_data,
)
return creation_date < (current_datetime - rd)
@root_validator(pre=True)
def set_is_public(cls, values): # noqa: B902, N805
# Hardcoding this to True because anon user is used for querying so all data
# returned by it is public
values["isPublic"] = True
return values

@classmethod
def from_icat(cls, icat_data, required_related_fields):
Expand Down Expand Up @@ -240,17 +232,12 @@ class Document(PaNOSCAttribute):
def set_pid(cls, value): # noqa: B902, N805
return f"pid:{value}" if isinstance(value, int) else value

@validator("is_public", pre=True, always=True)
def set_is_public(cls, value): # noqa: B902, N805
if not value:
return value

creation_date = DateHandler.str_to_datetime_object(value)
current_datetime = datetime.now(timezone.utc)
rd = relativedelta(
years=Config.config.search_api.num_of_years_determining_public_data,
)
return creation_date < (current_datetime - rd)
@root_validator(pre=True)
def set_is_public(cls, values): # noqa: B902, N805
# Hardcoding this to True because anon user is used for querying so all data
# returned by it is public
values["isPublic"] = True
return values

@classmethod
def from_icat(cls, icat_data, required_related_fields):
Expand Down

0 comments on commit 64f62c2

Please sign in to comment.