Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.9.0 [PROD] #347

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5059718
SXDEDPCXZIC-305 / show deleted records in trash
agmorev May 13, 2024
728f926
Merge pull request #267 from dpc-sdp/SXDEDPCXZIC-305
alexmorev May 13, 2024
f259bb9
SXDEDPCXZIC-299 / changes to Category functionality
agmorev May 15, 2024
028a203
Merge pull request #269 from dpc-sdp/SXDEDPCXZIC-299
alexmorev May 19, 2024
e695e51
SXDEDPCXZIC-298 / restrict access to activity stream
agmorev May 20, 2024
abcc637
SXDEDPCXZIC-298 /restrict access to activity stream using url
agmorev May 21, 2024
fdb1164
SXDEDPCXZIC-309_DATAVIC-651 / Update Dataset schema
Jun 10, 2024
ac2766f
Merge pull request #272 from dpc-sdp/SXDEDPCXZIC-309
Engerrs Jun 10, 2024
ab07ad2
SXDEDPCXZIC-313_DATAVIC-635 / make datatables_view prioritized
aleks-iv Jun 18, 2024
2fe6086
SXDEDPCXZIC-323 / Adding and managing home page content as superadmin…
mutantsan Jun 20, 2024
3920d33
SXDEDPCXZIC-323 / add schema
mutantsan Jun 20, 2024
5f19826
SXDEDPCXZIC-323 / wip
mutantsan Jun 24, 2024
d5858b6
SXDEDPCXZIC-323 / wip 2
mutantsan Jun 24, 2024
70c47df
SXDEDPCXZIC-323 / wip 3
mutantsan Jun 25, 2024
4c8b201
SXDEDPCXZIC-323 / wip 4
mutantsan Jun 25, 2024
c8be6f9
SXDEDPCXZIC-323 / update, fix tests
mutantsan Jun 25, 2024
22bd8f0
SXDEDPCXZIC-323 / add url_in_new_tab field
mutantsan Jun 25, 2024
585fc2b
SXDEDPCXZIC-323 / update tests
mutantsan Jun 25, 2024
111727c
SXDEDPCXZIC-320_DATAVIC-698 / hide DTV map preview for any file over …
alexmorev Jun 25, 2024
457f8b2
Merge pull request #284 from dpc-sdp/SXDEDPCXZIC-320
alexmorev Jun 25, 2024
a8ea73c
DATAVIC-597_SXDEDPCXZIC-323 / fix entity url redirect
mutantsan Jun 27, 2024
1a702e2
Merge branch 'DATAVIC-597_SXDEDPCXZIC-323' into release-2.9.0
mutantsan Jun 27, 2024
8fb7741
SXDEDPCXZIC-323 / allow arbitrary section names
mutantsan Jul 1, 2024
171e23e
Merge branch 'SXDEDPCXZIC-323' into release-2.9.0
mutantsan Jul 1, 2024
21c8146
Merge branch 'release-2.9.0' into SXDEDPCXZIC-313
aleks-iv Jul 4, 2024
4744eab
SXDEDPCXZIC-313_DATAVIC-635 / fix dataset read template issue
aleks-iv Jul 4, 2024
8cf4f80
SXDEDPCXZIC-372 / fix collaborator issue
alexmorev Sep 26, 2024
c5207ca
Merge pull request #330 from dpc-sdp/SXDEDPCXZIC-372
alexmorev Sep 26, 2024
6ec67e0
Merge branch 'release-2.8.0' into release-2.9.0
alexmorev Oct 13, 2024
8579e30
SXDEDPCXZIC-380 / enhancements to restricted orgs
alexmorev Oct 14, 2024
61d7517
Merge pull request #339 from dpc-sdp/SXDEDPCXZIC-380
alexmorev Oct 14, 2024
fde9f1c
SXDEDPCXZIC-380 / fix parent field ValidationError
alexmorev Oct 15, 2024
d091bc4
Merge pull request #342 from dpc-sdp/SXDEDPCXZIC-380
alexmorev Oct 15, 2024
dc9840f
Merge pull request #343 from dpc-sdp/master
joelwigley Oct 16, 2024
dca07e5
SXDEDPCXZIC-378 / Improve Org list page performance
Oct 21, 2024
51c9d34
Merge pull request #351 from dpc-sdp/SXDEDPCXZIC-378
Engerrs Oct 21, 2024
f40f94a
SXDEDPCXZIC-378 / Improve code logic
Oct 21, 2024
7913689
Merge pull request #352 from dpc-sdp/SXDEDPCXZIC-378
Engerrs Oct 21, 2024
13ab0b9
Merge pull request #373 from dpc-sdp/master
joelwigley Nov 29, 2024
c913c3c
Merge branch 'SXDEDPCXZIC-298' into release-2.9.0
alexmorev Dec 1, 2024
9a30a05
Merge remote-tracking branch 'origin/SXDEDPCXZIC-313' into release-2.9.0
mutantsan Dec 2, 2024
1322ebe
fix: fix organization_update is_org_changed logic
mutantsan Dec 2, 2024
ee50fd9
Merge pull request #346 from dpc-sdp/release-2.9.0
joelwigley Dec 5, 2024
7265860
fix: fix resource edit/create page missing fields
mutantsan Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions ckanext/datavicmain/cli/maintain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
import copy
import datetime
import logging
import csv
import openpyxl
import mimetypes

