Skip to content

Commit

Permalink
chore(release): Brand linkage & group access hotfix (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
ieuans authored Nov 7, 2023
1 parent fd29b05 commit 9dc98a9
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def has_member_access(user, entity, permissions):
"""
Checks if a user has access to an entity via its group membership
"""
if entity.group_id in user.groups.all():
if entity.group_id in user.groups.all().values_list('id', flat=True):
return entity.group_access in permissions

return False
Expand Down
3 changes: 2 additions & 1 deletion CodeListLibrary_project/clinicalcode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@
# url(r'^adminTemp/admin_mig_concepts_dt/$', adminTemp.admin_mig_concepts_dt, name='admin_mig_concepts_dt'),
# url(r'^adminTemp/admin_force_links_dt/$', adminTemp.admin_force_concept_linkage_dt, name='admin_force_links_dt'),
# url(r'^adminTemp/admin_fix_breathe_dt/$', adminTemp.admin_fix_breathe_dt, name='admin_fix_breathe_dt'),
url(r'^adminTemp/admin_fix_malformed_codes/$', adminTemp.admin_fix_malformed_codes, name='admin_fix_malformed_codes')
#url(r'^adminTemp/admin_fix_malformed_codes/$', adminTemp.admin_fix_malformed_codes, name='admin_fix_malformed_codes'),
url(r'^adminTemp/admin_force_brand_links/$', adminTemp.admin_force_brand_links, name='admin_force_brand_links'),
]
95 changes: 94 additions & 1 deletion CodeListLibrary_project/clinicalcode/views/adminTemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import json
import logging

from clinicalcode.entity_utils import permission_utils, gen_utils
from clinicalcode.entity_utils import permission_utils, gen_utils, create_utils
from clinicalcode.models.Tag import Tag
from clinicalcode.models.Concept import Concept
from clinicalcode.models.Template import Template
Expand Down Expand Up @@ -226,6 +226,99 @@ def admin_fix_malformed_codes(request):
}
)

@login_required
def admin_force_brand_links(request):
if settings.CLL_READ_ONLY:
raise PermissionDenied

if not request.user.is_superuser:
raise PermissionDenied

if not permission_utils.is_member(request.user, 'system developers'):
raise PermissionDenied

# get
if request.method == 'GET':
return render(
request,
'clinicalcode/adminTemp/admin_temp_tool.html',
{
'url': reverse('admin_force_brand_links'),
'action_title': 'Force brand linkage',
'hide_phenotype_options': True,
}
)

# post
if request.method != 'POST':
raise BadRequest('Invalid')

phenotypes = GenericEntity.objects.filter(Q(brands__isnull=True) | Q(brands__len__lte=0)) \
.exclude(Q(collections__isnull=True) | Q(collections__len__lte=0))

for phenotype in phenotypes:
collections = phenotype.collections
if not isinstance(collections, list):
continue

related_brands = set([])
for collection_id in collections:
collection = Tag.objects.filter(id=collection_id)
if not collection.exists():
continue

brand = collection.first().collection_brand
if brand is None:
continue
related_brands.add(brand.id)

phenotype.brands = list(related_brands)
phenotype.save_without_historical_record()

# save historical
phenotypes = GenericEntity.history.filter(Q(brands__isnull=True) | Q(brands__len__lte=0)) \
.exclude(Q(collections__isnull=True) | Q(collections__len__lte=0))

for phenotype in phenotypes:
collections = phenotype.collections
if not isinstance(collections, list):
continue

related_brands = set([])
for collection_id in collections:
collection = Tag.objects.filter(id=collection_id)
if not collection.exists():
continue

brand = collection.first().collection_brand
if brand is None:
continue
related_brands.add(brand.id)

related_brands = list(related_brands)
with connection.cursor() as cursor:
sql = '''
UPDATE public.clinicalcode_historicalgenericentity
SET brands = %(brands)s
WHERE id = %(phenotype_id)s
AND history_id = %(history_id)s
'''
cursor.execute(
sql,
{ 'brands': related_brands, 'phenotype_id': phenotype.id, 'history_id': phenotype.history_id }
)

return render(
request,
'clinicalcode/adminTemp/admin_temp_tool.html',
{
'pk': -10,
'rowsAffected' : { '1': 'ALL'},
'action_title': 'Force brand linkage',
'hide_phenotype_options': True,
}
)

@login_required
def admin_force_concept_linkage_dt(request):
"""
Expand Down

0 comments on commit 9dc98a9

Please sign in to comment.