Skip to content

Commit

Permalink
Merge branch 'develop' into feature-1586-disable-create-new-if-not-lo…
Browse files Browse the repository at this point in the history
…gged-in
  • Loading branch information
jh-RLI authored Feb 19, 2024
2 parents 50eae78 + 92eac85 commit 96f8209
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 53 deletions.
12 changes: 6 additions & 6 deletions factsheet/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 26 additions & 11 deletions factsheet/frontend/src/components/factsheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,28 @@ function Factsheet(props) {
headers: { 'X-CSRFToken': CSRFToken() }
}
).then(response => {
if (response.data === 'Factsheet saved') {
navigate('/factsheet/fs/' + new_uid);
setIsCreated(true);
setOpenSavedDialog(true);
setUID(new_uid);
setOpenBackDrop(false);
if (response.status === 200) {
// Handle successful response

if (response.data === 'Factsheet saved') {
navigate('/factsheet/fs/' + new_uid);
setIsCreated(true);
setOpenSavedDialog(true);
setUID(new_uid);
setOpenBackDrop(false);
}
else if (response.data === 'Factsheet exists') {
setOpenExistDialog(true);
setOpenBackDrop(false);
}

}
else if (response.data === 'Factsheet exists') {
setOpenExistDialog(true);

}).catch(error => {
if (error.response && error.response.status === 403) {
// Handle "Access Denied" error
const redirectUrl = conf.toep + "/user/login/?next=/scenario-bundles/id/new";
window.location.href = redirectUrl;
}
});
} else {
Expand Down Expand Up @@ -435,6 +448,7 @@ function Factsheet(props) {
}
else if (response.data === 'Factsheet exists') {
setOpenExistDialog(true);
setOpenBackDrop(false);
}
})
.catch(error => {
Expand All @@ -453,6 +467,7 @@ function Factsheet(props) {

} else {
setEmptyAcronym(true);
setOpenBackDrop(false);
}
};

Expand Down Expand Up @@ -1923,14 +1938,14 @@ function Factsheet(props) {
<TableRow>
<FirstRowTableCell>
<div>
<span>Scenario descriptors</span>
<span>Scenario type</span>
<HtmlTooltip
title={
<React.Fragment>
<Typography color="inherit" variant="subtitle1">
{'A data descriptor is an information content entity that contains additional information about some data.'}
{'A scenario is an information content entity that contains statements about a possible future development based on a coherent and internally consistent set of assumptions and their motivation.'}
<br />
<a href="http://openenergy-platform.org/ontology/oeo/OEO_00000119">More info from Open Energy Ontology (OEO)....</a>
<a href="http://openenergy-platform.org/ontology/oeo/OEO_00000364">More info from Open Energy Ontology (OEO)....</a>
</Typography>
</React.Fragment>
}
Expand Down
2 changes: 1 addition & 1 deletion factsheet/frontend/src/components/scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export default function Scenario(props) {
{...props}
labelGridSize = {3}
fieldGridSize = {9}
spanValue="Scenario descriptors"
spanValue="Scenario type"
tooltipText="A scenario is an information content entity that contains statements about a possible future development based on a coherent and internally consistent set of assumptions and their motivation."
hrefLink="http://openenergy-platform.org/ontology/oeo/OEO_00000364"
renderField={() => (
Expand Down
100 changes: 69 additions & 31 deletions factsheet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
from django.views.decorators.csrf import csrf_exempt
from django.core import serializers
from django.utils.cache import patch_response_headers

import uuid
import requests
import rdflib
from rdflib import ConjunctiveGraph, Graph, Literal, RDF, URIRef, BNode, XSD

from rdflib.compare import to_isomorphic, graph_diff
from rdflib.plugins.stores import sparqlstore
from rdflib.namespace import XSD, Namespace
from rdflib.graph import DATASET_DEFAULT_GRAPH_ID as default
import os
from oeplatform.settings import ONTOLOGY_FOLDER, ONTOLOGY_ROOT, RDF_DATABASES
from datetime import date
from oeplatform.settings import ONTOLOGY_ROOT, RDF_DATABASES, OPEN_ENERGY_ONTOLOGY_NAME

from SPARQLWrapper import SPARQLWrapper, JSON
import sys
from owlready2 import get_ontology
Expand All @@ -27,9 +29,11 @@
authentication_classes,
permission_classes,
)
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.authtoken.models import Token

# from rest_framework.authentication import TokenAuthentication
# from rest_framework.permissions import IsAuthenticated
# from rest_framework.authtoken.models import Token

from django.contrib.auth.decorators import login_required

from .models import OEKG_Modifications, ScenarioBundleAccessControl
Expand Down Expand Up @@ -61,11 +65,11 @@
query_endpoint = "http://localhost:3030/ds/query"
update_endpoint = "http://localhost:3030/ds/update"

#query_endpoint = 'https://toekb.iks.cs.ovgu.de:3443/oekg/query'
#update_endpoint = 'https://toekb.iks.cs.ovgu.de:3443/oekg/update'
# query_endpoint = 'https://toekb.iks.cs.ovgu.de:3443/oekg/query'
# update_endpoint = 'https://toekb.iks.cs.ovgu.de:3443/oekg/update'

#query_endpoint = "https://oekb.iks.cs.ovgu.de:3443/oekg_main/query"
#update_endpoint = "https://oekb.iks.cs.ovgu.de:3443/oekg_main/update"
# query_endpoint = "https://oekb.iks.cs.ovgu.de:3443/oekg_main/query"
# update_endpoint = "https://oekb.iks.cs.ovgu.de:3443/oekg_main/update"

sparql = SPARQLWrapper(query_endpoint)

Expand Down Expand Up @@ -125,6 +129,14 @@ def undo_clean_name(name):


def factsheets_index(request, *args, **kwargs):
# userLoggedIn = False
# if request.user.is_authenticated:
# userLoggedIn = True

# context_data = {
# "userLoggedIn": userLoggedIn,
# }

return render(request, "factsheet/index.html")


Expand Down Expand Up @@ -185,7 +197,7 @@ def get_oekg_modifications(request, *args, **kwargs):
return response


@login_required
# @login_required
def create_factsheet(request, *args, **kwargs):
"""
Creates a scenario bundle based on user's data. Currently, the minimum requirement to create a bundle is the "acronym".
Expand Down Expand Up @@ -218,6 +230,10 @@ def create_factsheet(request, *args, **kwargs):
"Factsheet saved" if successful, "Duplicate error" if the bundle's acronym exists.
"""

if not request.user.is_authenticated:
return HttpResponseForbidden("User not authenticated")

request_body = json.loads(request.body)
name = request_body["name"]
uid = request_body["uid"]
Expand Down Expand Up @@ -333,24 +349,34 @@ def create_factsheet(request, *args, **kwargs):
if "interacting_regions" in item:
for interacting_region in item["interacting_regions"]:
interacting_region_URI = URIRef(interacting_region["iri"])
interacting_regions = URIRef(
scenario_interacting_region = URIRef(
"http://openenergy-platform.org/ontology/oekg/"
+ interacting_region["iri"]
)

bundle.add((interacting_regions, RDF.type, OEO.OEO_00020036))
bundle.add(
(interacting_regions, RDFS.label, Literal(region["name"]))
(scenario_interacting_region, RDF.type, OEO.OEO_00020036)
)
bundle.add(
(
scenario_interacting_region,
RDFS.label,
Literal(interacting_region["name"]),
)
)
bundle.add(
(
interacting_regions,
scenario_interacting_region,
OEKG["reference"],
interacting_region_URI,
)
)
bundle.add(
(scenario_URI, OEO.OEO_00020222, interacting_regions)
(
scenario_URI,
OEO.OEO_00020222,
scenario_interacting_region,
)
)

if "scenario_years" in item:
Expand Down Expand Up @@ -651,31 +677,42 @@ def update_factsheet(request, *args, **kwargs):
region_URI,
)
)
new_bundle.add(
(scenario_URI, OEO.OEO_00020220, scenario_region)
)

if "interacting_regions" in item:
for interacting_region in item["interacting_regions"]:
interacting_region_URI = URIRef(interacting_region["iri"])
interacting_regions = URIRef(
scenario_interacting_region = URIRef(
"http://openenergy-platform.org/ontology/oekg/"
+ interacting_region["iri"]
)

new_bundle.add(
(interacting_regions, RDF.type, OEO.OEO_00020036)
(scenario_interacting_region, RDF.type, OEO.OEO_00020036)
)
new_bundle.add(
(interacting_regions, RDFS.label, Literal(region["name"]))
(
scenario_interacting_region,
RDFS.label,
Literal(interacting_region["name"]),
)
)
new_bundle.add(
(
interacting_regions,
scenario_interacting_region,
OEKG["reference"],
interacting_region_URI,
)
)

new_bundle.add(
(scenario_URI, OEO.OEO_00020222, interacting_regions)
(
scenario_URI,
OEO.OEO_00020222,
scenario_interacting_region,
)
)

if "scenario_years" in item:
Expand Down Expand Up @@ -890,7 +927,7 @@ def update_factsheet(request, *args, **kwargs):
old_state=in_first.serialize(format="json-ld"),
new_state=in_second.serialize(format="json-ld"),
)
#OEKG_Modifications_instance.save()
# OEKG_Modifications_instance.save()

response = JsonResponse(
"factsheet updated!", safe=False, content_type="application/json"
Expand All @@ -900,10 +937,12 @@ def update_factsheet(request, *args, **kwargs):


def is_logged_in(request, *args, **kwargs):
user=login_models.myuser.objects.filter(name=request.user).first()

user = None
if request.user.is_authenticated:
user = True

output = ""
if user == None:
if user is None:
output = "NOT_LOGGED_IN"
else:
output = "LOGGED_IN"
Expand Down Expand Up @@ -1213,9 +1252,9 @@ def query_oekg(request, *args, **kwargs):
study_keywords=str(study_keywords_list).replace("[", "").replace("]", ""),
scenario_year_start=scenario_year_start_value,
scenario_year_end=scenario_year_end_value,
funding_source_exp="OEO:OEO_00000509 ?funding_sources ;"
if funding_sources_list != []
else "",
funding_source_exp=(
"OEO:OEO_00000509 ?funding_sources ;" if funding_sources_list != [] else ""
),
authors_exp="OEO:OEO_00000506 ?authors ;" if authors_list != [] else "",
)

Expand Down Expand Up @@ -1583,13 +1622,12 @@ def get_all_sub_classes(cls, visited=None):
childCount = len(list(cls.subclasses()))
subclasses = cls.subclasses()


dict = {
"name": cls.label.first(),
"label": cls.label.first(),
"value": cls.label.first(),
"iri": cls.iri,
"definition": oeo.value(OEO[str(cls).split('.')[1]], OBO.IAO_0000115)
"definition": oeo.value(OEO[str(cls).split(".")[1]], OBO.IAO_0000115),
}

if childCount > 0:
Expand All @@ -1601,7 +1639,7 @@ def get_all_sub_classes(cls, visited=None):
return dict


#@login_required
# @login_required
def populate_factsheets_elements(request, *args, **kwargs):
scenario_class = oeo_owl.search_one(
iri="http://openenergy-platform.org/ontology/oeo/OEO_00000364"
Expand Down Expand Up @@ -1645,7 +1683,7 @@ def populate_factsheets_elements(request, *args, **kwargs):
"label": sector_label,
"value": sector_label,
"sector_division": sector_division_URI,
"sector_difinition": sector_difinition
"sector_difinition": sector_difinition,
}
)

Expand Down
6 changes: 3 additions & 3 deletions modelview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def show(request, sheettype, model_name):
)
org = match.group("org")
repo = match.group("repo")
_handle_github_contributions(org, repo)
# _handle_github_contributions(org, repo)
except Exception:
org = None
repo = None
Expand Down Expand Up @@ -343,8 +343,8 @@ def _handle_github_contributions(org, repo, timedelta=3600, weeks_back=8):
If the image is not present or outdated it will be reconstructed
Note:
Keep in mind that a external (GitHub) API is called and you server need to allow
such connections.
Keep in mind that a external (GitHub) API is called and your server
needs to allow such connections.
"""
path = "GitHub_{0}_{1}_Contribution.png".format(org, repo)
full_path = os.path.join(djangoSettings.MEDIA_ROOT, path)
Expand Down
11 changes: 10 additions & 1 deletion versions/changelogs/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
## Changes

- Disable view and edit button on create new page of the scenario bundles (issue #1576) [(#1577)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1577)

- Disable create new button when the user is not logged in (issue #1576) [(#1598)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1598)



## Features

- implement ready check for ontology app to check for missing oeo release files and guide the user in case of an error [#1457](https://github.com/OpenEnergyPlatform/oeplatform/pull/1547/)
Expand All @@ -15,4 +18,10 @@

## Bugs

Bugfix: Delete a row using the http api leads to server error if table includes not nullable fields [#1581](https://github.com/OpenEnergyPlatform/oeplatform/pull/1581)
- Bugfix: Delete a row using the http api leads to server error if table includes not nullable fields [#1581](https://github.com/OpenEnergyPlatform/oeplatform/pull/1581)

- Fix: Users are now redirected to the login page if they attempt to create a new scenario bundle. (Note we will prevent not logged in users to open the create bundle page soon) [(#1595)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1595)

- Fix: Prevent functionality that attempts to connect to an external service and raises errors in the oep server logs. [#1594](https://github.com/OpenEnergyPlatform/oeplatform/pull/1594)

- Fix bug in saving and updating interacting regions (issue #1576) [(#1597)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1597)

0 comments on commit 96f8209

Please sign in to comment.