-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracking pull request to merge release-1.18.0 to master - Sprint 28 (…
…Bunsen) (#510)
- Loading branch information
1 parent
8fb1172
commit f9f4d3c
Showing
73 changed files
with
1,733 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
backend/api/fixtures/operational/0018_update_notifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from django.db import transaction | ||
|
||
from api.management.data_script import OperationalDataScript | ||
from api.models.notification import Notification | ||
from api.models.permission import Permission | ||
from api.authorities import REQUIRED_AUTHORITIES | ||
|
||
|
||
class UpdateNotifications(OperationalDataScript): | ||
""" | ||
Update the Notifications | ||
""" | ||
is_revertable = False | ||
comment = 'Update the Notifications' | ||
|
||
def check_run_preconditions(self): | ||
return True | ||
|
||
def add_notifications(self): | ||
|
||
Notification.objects.get_or_create( | ||
notification_code="CREDIT_TRANSFER_SUBMITTED", | ||
permission=Permission.objects.get(permission_code="CREATE_CREDIT_TRANSFERS"), | ||
defaults={ | ||
'name': 'Credit Transfer to Review', | ||
'description': "when supplier submits a credit transfer" | ||
} | ||
) | ||
Notification.objects.get_or_create( | ||
notification_code="CREDIT_TRANSFER_RESCINDED_PARTNER", | ||
permission=Permission.objects.get(permission_code="CREATE_CREDIT_TRANSFERS"), | ||
defaults={ | ||
'name': 'Credit Transfer Rescinded by Transfer Partner', | ||
'description': "when transfer partner rescind a credit transfer" | ||
} | ||
) | ||
Notification.objects.get_or_create( | ||
notification_code="CREDIT_TRANSFER_REJECTED_PARTNER", | ||
permission=Permission.objects.get(permission_code="CREATE_CREDIT_TRANSFERS"), | ||
defaults={ | ||
'name': 'Credit Transfer Rejected by Transfer Partner', | ||
'description': "when transfer partner reject a credit transfer" | ||
} | ||
) | ||
Notification.objects.get_or_create( | ||
notification_code="ZEV_MODEL_RANGE_REPORT_TEST_RESULT_REQUESTED", | ||
permission=Permission.objects.get(permission_code="CREATE_ZEV"), | ||
defaults={ | ||
'name': 'ZEV Model Request for Range Change / Test Results', | ||
'description': "when government request range report or test results for a zev model" | ||
} | ||
) | ||
Notification.objects.get_or_create( | ||
notification_code="CREDIT_TRANSFER_RESCINDED", | ||
permission=Permission.objects.get(permission_code="RECOMMEND_CREDIT_TRANSFER"), | ||
defaults={ | ||
'name': 'Credit Transfer Rescinded by Supplier', | ||
'description': "when supplier rescinds transfer" | ||
} | ||
) | ||
|
||
def delete_notifications(self): | ||
notifications_to_be_deleted = [ | ||
'ZEV_MODEL_RANGE_REPORT_REQUESTED', | ||
'ZEV_MODEL_TEST_RESULTS_REQUESTED', | ||
'CREDIT_TRANSFER_RESCIND_PARTNER', | ||
'CREDIT_TRANSFER_REJECT_PARTNER', | ||
'CREDIT_TRANSFER_RESCIND' | ||
] | ||
Notification.objects.filter( | ||
notification_code__in=notifications_to_be_deleted | ||
).delete() | ||
|
||
@transaction.atomic | ||
def run(self): | ||
self.delete_notifications() | ||
self.add_notifications() | ||
|
||
print('Updated Notifications') | ||
|
||
|
||
script_class = UpdateNotifications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 3.0.3 on 2021-01-20 16:53 | ||
|
||
import db_comments.model_mixins | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0084_notification_notificationsubscription'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SalesEvidence', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), | ||
('create_user', models.CharField(default='SYSTEM', max_length=130)), | ||
('update_timestamp', models.DateTimeField(auto_now=True, null=True)), | ||
('update_user', models.CharField(max_length=130, null=True)), | ||
('filename', models.CharField(max_length=260)), | ||
('minio_object_name', models.CharField(max_length=32)), | ||
('size', models.BigIntegerField(default=0)), | ||
('mime_type', models.CharField(blank=True, max_length=255, null=True)), | ||
('is_removed', models.BooleanField(default=False)), | ||
('submission', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='sales_evidence', to='api.SalesSubmission')), | ||
], | ||
options={ | ||
'db_table': 'sale_submission_file_attachment', | ||
}, | ||
bases=(models.Model, db_comments.model_mixins.DBComments), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 3.0.3 on 2021-01-20 21:18 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0085_salesevidence'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelTable( | ||
name='salesevidence', | ||
table='sales_submission_evidence', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.db import models | ||
from auditable.models import Auditable | ||
|
||
|
||
class SalesEvidence(Auditable): | ||
""" | ||
Attachment information for the sale submission. | ||
""" | ||
submission = models.ForeignKey( | ||
'SalesSubmission', | ||
null=False, | ||
related_name='sales_evidence', | ||
on_delete=models.PROTECT | ||
) | ||
filename = models.CharField( | ||
max_length=260, | ||
db_comment="Filename from when it was in the user's system." | ||
) | ||
minio_object_name = models.CharField( | ||
blank=False, | ||
max_length=32, | ||
null=False, | ||
db_comment="Object name in minio (UUID as a 32 hexadecimal string)." | ||
) | ||
size = models.BigIntegerField( | ||
default=0, | ||
null=False, | ||
db_comment="Size of the file in bytes." | ||
) | ||
mime_type = models.CharField( | ||
blank=True, | ||
max_length=255, | ||
null=True, | ||
db_comment="Mime type information of the file. " | ||
"(eg. application/pdf, image/gif, image/png, etc)" | ||
) | ||
is_removed = models.BooleanField( | ||
default=False, | ||
db_comment="Whether it was marked as deleted" | ||
) | ||
|
||
class Meta: | ||
db_table = 'sales_submission_evidence' | ||
|
||
db_table_comment = "Attachment information for the sale submission." \ | ||
"Contains information such as mime type, file size, " \ | ||
"and minio URL." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class UploadPermissions(permissions.BasePermission): | ||
"""Used by Viewset to check permissions for API requests""" | ||
|
||
def has_permission(self, request, view): | ||
if request.user.is_government: | ||
return True | ||
|
||
return request.user.has_perm('CREATE_SALES') or \ | ||
request.user.has_perm('SUBMIT_SALES') or \ | ||
request.user.has_perm('EDIT_SALES') or \ | ||
request.user.has_perm('CREATE_ZEV') or \ | ||
request.user.has_perm('EDIT_ZEV') or \ | ||
request.user.has_perm('SUBMIT_ZEV') | ||
|
||
def has_object_permission(self, request, view, obj): | ||
"""Check permissions When an object does exist (PUT, GET)""" | ||
if request.user.is_government: | ||
return True | ||
|
||
if request.user.has_perm('CREATE_SALES') or \ | ||
request.user.has_perm('SUBMIT_SALES') or \ | ||
request.user.has_perm('EDIT_SALES') or \ | ||
request.user.has_perm('CREATE_ZEV') or \ | ||
request.user.has_perm('EDIT_ZEV') or \ | ||
request.user.has_perm('SUBMIT_ZEV'): | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class VehiclePermissions(permissions.BasePermission): | ||
"""Used by Viewset to check permissions for API requests""" | ||
|
||
def has_permission(self, request, view): | ||
"""Check permissions When an object does not yet exist (POST)""" | ||
# Fallback to has_object_permission unless it's a POST | ||
if request.method != 'POST': | ||
return True | ||
|
||
if request.user.is_government: | ||
return request.user.has_perm('REQUEST_ZEV_CHANGES') or \ | ||
request.user.has_perm('VALIDATE_ZEV') | ||
|
||
return request.user.has_perm('CREATE_ZEV') or \ | ||
request.user.has_perm('SUBMIT_ZEV') or \ | ||
request.user.has_perm('EDIT_ZEV') | ||
|
||
def has_object_permission(self, request, view, obj): | ||
"""Check permissions When an object does exist (PUT, GET)""" | ||
if request.user.has_perm('REQUEST_ZEV_CHANGES') or \ | ||
request.user.has_perm('VALIDATE_ZEV'): | ||
return True | ||
|
||
if obj.organization_id == request.user.organization_id: | ||
if request.method in permissions.SAFE_METHODS: | ||
return True | ||
|
||
if request.user.has_perm('CREATE_ZEV') or \ | ||
request.user.has_perm('SUBMIT_ZEV') or \ | ||
request.user.has_perm('EDIT_ZEV'): | ||
return True | ||
|
||
if request.method == 'GET' and \ | ||
request.user.has_perm('VIEW_ZEV'): | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.