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

Various code compliance changes and updates #2143

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
exclude: '.*/vendor/.*'
repos:
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.12.0
rev: 1.15.0
hooks:
- id: django-upgrade
args: [--target-version, '3.2']
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
rev: v0.1.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/rtts/djhtml
rev: 'v1.5.2'
rev: '3.0.6'
hooks:
- id: djhtml
- repo: https://github.com/ambv/black
rev: 23.3.0
rev: 23.10.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ['--maxkb=128']
Expand Down Expand Up @@ -49,12 +49,12 @@ repos:
exclude: fixtures/.*
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
rev: v3.0.3
hooks:
- id: prettier
files: \.(css|less|scss|ts|tsx|graphql|gql|json|js|jsx|md|yaml|yml)$
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.32.0
rev: v8.51.0
hooks:
- id: eslint
additional_dependencies:
Expand All @@ -72,11 +72,11 @@ repos:
- 'stylelint-config-recommended@^3.0.0'
- 'stylelint-value-no-unknown-custom-properties@^4.0.0'
- repo: https://github.com/aws-cloudformation/cfn-python-lint
rev: v0.72.9
rev: v0.82.2
hooks:
- id: cfn-python-lint
files: cloudformation/.*\.(json|yml|yaml)$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
rev: 1.7.5
hooks:
- id: bandit
8 changes: 6 additions & 2 deletions cloudformation/add_cloudflare_ips_to_sgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@

EC2_CLIENT = boto3.client("ec2")

CLOUDFLARE_IPV4 = requests.get("https://www.cloudflare.com/ips-v4").text.splitlines()
CLOUDFLARE_IPV6 = requests.get("https://www.cloudflare.com/ips-v6").text.splitlines()
CLOUDFLARE_IPV4 = requests.get(
"https://www.cloudflare.com/ips-v4", timeout=30
).text.splitlines()
CLOUDFLARE_IPV6 = requests.get(
"https://www.cloudflare.com/ips-v6", timeout=30
).text.splitlines()


def add_ingess_rules_for_group(sg_id, existing_permissions):
Expand Down
4 changes: 2 additions & 2 deletions concordia/management/commands/import_site_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def handle(self, *, csv_file, **options):
reader = csv.reader(csv_file, delimiter=",")
header = reader.__next__()
for row in reader:
site_report_data = {key: value for key, value in zip(header, row)}
site_report = dict()
site_report_data = dict(zip(header, row, strict=True))
site_report = {}

for key in site_report_data:
if site_report_data[key] != "":
Expand Down
8 changes: 5 additions & 3 deletions concordia/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ def get_secret(secret_name):
get_secret_value_response = client.get_secret_value(SecretId=secret_name)
except ClientError as e:
if e.response["Error"]["Code"] == "ResourceNotFoundException":
raise Exception("The requested secret " + secret_name + " was not found")
raise Exception(
"The requested secret " + secret_name + " was not found"
) from e
elif e.response["Error"]["Code"] == "InvalidRequestException":
raise Exception("The request was invalid due to:", e)
raise Exception("The request was invalid due to:", e) from e
elif e.response["Error"]["Code"] == "InvalidParameterException":
raise Exception("The request had invalid params:", e)
raise Exception("The request had invalid params:", e) from e
else:
# Decrypted secret using the associated KMS CMK Depending on whether the
# secret was a string or binary, one of these fields will be populated
Expand Down
3 changes: 0 additions & 3 deletions concordia/signals/signals.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import django.dispatch

# signals notify channels of asset reservation - kwargs from handlers
# ["asset_pk", "reservation_token"]

reservation_obtained = django.dispatch.Signal()

reservation_released = django.dispatch.Signal()
22 changes: 10 additions & 12 deletions concordia/static/admin/editor-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
var frameDocument = this.contentDocument;
frameDocument.open();
frameDocument.write(
'<html><body><main>Loading…</main></body></html>'
'<html><body><main>Loading…</main></body></html>',
);
frameDocument.close();

var previewTemplate = document.querySelector(
'template#preview-head'
'template#preview-head',
).content;

