Skip to content

Commit

Permalink
Merge 4c688a0 into 93f7434
Browse files Browse the repository at this point in the history
  • Loading branch information
mboudet committed May 6, 2022
2 parents 93f7434 + 4c688a0 commit 9e60fa6
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -24,6 +24,7 @@ This changelog was started for release 4.2.0.
- Added 'Status' for files (for celery upload, and later for better file management)
- Added tooltips to buttons in the query form (and other forms)
- Added owl integration
- Added 'single tenant' mode

### Changed

Expand All @@ -46,7 +47,7 @@ This changelog was started for release 4.2.0.
- Bump path-parse from 1.0.6 to 1.0.7
- Bump prismjs from 1.23.0 to 1.27.0
- Bump simple-get from 2.8.1 to 2.8.2
- Bump ssri from 6.0.1 to 6.0.2
- Bump ssri from 6.0.1 to 6.0.2
- Bump follow-redirects from 1.14.4 to 1.14.8
- Bump mkdocs from 1.0.4 to 1.2.3 in /docs
- Bump python-ldap from 3.3.1 to 3.4.0
Expand Down
1 change: 1 addition & 0 deletions askomics/api/datasets.py
Expand Up @@ -119,6 +119,7 @@ def toogle_public():
error: True if error, else False
errorMessage: the error message of error, else an empty string
"""

data = request.get_json()
if not (data and data.get("id")):
return jsonify({
Expand Down
2 changes: 1 addition & 1 deletion askomics/api/file.py
Expand Up @@ -339,7 +339,7 @@ def integrate():
"file_id": file.id,
"name": file.human_name,
"graph_name": file.file_graph,
"public": data.get("public") if session["user"]["admin"] else False
"public": (data.get("public", False) if session["user"]["admin"] else False) or current_app.iniconfig.getboolean("askomics", "single_tenant", fallback=False)
}

dataset = Dataset(current_app, session, dataset_info)
Expand Down
3 changes: 2 additions & 1 deletion askomics/api/start.py
Expand Up @@ -79,7 +79,8 @@ def start():
"namespaceInternal": current_app.iniconfig.get('triplestore', 'namespace_internal'),
"proxyPath": proxy_path,
"user": {},
"logged": False
"logged": False,
"singleTenant": current_app.iniconfig.getboolean('askomics', 'single_tenant', fallback=False)
}

json = {
Expand Down
2 changes: 1 addition & 1 deletion askomics/libaskomics/SparqlQuery.py
Expand Up @@ -1376,7 +1376,7 @@ def build_query_from_json(self, preview=False, for_editor=False):
))
var_to_replace.append((category_value_uri, var_2))

from_string = self.get_froms_from_graphs(self.graphs)
from_string = "" if self.settings.getboolean("askomics", "single_tenant", fallback=False) else self.get_froms_from_graphs(self.graphs)
federated_from_string = self.get_federated_froms_from_graphs(self.graphs)
endpoints_string = self.get_endpoints_string()

Expand Down
1 change: 1 addition & 0 deletions askomics/libaskomics/SparqlQueryLauncher.py
Expand Up @@ -294,6 +294,7 @@ def execute_query(self, query, disable_log=False, isql_api=False):

# Debug
if self.settings.getboolean('askomics', 'debug'):
print(query)
self.log.debug("Launch {} query on {} ({})".format("ISQL" if use_isql else "SPARQL", self.triplestore, self.url_endpoint))
self.log.debug(query)

Expand Down
14 changes: 8 additions & 6 deletions askomics/libaskomics/TriplestoreExplorer.py
Expand Up @@ -208,12 +208,14 @@ def get_abstraction(self):
"""
insert, abstraction = self.get_cached_asbtraction()

single_tenant = self.settings.getboolean("askomics", "single_tenant", fallback=False)

# No abstraction entry in database, create it
if not abstraction:
abstraction = {
"entities": self.get_abstraction_entities(),
"attributes": self.get_abstraction_attributes(),
"relations": self.get_abstraction_relations()
"entities": self.get_abstraction_entities(single_tenant),
"attributes": self.get_abstraction_attributes(single_tenant),
"relations": self.get_abstraction_relations(single_tenant)
}

# Cache abstraction in DB, only for logged users
Expand Down Expand Up @@ -305,7 +307,7 @@ def uncache_abstraction(self, public=True, force=False):

database.execute_sql_query(query, sql_var)

def get_abstraction_entities(self):
def get_abstraction_entities(self, single_tenant=False):
"""Get abstraction entities
Returns
Expand Down Expand Up @@ -378,7 +380,7 @@ def get_abstraction_entities(self):

return entities

def get_abstraction_attributes(self):
def get_abstraction_attributes(self, single_tenant=False):
"""Get user abstraction attributes from the triplestore
Returns
Expand Down Expand Up @@ -497,7 +499,7 @@ def get_abstraction_attributes(self):

return attributes