from os import path, stat
from typing import Any
from sqlalchemy.orm import Query
from itertools import groupby
from os import path
from typing import Any
from urllib.parse import urlparse

import click
import tqdm

import ckan.logic.validators as validators
import ckan.model as model
import ckan.plugins.toolkit as tk

import click
import openpyxl
import tqdm
from ckan.lib.munge import munge_title_to_name
from ckan.lib.search import rebuild
from ckan.lib.uploader import get_resource_uploader
Expand All @@ -29,6 +27,8 @@
from ckanext.harvest.model import HarvestObject, HarvestSource
from ckanext.datastore.backend import get_all_resources_ids_in_datastore

from ckanext.harvest.model import HarvestObject, HarvestSource
from sqlalchemy.orm import Query

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -576,7 +576,7 @@ def _search_in_batch(datasets: list[dict[str, Any]]) -> dict[str, dict[str, str]

def _get_default_values_for_missing_fields(
dataset: dict[str, Any], field: str
) -> "str":
) -> str:
"""Get values for missing fields"""
if field == "date_created_data_asset":
return _get_date_created(dataset)
Expand All @@ -590,6 +590,7 @@ def _get_default_values_for_missing_fields(
return "official"
elif field == "category":
return _get_category(dataset)
return ""


def _get_date_created(pkg: dict[str, Any]) -> str:
Expand All @@ -615,7 +616,7 @@ def _get_category(pkg: dict[str, Any]) -> str:
"""
if groups := pkg.get("groups"):
return groups[0].get("id")
return
return ""


@maintain.command(u"update-broken-urls",
Expand All @@ -624,7 +625,8 @@ def update_broken_urls():
"""Change resources urls' protocols from http to https listed in XLSX file"""

file = path.join(
path.dirname(__file__), "data/DTF Content list bulk URL change 20231017.xlsx"
path.dirname(__file__),
"data/DTF Content list bulk URL change 20231017.xlsx",
)
wb = openpyxl.load_workbook(file)
ws = wb.active
Expand All @@ -641,15 +643,14 @@ def update_broken_urls():

if not resource:
click.secho(
f"Resource <{title}> with URL <{url}> does not exist",
fg="red"
f"Resource <{title}> with URL <{url}> does not exist", fg="red"
)
continue

resource.url = row[XLSX_IDX_NEW_URL].value
click.secho(
f"URL of resource <{title}> has been updated to <{resource.url}>",
fg="green"
fg="green",
)

model.Session.commit()
Expand Down Expand Up @@ -825,3 +826,18 @@ def get_resources_by_size(empty: bool, limit: bool, restricted: bool):
f"Found {resources.count()} resources...",
fg="green",
)


@maintain.command("make-datatables-view-prioritized")
def make_datatables_view_prioritized():
"""Check if there are resources that have recline_view and datatables_view and
reorder them so that datatables_view is first."""
resources = model.Session.query(Resource).all()
number_reordered = 0
for resource in tqdm.tqdm(resources):
result = tk.get_action("datavic_datatables_view_prioritize")(
{"ignore_auth": True}, {"resource_id": resource.id}
)
if result.get("updated"):
number_reordered += 1
click.secho(f"Reordered {number_reordered} resources", fg="green")
7 changes: 6 additions & 1 deletion ckanext/datavicmain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

CONFIG_PAGES_BASE_URL = "ckan.pages.base_url"
CONFIG_DTV_URL = "ckanext.datavicmain.dtv.url"
CONFIG_DTV_MAX_SIZE_LIMIT = "ckanext.datavicmain.dtv.max_size_limit"
CONFIG_DTV_EXTERNAL_LINK = "ckanext.datavicmain.dtv.external_link"


Expand All @@ -15,5 +16,9 @@ def get_dtv_url() -> str:
return tk.config.get(CONFIG_DTV_URL, "")


def get_dtv_max_size_limit() -> int:
return tk.config.get(CONFIG_DTV_MAX_SIZE_LIMIT, "157286400")