previewTemplate.childNodes.forEach((node) => {
frameDocument.head.appendChild(
frameDocument.importNode(node, true)
frameDocument.head.append(
frameDocument.importNode(node, true),
);
});

Expand Down Expand Up @@ -90,7 +90,7 @@
$formRow.find('.errornote').remove();

editorLineWidgets.forEach((widget) =>
editor.removeLineWidget(widget)
editor.removeLineWidget(widget),
);

try {
Expand All @@ -110,21 +110,19 @@
lineWarning.style.whiteSpace = 'nowrap';
lineWarning.style.overflow = 'hidden';

var icon = lineWarning.appendChild(
document.createElement('span')
var icon = lineWarning.append(
document.createElement('span'),
);
icon.style.marginRight = '1rem';
icon.innerHTML = '⚠️';
lineWarning.appendChild(
document.createTextNode(error.message)
);
lineWarning.append(document.createTextNode(error.message));

editorLineWidgets.push(
editor.addLineWidget(
error.loc.start.line - 1,
lineWarning,
{coverGutter: false, noHScroll: true}
)
{coverGutter: false, noHScroll: true},
),
);
}
});
Expand Down
54 changes: 27 additions & 27 deletions concordia/static/js/action-app/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class Alert {
'data-dismiss': 'alert',
'aria-label': 'Close',
},
html('span.fas.fa-times-circle', {'aria-hidden': 'true'})
)
html('span.fas.fa-times-circle', {'aria-hidden': 'true'}),
),
);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ export class MetadataPanel {
constructor(asset) {
this.campaignMetadata = new CampaignMetadataDetails(
'Campaign',
asset.campaign
asset.campaign,
);
this.projectMetadata = new MetadataDetails('Project', asset.project);
this.itemMetadata = new ItemMetadataDetails('Item', asset.item);
Expand All @@ -76,7 +76,7 @@ export class MetadataPanel {
'#asset-metadata-panel',
this.campaignMetadata,
this.projectMetadata,
this.itemMetadata
this.itemMetadata,
);
}
}
Expand All @@ -94,10 +94,10 @@ class MetadataDetails {
'a',
{target: '_blank', hidden: true},
(this.thumbnailIcon = html(
'img.img-thumbnail.img-fluid.w-25.float-right'
))
'img.img-thumbnail.img-fluid.w-25.float-right',
)),
)),
(this.descriptionContainer = html('div'))
(this.descriptionContainer = html('div')),
),
];
this.el = html('details', {open: true}, this.children);
Expand Down Expand Up @@ -146,7 +146,7 @@ class RelatedLink {
this.el = html(
'li.link',
(this.title = html('h5.title')),
(this.link = html('a', {target: '_blank'}))
(this.link = html('a', {target: '_blank'})),
);
}
update(relatedLink) {
Expand All @@ -162,7 +162,7 @@ class RelatedLinks {
'.related-links',
{hidden: true},
html('h4.title', text('Related Links')),
(this.linkList = list('ul.list-unstyled', RelatedLink))
(this.linkList = list('ul.list-unstyled', RelatedLink)),
);
}
update(links) {
Expand Down Expand Up @@ -195,7 +195,7 @@ class RawMetadataDisplay {
this.el = html(
'details',
html('summary', text('Raw Metadata')),
html('pre.raw-metadata')
html('pre.raw-metadata'),
);
}
update(data) {
Expand Down Expand Up @@ -223,7 +223,7 @@ class FeaturedMetadata extends List {
// the keys to display titles:
.sort(
(a, b) =>
FEATURED_KEYS.indexOf(a[0]) - FEATURED_KEYS.indexOf(b[0])
FEATURED_KEYS.indexOf(a[0]) - FEATURED_KEYS.indexOf(b[0]),
)
.map(([key, value]) => {
let values = [];
Expand Down Expand Up @@ -299,7 +299,7 @@ class AssetListItem {
// FIXME: [2020-10-31] this is an ugly, ugly kludge and should be replaced with something like https://www.npmjs.com/package/iiif-image
thumbnailUrl = thumbnailUrl.replace(
/(\/iiif\/.+\/full)\/pct:100\/(0\/default.jpg)$/,
'$1/!512,512/$2'
'$1/!512,512/$2',
);
}

Expand Down Expand Up @@ -445,7 +445,7 @@ class ConditionalToolbar {
this.message = html('div.text-center');

this.el = html(
'.concordia-app-transcription-toolbar.py-3.text-center.d-print-none'
'.concordia-app-transcription-toolbar.py-3.text-center.d-print-none',
);
}

Expand Down Expand Up @@ -480,7 +480,7 @@ class ReviewerView {
class: 'btn btn-primary',
title: 'Correct errors you see in the text',
},
text('Edit')
text('Edit'),
)),
(this.acceptButton = html(
'button',
Expand All @@ -490,9 +490,9 @@ class ReviewerView {
class: 'btn btn-primary',
title: 'Confirm that the text is accurately transcribed',
},
text('Accept')
text('Accept'),
)),
]))
])),
);

this.rejectButton.addEventListener('click', (event) => {
Expand All @@ -513,7 +513,7 @@ class ReviewerView {

this.el.classList.toggle(
'nothing-to-transcribe',
!asset.latest_transcription.text
!asset.latest_transcription.text,
);

if (asset.latest_transcription.text) {
Expand Down Expand Up @@ -550,7 +550,7 @@ class TranscriberView {
class: 'form-check-label',
for: 'nothing-to-transcribe',
},
text('Nothing to transcribe')
text('Nothing to transcribe'),
),
html(
'a',
Expand All @@ -569,8 +569,8 @@ class TranscriberView {
html('span', {
class: 'fas fa-question-circle',
'aria-label': 'Open Help',
})
)
}),
),
),
(this.saveButton = html(
'button',
Expand All @@ -589,7 +589,7 @@ class TranscriberView {
return false;
},
},
text('Save')
text('Save'),
)),
(this.submitButton = html(
'button',
Expand All @@ -605,7 +605,7 @@ class TranscriberView {
return false;
},
},
text('Submit for Review')
text('Submit for Review'),
)),
]);

Expand All @@ -632,8 +632,8 @@ class TranscriberView {
this.updateAvailableToolbarActions();
},
})),
this.toolbar
)
this.toolbar,
),
);
}

Expand All @@ -657,7 +657,7 @@ class TranscriberView {
if (noUpstream || upstreamUnchanged || assetStatusUnchanged) {
// eslint-disable-next-line no-console
console.debug(
`Asset ${asset.id} unmodified; not resetting transcription view`
`Asset ${asset.id} unmodified; not resetting transcription view`,
);
return;
}
Expand Down Expand Up @@ -728,7 +728,7 @@ class TranscriberView {
if (nothingToTranscribe && this.textarea.value) {
if (
!confirm(
'You currently have entered text which will not be saved because “Nothing to transcribe” is checked. Do you want to discard that text?'
'You currently have entered text which will not be saved because “Nothing to transcribe” is checked. Do you want to discard that text?',
)
) {
nothingToTranscribe = false;
Expand Down Expand Up @@ -808,7 +808,7 @@ export class AssetViewer {

this.reviewerView = new ReviewerView(this.submitAction.bind(this));
this.transcriberView = new TranscriberView(
this.submitAction.bind(this)
this.submitAction.bind(this),
);

// FIXME: [2020-10-31] finish pulling in the rest of this structure so it will all be created normally
Expand Down
Loading