Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into Update-contribution-instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
TanyaStere42 authored Jan 24, 2024
2 parents f69def1 + 813a459 commit bb430b5
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

name: Testing

on: push
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
name: pyupgrade
description: Run PyUpgrade on Python code.
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort
args: [--settings-path setup.cfg]
Expand All @@ -39,7 +39,7 @@ repos:
entry: brunette --config=setup.cfg
language: system
types: [python]
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
Expand Down
4 changes: 3 additions & 1 deletion app/modules/annotations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class AnnotationKeywords(db.Model, HoustonModel):
annotation_guid = db.Column(
db.GUID, db.ForeignKey('annotation.guid'), primary_key=True
)
keyword_guid = db.Column(db.GUID, db.ForeignKey('keyword.guid'), primary_key=True)
keyword_guid = db.Column(
db.GUID, db.ForeignKey('keyword.guid', ondelete='CASCADE'), primary_key=True
)
annotation = db.relationship('Annotation', back_populates='keyword_refs')
keyword = db.relationship('Keyword')

Expand Down
4 changes: 3 additions & 1 deletion app/modules/assets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

class AssetTags(db.Model, HoustonModel):
asset_guid = db.Column(db.GUID, db.ForeignKey('asset.guid'), primary_key=True)
tag_guid = db.Column(db.GUID, db.ForeignKey('keyword.guid'), primary_key=True)
tag_guid = db.Column(
db.GUID, db.ForeignKey('keyword.guid', ondelete='CASCADE'), primary_key=True
)
asset = db.relationship('Asset', back_populates='tag_refs')
tag = db.relationship('Keyword')

Expand Down
2 changes: 1 addition & 1 deletion app/modules/keywords/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Keywords(Resource):
Manipulations with Keywords.
"""

@api.response(schemas.BaseKeywordSchema(many=True))
@api.response(schemas.DetailedKeywordSchema(many=True))
@api.paginate()
def get(self, args):
"""
Expand Down
7 changes: 7 additions & 0 deletions app/modules/keywords/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""


from flask_marshmallow import base_fields

from flask_restx_patched import ModelSchema

from .models import Keyword
Expand All @@ -31,10 +33,15 @@ class DetailedKeywordSchema(BaseKeywordSchema):
Detailed Keyword schema exposes all useful fields.
"""

usageCount = base_fields.Function(
lambda kw: kw.number_referenced_dependencies(), dump_only=True
)

class Meta(BaseKeywordSchema.Meta):
fields = BaseKeywordSchema.Meta.fields + (
Keyword.created.key,
Keyword.updated.key,
'usageCount', # This is a read-only field
)
dump_only = BaseKeywordSchema.Meta.dump_only + (
Keyword.created.key,
Expand Down
1 change: 1 addition & 0 deletions app/modules/users/permissions/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
'is_admin',
],
('Keyword', AccessOperation.READ): ['is_active'],
('Keyword', AccessOperation.DELETE): ['is_admin'],
('Sighting', AccessOperation.WRITE_INTERNAL): ['is_internal'],
('Sighting', AccessOperation.READ_PRIVILEGED): ['is_staff'],
('Sighting', AccessOperation.READ): ['is_admin'],
Expand Down
73 changes: 73 additions & 0 deletions migrations/versions/dc91b517a7a4_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
"""empty message
Revision ID: dc91b517a7a4
Revises: 53b0fec87272
Create Date: 2024-01-22 22:51:34.690766
"""

from alembic import op

# revision identifiers, used by Alembic.
revision = 'dc91b517a7a4'
down_revision = '53b0fec87272'


def upgrade():
"""
Upgrade Semantic Description:
ENTER DESCRIPTION HERE
"""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('annotation_keywords', schema=None) as batch_op:
batch_op.drop_constraint(
'fk_annotation_keywords_keyword_guid_keyword', type_='foreignkey'
)
batch_op.create_foreign_key(
batch_op.f('fk_annotation_keywords_keyword_guid_keyword'),
'keyword',
['keyword_guid'],
['guid'],
ondelete='CASCADE',
)

with op.batch_alter_table('asset_tags', schema=None) as batch_op:
batch_op.drop_constraint('fk_asset_tags_tag_guid_keyword', type_='foreignkey')
batch_op.create_foreign_key(
batch_op.f('fk_asset_tags_tag_guid_keyword'),
'keyword',
['tag_guid'],
['guid'],
ondelete='CASCADE',
)

# ### end Alembic commands ###


def downgrade():
"""
Downgrade Semantic Description:
ENTER DESCRIPTION HERE
"""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('asset_tags', schema=None) as batch_op:
batch_op.drop_constraint(
batch_op.f('fk_asset_tags_tag_guid_keyword'), type_='foreignkey'
)
batch_op.create_foreign_key(
'fk_asset_tags_tag_guid_keyword', 'keyword', ['tag_guid'], ['guid']
)

with op.batch_alter_table('annotation_keywords', schema=None) as batch_op:
batch_op.drop_constraint(
batch_op.f('fk_annotation_keywords_keyword_guid_keyword'), type_='foreignkey'
)
batch_op.create_foreign_key(
'fk_annotation_keywords_keyword_guid_keyword',
'keyword',
['keyword_guid'],
['guid'],
)

# ### end Alembic commands ###
1 change: 1 addition & 0 deletions tests/modules/keywords/resources/test_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_modify_keyword(db, flask_app_client, researcher_1, staff_user):
# doublecheck by reading back in
response = keyword_utils.read_keyword(flask_app_client, researcher_1, guid)
assert response.json.get('value', None) == val2
assert response.json.get('usageCount', None) == 0

# both of these should not be allowed (403)
response = keyword_utils.patch_keyword(
Expand Down

0 comments on commit bb430b5

Please sign in to comment.