Skip to content

Commit

Permalink
Merge pull request #1151 from PnX-SI/develop
Browse files Browse the repository at this point in the history
Develop > Master / Prepa 2.5.4
  • Loading branch information
camillemonchicourt authored Nov 17, 2020
2 parents f8789da + 4a04a3f commit 088d8f8
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 35 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.3
2.5.4
19 changes: 15 additions & 4 deletions backend/geonature/core/gn_commons/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from PIL import Image
from io import BytesIO
from flask import current_app, url_for
from sqlalchemy import and_
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from pypnnomenclature.models import TNomenclatures
Expand Down Expand Up @@ -399,13 +400,19 @@ def sync_medias():
res_medias_temp = (
DB.session.query(TMedias.id_media)
.filter(
TMedias.meta_update_date < (datetime.datetime.now() - datetime.timedelta(hours=24))
and_(
TMedias.meta_update_date < (datetime.datetime.now() - datetime.timedelta(hours=24)),
TMedias.uuid_attached_row == None
)
)
.all()
)

id_medias_temp = [res.id_media for res in res_medias_temp]

if (id_medias_temp):
print('sync media remove temp media with ids : ', id_medias_temp)

for id_media in id_medias_temp:
TMediaRepository(id_media=id_media).delete()

Expand Down Expand Up @@ -438,14 +445,18 @@ def sync_medias():

ids_media_to_delete = [x for x in ids_media_file if x not in ids_media_base]

if (ids_media_to_delete):
print('sync media remove unassociated medias with ids : ', ids_media_to_delete)

for f_data in liste_fichiers:
if f_data['id_media'] not in ids_media_to_delete:
continue

if 'thumbnail' in str(f_data['path']):
print(f_data['path'])
os.remove(f_data['path'])
remove_file(f_data['path'])
else:
deleted_paths = str(f_data['path']).split('/')
deleted_paths[-1] = 'deleted_' + deleted_paths[-1]
rename_file(f_data['path'], "/".join(deleted_paths))