def get_abstraction_relations(self):
def get_abstraction_relations(self, single_tenant=False):
"""Get user abstraction relations from the triplestore
Returns
Expand Down
3 changes: 2 additions & 1 deletion askomics/react/src/routes.jsx
Expand Up @@ -44,7 +44,8 @@ export default class Routes extends Component {
gitUrl: null,
disableIntegration: null,
namespaceData: null,
namespaceInternal: null
namespaceInternal: null,
singleTenant: false
}
}
this.cancelRequest
Expand Down
9 changes: 6 additions & 3 deletions askomics/react/src/routes/integration/bedpreview.jsx
Expand Up @@ -91,9 +91,12 @@ export default class BedPreview extends Component {
if (this.state.publicTick) {
publicIcon = <i className="fas fa-check text-success"></i>
}

let privateButton
if (this.props.config.user.admin || !this.props.config.singleTenant){
privateButton = <Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
}
let publicButton
if (this.props.config.user.admin) {
if (this.props.config.user.admin || this.props.config.singleTenant) {
publicButton = <Button onClick={this.integrate} value="public" color="secondary" disabled={this.state.publicTick}>{publicIcon} Integrate (public dataset)</Button>
}

Expand Down Expand Up @@ -124,7 +127,7 @@ export default class BedPreview extends Component {
<br />
<div className="center-div">
<ButtonGroup>
<Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
{privateButton}
{publicButton}
</ButtonGroup>
<br />
Expand Down
9 changes: 6 additions & 3 deletions askomics/react/src/routes/integration/csvtable.jsx
Expand Up @@ -240,9 +240,12 @@ export default class CsvTable extends Component {
if (this.state.publicTick) {
publicIcon = <i className="fas fa-check text-success"></i>
}

let privateButton
if (this.props.config.user.admin || !this.props.config.singleTenant){
privateButton = <Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
}
let publicButton
if (this.props.config.user.admin) {
if (this.props.config.user.admin || this.props.config.singleTenant) {
publicButton = <Button onClick={this.integrate} value="public" color="secondary" disabled={this.state.publicTick}>{publicIcon} Integrate (public dataset)</Button>
}

Expand Down Expand Up @@ -276,7 +279,7 @@ export default class CsvTable extends Component {
<br />
<div className="center-div">
<ButtonGroup>
<Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
{privateButton}
{publicButton}
</ButtonGroup>
</div>
Expand Down
8 changes: 6 additions & 2 deletions askomics/react/src/routes/integration/gffpreview.jsx
Expand Up @@ -100,8 +100,12 @@ export default class GffPreview extends Component {
if (this.state.publicTick) {
publicIcon = <i className="fas fa-check text-success"></i>
}
let privateButton
if (this.props.config.user.admin || !this.props.config.singleTenant){
privateButton = <Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
}
let publicButton
if (this.props.config.user.admin) {
if (this.props.config.user.admin || this.props.config.singleTenant) {
publicButton = <Button onClick={this.integrate} value="public" color="secondary" disabled={this.state.publicTick}>{publicIcon} Integrate (public dataset)</Button>
}

Expand Down Expand Up @@ -130,7 +134,7 @@ export default class GffPreview extends Component {
<br />
<div className="center-div">
<ButtonGroup>
<Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
{privateButton}
{publicButton}
</ButtonGroup>
<br />
Expand Down
9 changes: 6 additions & 3 deletions askomics/react/src/routes/integration/rdfpreview.jsx
Expand Up @@ -107,9 +107,12 @@ export default class RdfPreview extends Component {
if (this.state.publicTick) {
publicIcon = <i className="fas fa-check text-success"></i>
}

let privateButton
if (this.props.config.user.admin || !this.props.config.singleTenant){
privateButton = <Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
}
let publicButton
if (this.props.config.user.admin) {
if (this.props.config.user.admin || this.props.config.singleTenant) {
publicButton = <Button onClick={this.integrate} value="public" color="secondary" disabled={this.state.publicTick}>{publicIcon} Integrate (public dataset)</Button>
}

Expand Down Expand Up @@ -144,7 +147,7 @@ export default class RdfPreview extends Component {
<br />
<div className="center-div">
<ButtonGroup>
<Button onClick={this.integrate} value="private" color="secondary" disabled={this.state.privateTick}>{privateIcon} Integrate (private dataset)</Button>
{privateButton}
{publicButton}
</ButtonGroup>
</div>
Expand Down
4 changes: 2 additions & 2 deletions askomics/tasks.py
Expand Up @@ -47,7 +47,7 @@ def integrate(self, session, data, host_url):
files_handler = FilesHandler(app, session, host_url=host_url, external_endpoint=data["externalEndpoint"], custom_uri=data["customUri"])
files_handler.handle_files([data["fileId"], ])

public = data.get("public", False) if session["user"]["admin"] else False
public = (data.get("public", False) if session["user"]["admin"] else False) or app.iniconfig.getboolean("askomics", "single_tenant", fallback=False)

for file in files_handler.files:

Expand Down Expand Up @@ -170,7 +170,7 @@ def query(self, session, info):

headers = info["selects"]
results = []
if info["graphs"]:
if info["graphs"] or app.iniconfig.getboolean("askomics", "single_tenant", fallback=False):
query_launcher = SparqlQueryLauncher(app, session, get_result_query=True, federated=info["federated"], endpoints=info["endpoints"])
headers, results = query_launcher.process_query(info["query"], isql_api=True)

Expand Down
3 changes: 3 additions & 0 deletions config/askomics.ini.template
Expand Up @@ -124,6 +124,9 @@ preview_limit = 25
# Triplestore max rows limit
# result_set_max_rows = 10000

# Single tenant means all graphs are public
single_tenant=False

[federation]
# Query engine can be corese or fedx
#query_engine = corese
Expand Down
2 changes: 2 additions & 0 deletions config/askomics.test.ini
Expand Up @@ -118,6 +118,8 @@ preview_limit = 25
# Triplestore max rows limit
result_set_max_rows = 10000

single_tenant=False

[federation]
# Query engine can be corese or fedx
query_engine = corese
Expand Down
3 changes: 2 additions & 1 deletion tests/test_api.py
Expand Up @@ -42,7 +42,8 @@ def test_start(self, client):
"namespaceInternal": client.get_config('triplestore', 'namespace_internal'),
"proxyPath": "/",
"user": {},
"logged": False
"logged": False,
"singleTenant": False
}
response = client.client.get('/api/start')
assert response.status_code == 200
Expand Down

0 comments on commit 9e60fa6

Please sign in to comment.