def get_dtv_external_link() -> str:
return tk.config.get(CONFIG_DTV_EXTERNAL_LINK, "")
return tk.config.get(CONFIG_DTV_EXTERNAL_LINK, "")
87 changes: 75 additions & 12 deletions ckanext/datavicmain/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import annotations
from json import tool

import math
import os
Expand All @@ -8,26 +7,23 @@
import logging
import json
import base64
from typing import Any
from typing import Any, Optional

from urllib.parse import urlsplit, urljoin

from flask import Blueprint

import ckan.plugins as plugins
import ckan.model as model
import ckan.authz as authz
import ckan.plugins.toolkit as toolkit

from ckanext.harvest.model import HarvestObject
from ckanext.activity.model.activity import Activity
from ckanext.mailcraft.utils import get_mailer
from ckanext.mailcraft.exception import MailerException

from . import utils, const
from . import utils, const, config as conf
from ckanext.datavicmain.config import get_dtv_url, get_dtv_external_link

mailer = get_mailer()

log = logging.getLogger(__name__)
WORKFLOW_STATUS_OPTIONS = [
"draft",
Expand Down Expand Up @@ -368,6 +364,43 @@ def datavic_org_uploads_allowed(org_id: str) -> bool:
return flake["data"].get(org.id, False)


def get_group(group: Optional[str] = None,
include_datasets: bool = False) -> dict[str, Any]:
if group is None:
return {}
try:
return toolkit.get_action("group_show")(
{},
{"id": group, "include_datasets": include_datasets}
)
except (toolkit.NotFound, toolkit.ValidationError, toolkit.NotAuthorized):
return {}


def dtv_exceeds_max_size_limit(resource_id: str) -> bool:
"""Check if DTV resource exceeds the maximum file size limit

Args:
resource_id (str): DTV resource id

Returns:
bool: return True if dtv resource exceeds maximum file size limit set
in ckan config "ckanext.datavicmain.dtv.max_size_limit",
otherwise - False
"""
try:
resource = toolkit.get_action("resource_show")({}, {"id": resource_id})
except (toolkit.ObjectNotFound, toolkit.NotAuthorized):
return True

limit = conf.get_dtv_max_size_limit()
filesize = resource.get("filesize")
if filesize and int(filesize) >= int(limit):
return True

return False


def datavic_get_org_roles() -> list[str]:
return ["admin", "editor", "member"]

Expand Down Expand Up @@ -560,27 +593,27 @@ def _group_tree_parents(id_, type_="organization"):


def add_current_organisation(
avalable_organisations: list[dict[str, Any]], current_org: dict[str, Any]
available_organisations: list[dict[str, Any]], current_org: dict[str, Any]
):
"""When user doesn't have an access to an organisation, it won't be included
for a list of available organisations. Include it there, but check if it's
not already there"""

current_org_included = False

for organization in avalable_organisations:
for organization in available_organisations:
if organization["id"] == current_org["id"]:
current_org_included = True
break

if not current_org_included:
avalable_organisations.append(current_org)
available_organisations.append(current_org)

return avalable_organisations
return available_organisations


def datavic_max_image_size():
"""Return max size for image configurate for portal"""
"""Return max size for image configuration for portal"""
return toolkit.config["ckan.max_image_size"]


Expand Down Expand Up @@ -658,3 +691,33 @@ def datavic_allowable_parent_orgs(org_id: str = None) -> list[dict[str, Any]]:
continue
orgs.append(org)
return orgs


def has_user_capacity(
org_id: str,
current_user_id: str,
capacity: Optional[str] = None) -> bool:
"""Check if the current user has an appropriate capacity in the certain organization

Args:
org_id (str): the id or name of the organization
current_user_id (str): the id or name of the user
capacity (str): restrict the members returned to those with a given capacity,
e.g. 'member', 'editor', 'admin', 'public', 'private'
(optional, default: None)

Returns:
bool: True for success, False otherwise
"""
try:
members = toolkit.get_action("member_list")(
{},
{"id": org_id, "object_type": "user", "capacity": capacity}
)
members_id = [member[0] for member in members]
if current_user_id in members_id:
return True
except (toolkit.ObjectNotFound, toolkit.NotAuthorized):
return False

return False
2 changes: 2 additions & 0 deletions ckanext/datavicmain/iar_ckan_dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dataset_fields:

- field_name: alias
preset: dataset_alias
display_group: General

- field_name: notes
label: Description
Expand Down Expand Up @@ -152,6 +153,7 @@ dataset_fields:
label: "Off"
validators: default(true) boolean_validator
output_validators: boolean_validator
display_group: General

# Security fields

Expand Down
Loading