def get_table_location_id(schema_name, table_name):
try:
Expand Down
1 change: 0 additions & 1 deletion backend/geonature/core/gn_commons/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def get_modules(info_role):
modules = q.all()
allowed_modules = []
for mod in modules:
print(mod.module_code)
app_cruved = cruved_scope_for_user_in_module(
id_role=info_role.id_role, module_code=mod.module_code
)[0]
Expand Down
22 changes: 9 additions & 13 deletions backend/geonature/core/gn_permissions/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def get_user_from_token_and_raise(
return Response(msg, 403)


class UserCruved():
class UserCruved:
def __init__(self,):
self.is_herited = False
self.is_herited = False

def build_herited_user_cruved(self, user_permissions, module_code, object_code):
"""
Expand Down Expand Up @@ -127,12 +127,11 @@ def build_herited_user_cruved(self, user_permissions, module_code, object_code):
return get_max_perm(module_permissions)
# if no module permission take the max of GN perm
elif len(module_permissions) == 0:
if module_code != 'GEONATURE':
if module_code != "GEONATURE":
self.is_herited = True
return get_max_perm(geonature_permission)



def query_user_perm(
id_role, code_filter_type, code_action=None, module_code=None, object_code=None
):
Expand All @@ -153,6 +152,7 @@ def query_user_perm(
q = q.filter(VUsersPermissions.code_object == "ALL")
return q.filter(sa.or_(*ors)).all()


def get_user_permissions(
user, code_filter_type, code_action=None, module_code=None, code_object=None
):
Expand Down Expand Up @@ -189,6 +189,7 @@ def get_user_permissions(
f"User {user['id_role']} cannot '{code_action}' in module/app/object {object_for_error}"
)


def get_max_perm(perm_list):
"""
Return the max filter_code from a list of VUsersPermissions instance
Expand Down Expand Up @@ -219,9 +220,6 @@ def build_cruved_dict(cruved, get_id):
return cruved_dict





def beautifulize_cruved(actions, cruved):
"""
Build more readable the cruved dict with the actions label
Expand Down Expand Up @@ -275,7 +273,9 @@ def cruved_scope_for_user_in_module(
herited_perm = {}

for action, perm in perm_by_actions.items():
herited_perm[action] = user_cruved.build_herited_user_cruved(perm, module_code=module_code, object_code=object_code)
herited_perm[action] = user_cruved.build_herited_user_cruved(
perm, module_code=module_code, object_code=object_code
)
cruved_actions = ["C", "R", "U", "V", "E", "D"]

herited_cruved = {}
Expand Down Expand Up @@ -335,7 +335,7 @@ def cruved_scope_for_user_in_module(
return herited_cruved, herited


def get_or_fetch_user_cruved(session=None, id_role=None, module_code=None, object_code="ALL"):
def get_or_fetch_user_cruved(session=None, id_role=None, module_code=None, object_code=None):
"""
Check if the cruved is in the session
if not, get the cruved from the DB with
Expand All @@ -351,7 +351,3 @@ def get_or_fetch_user_cruved(session=None, id_role=None, module_code=None, objec
session[module_code]["user_cruved"] = user_cruved
return user_cruved





10 changes: 6 additions & 4 deletions config/settings.ini.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Fichier de configuration utilisé lors de l'installation de GeoNature

# Langue du serveur
# valeur possible : fr_FR.UTF-8, en_US.utf8
# locale -a pour voir la liste des locales disponible
Expand Down Expand Up @@ -37,8 +39,8 @@ user_pg_pass=monpassachanger
# Local projection SRID
srid_local=2154

# default language (locale)
# availaible language value : fr
# Default language (locale)
# Availaible language value : fr
default_language=fr

# Permet l'installation des couches SIG des communes et départements
Expand Down Expand Up @@ -84,13 +86,13 @@ habref_api_release=0.1.4

# Définir dans quelle version du sous-module des nomenclatures (release, branche ou tag) prendre le code SQL permettant la création du schéma 'ref_nomenclatures' de la base de données GeoNature
nomenclature_release=1.3.4
#Proxy - si le serveur sur lequel se trouve GeoNature se trouve derrière un proxy
# Proxy - si le serveur sur lequel se trouve GeoNature se trouve derrière un proxy
# laisser vide si vous n'avez pas de proxy
proxy_http=
proxy_https=


#Configuration python
# Configuration python
###########################
python_path=/usr/bin/python3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<div class="col-sm-12 col-md-7 form-container" [ngStyle]="{'max-height.px': cardHeight}">
<div>
<ng-container *ngIf="releve; else waitingBlock">

<mat-card-title>
Relevé n°{{id}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class OcctaxMapInfoComponent implements OnInit, AfterViewInit {
public cardHeight: number;
displayOccurrence: BehaviorSubject<any> = new BehaviorSubject(null);
private _geojson: any;
public userReleveCruved: any;

get releve() {
return this.occtaxData.getValue()
Expand Down Expand Up @@ -101,7 +102,9 @@ export class OcctaxMapInfoComponent implements OnInit, AfterViewInit {
this.occtaxDataService
.getOneCounting(Number(id_counting))
.pipe(map((data) => data["id_releve"]))
.subscribe((id_releve) => this.getOcctaxData(id_releve));
.subscribe((id_releve) => {
this.getOcctaxData(id_releve)
});
}

this.getNomenclatures();
Expand Down Expand Up @@ -133,6 +136,7 @@ export class OcctaxMapInfoComponent implements OnInit, AfterViewInit {
.getOneReleve(id)
.pipe(
map((data) => {
this.userReleveCruved = data.cruved;
let releve = data.releve;
releve.properties.date_min = new Date(releve.properties.date_min);
releve.properties.date_max = new Date(releve.properties.date_max);
Expand Down
5 changes: 5 additions & 0 deletions data/medias/restore_medias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dans le repertoire de geonature
# Va remplacer tous les fichiers deleted_<fichier_media> par <fichier_media>
# La synchronisation des medias fera le menage à la prochaine action sur les medias depuis geonature (creation / modification / suppression)

find . -type f -wholename './backend/static/medias/*deleted_*' | sed -e 'p;s/deleted_//' | xargs -n2 mv
94 changes: 94 additions & 0 deletions data/medias/restore_medias.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
-- Requete pour restaurer les medias depuis la table gn_commons.t_history_actions
--
-- pour les medias qui ne sont plus dans gn_commons.t_medias
-- en complement il faut executer la commande du fichier restore_medias.sh depuis le repertoire de GeoNature
-- afin de marquer les fichier supprimer (avec 'deleted_' dans le nom) en non supprimé (on enleve 'deleted')

WITH valid_deleted_media AS (
SELECT DISTINCT ON (id_media)
(a.table_content->>'id_media')::int AS id_media,
a.table_content
FROM gn_commons.t_history_actions a
JOIN gn_commons.bib_tables_location l
ON (a.table_content->>'id_table_location')::int = l.id_table_location
LEFT JOIN gn_commons.t_medias m
ON m.id_media = (table_content->>'id_media')::int
WHERE table_content->'id_media' IS NOT NULL
AND operation_type = 'D'
AND table_content->>'uuid_attached_row' IS NOT NULL
AND gn_commons.check_entity_uuid_exist(
CONCAT(schema_name, '.', table_name, '.', uuid_field_name),
(a.table_content->>'uuid_attached_row')::uuid
)
AND m.id_media IS NULL
ORDER BY id_media, id_history_action DESC
)
, media_data AS (
SELECT d.*
FROM valid_deleted_media, json_to_record(valid_deleted_media.table_content) AS d(
id_media int,
unique_id_media uuid,
id_nomenclature_media_type int,
id_table_location int,
uuid_attached_row uuid,
title_fr character varying(255),
title_en character varying(255),
title_it character varying(255),
title_es character varying(255),
title_de character varying(255),
media_url character varying(255),
media_path character varying(255),
author character varying(100),
description_fr text,
description_en text,
description_it text,
description_es text,
description_de text,
is_public boolean,
meta_create_date timestamp without time zone
)
)
INSERT INTO gn_commons.t_medias (
id_media,
unique_id_media,
id_nomenclature_media_type,
id_table_location,
uuid_attached_row,
title_fr,
title_en,
title_it,
title_es,
title_de,
media_url,
media_path,
author,
description_fr,
description_en,
description_it,
description_es,
description_de,
is_public,
meta_create_date
)
SELECT
id_media,
unique_id_media,
id_nomenclature_media_type,
id_table_location,
uuid_attached_row,
title_fr,
title_en,
title_it,
title_es,
title_de,
media_url,
media_path,
author,
description_fr,
description_en,
description_it,
description_es,
description_de,
is_public,
meta_create_date
FROM media_data
Loading

0 comments on commit 088d8f8

Please sign in to comment.