Skip to content

Commit

Permalink
Bring all v0.3.1 changes from develop to master. (#406)
Browse files Browse the repository at this point in the history
* Working on Credit Trade Permissions

Changelog:
- Model created
- Serializers created and adjuste
- privileged_access boolean field to control API visibility of comments

Todo:
- Create new permission (VIEW|EDIT)_PRIVILIGED_COMMENT
- Create route/viewSet to save comments
- Wire up the frontend
- Unit tests

* WIP

Testing mostly finished now. A few more test cases to include for
completeness.

Pending:
- Wire up the frontend
- A handful of additional api test cases

* Comments API

API is now built and has thorough unit-testing

* Split new permissions into release fixture

roles_permissions_v0.3.0.json

* Updated test to include new fixture

* Python3 Compatibility Fix

Adjusted permission class to use `'key' in dict` format rather than
dict.has_key('key').

Confirmed working with Python 3.6.4

* Added Declined indicator in the breadcrumbs

* Organizations balances (#384)

Added front-end code to show Credit Balance of the selected organization for IDIR Users
Added a check on the user's permission before showing the balance of the organization
Updated test_api_custom so it follows pep8 coding style a bit better
Added MinSerializer for Organization to reduce the amount of data (and add security) coming in for Credit Trades

* Allow partial updates through PATCH. Rescinded should now be a flag

* Updated breadcrumbs to show rescinded status. Added checks for permissions

* Code cleanup

* Comments UI complete

* Cleanup

* Typo fix

* Cleanup

* Minor refactoring. Added tests

* Fixed tests

* test site also uses logontest

* Renamed the migration table for credit trade comment

* Refactored to address review comments

* Migrations fixed up

* Added ETag and relevant testing for credit_trades query

* Added tooltip for signing the proposal

* Changing api to api-business shouldn't have been committed

* Added dropdown-menu and Credit Market Report link
  • Loading branch information
kuanfandevops committed Jun 26, 2018
1 parent d078248 commit c80d686
Show file tree
Hide file tree
Showing 79 changed files with 8,102 additions and 5,374 deletions.
546 changes: 546 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions backend/api/fake_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,6 @@ def create_credit_trade(**kwargs):
return response_data


def get_organization_balance(**kwargs):

fs_id = kwargs.get("id", create_organization())
response = client.get("/api/organizations/{}/balance".format(fs_id))
assert status.HTTP_200_OK == response.status_code
response_data = json.loads(response.content.decode("utf-8"))
return response_data


def get_fuel_suppliers(**kwargs):

response = client.get("/api/organizations/fuel_suppliers")
assert status.HTTP_200_OK == response.status_code
response_data = json.loads(response.content.decode("utf-8"))
return response_data


def create_credit_trade_dict(data):
response = client.post(
'/api/credit_trades',
Expand Down
52 changes: 52 additions & 0 deletions backend/api/fixtures/roles_permissions_v0.3.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"fields": {
"code": "VIEW_PRIVILEGED_COMMENTS",
"description": "View (Read) Privileged Comments",
"name": "View Privileged Comments"
},
"model": "api.permission",
"pk": "16"
},
{
"fields": {
"code": "EDIT_PRIVILEGED_COMMENTS",
"description": "Create and Update Privileged Comments",
"name": "Edit Privileged Comments"
},
"model": "api.permission",
"pk": "17"
},
{
"fields": {
"permission": "16",
"role": "2"
},
"model": "api.rolepermission",
"pk": null
},
{
"fields": {
"permission": "16",
"role": "3"
},
"model": "api.rolepermission",
"pk": null
},
{
"fields": {
"permission": "17",
"role": "2"
},
"model": "api.rolepermission",
"pk": null
},
{
"fields": {
"permission": "17",
"role": "3"
},
"model": "api.rolepermission",
"pk": null
}
]
174 changes: 174 additions & 0 deletions backend/api/fixtures/test_credit_trade_comments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
[
{
"fields": {
"authorization_guid": "6c239bc5-5f08-4ddd-855a-b3bf39096937",
"email": "[email protected]",
"username": "fs1",
"authorization_id": "fs1",
"display_name": "Test FS",
"first_name": "Test",
"last_name": "FS",
"organization_id": 2
},
"model": "api.user",
"pk": 400
},
{
"fields": {
"role": "4",
"user": "400"
},
"model": "api.userrole",
"pk": null
},
{
"fields": {
"authorization_guid": "935bebdb-de2a-4839-a4da-d87635cffbb3",
"email": "[email protected]",
"username": "gov_priv",
"authorization_id": "gov_priv",
"display_name": "Gov",
"first_name": "Gov",
"last_name": "Gov",
"organization_id": 1
},
"model": "api.user",
"pk": 401
},
{
"fields": {
"role": "2",
"user": "401"
},
"model": "api.userrole",
"pk": null
},
{
"fields": {
"role": "3",
"user": "401"
},
"model": "api.userrole",
"pk": null
},
{
"fields": {
"authorization_guid": "10385306-8e74-4ad5-8cc1-003bc50fbefd",
"email": "[email protected]",
"username": "gov_unpriv",
"authorization_id": "gov_unpriv",
"display_name": "Gov",
"first_name": "Gov",
"last_name": "Gov",
"organization_id": 1
},
"model": "api.user",
"pk": 402
},
{
"fields": {
"authorization_guid": "1dfbe008-d321-4a1f-912d-ecca36730895",
"email": "[email protected]",
"username": "fs2",
"authorization_id": "fs2",
"display_name": "Test FS",
"first_name": "Test",
"last_name": "FS",
"organization_id": 4
},
"model": "api.user",
"pk": 403
},
{
"fields": {
"role": "4",
"user": "403"
},
"model": "api.userrole",
"pk": null
},
{
"model": "api.credittrade",
"pk": 200,
"fields": {
"create_timestamp": null,
"create_user": null,
"update_timestamp": null,
"update_user": null,
"status": 3,
"initiator": 2,
"respondent": 3,
"type": 2,
"number_of_credits": 1000,
"fair_market_value_per_credit": "20.00",
"zero_reason": null,
"trade_effective_date": "2017-08-07",
"note": null
}
},
{
"model": "api.credittradecomment",
"pk": 1,
"fields": {
"create_timestamp": null,
"create_user": 400,
"update_timestamp": null,
"update_user": null,
"credit_trade": 200,
"privileged_access": false,
"comment": "Test Comment 1"
}
},
{
"model": "api.credittradecomment",
"pk": 2,
"fields": {
"create_timestamp": null,
"create_user": 400,
"update_timestamp": null,
"update_user": null,
"credit_trade": 200,
"privileged_access": true,
"comment": "Test Comment (privileged)"
}
},
{
"model": "api.credittradecomment",
"pk": 3,
"fields": {
"create_timestamp": null,
"create_user": 401,
"update_timestamp": null,
"update_user": null,
"credit_trade": 200,
"privileged_access": false,
"comment": "Test Comment 4 (belongs to user 401)"
}
},
{
"model": "api.credittradecomment",
"pk": 4,
"fields": {
"create_timestamp": null,
"create_user": 401,
"update_timestamp": null,
"update_user": null,
"credit_trade": 200,
"privileged_access": true,
"comment": "Test Comment 4 (privileged, belongs to user 401)"
}
},
{
"model": "api.credittradecomment",
"pk": 5,
"fields": {
"create_timestamp": null,
"create_user": 403,
"update_timestamp": null,
"update_user": null,
"credit_trade": 200,
"privileged_access": false,
"comment": "Test Comment 1 (belongs to user 403)"
}
}
]
30 changes: 30 additions & 0 deletions backend/api/migrations/0011_auto_20180613_1848.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-06-13 18:48
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0010_auto_20180529_2003'),
]

operations = [
migrations.AlterModelOptions(
name='credittrade',
options={},
),
migrations.AlterField(
model_name='user',
name='cell_phone',
field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message=b"Phone number must be entered in theformat: '+999999999'. Up to 15 digitsallowed.", regex=b'^\\+?1?\\d{9,15}$')]),
),
migrations.AlterField(
model_name='user',
name='phone',
field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message=b"Phone number must be entered in theformat: '+999999999'. Up to 15 digitsallowed.", regex=b'^\\+?1?\\d{9,15}$')]),
),
]
34 changes: 34 additions & 0 deletions backend/api/migrations/0012_credittradecomment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-06-15 21:09
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0011_auto_20180613_1848'),
]

operations = [
migrations.CreateModel(
name='CreditTradeComment',
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)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('comment', models.CharField(blank=True, max_length=4000, null=True)),
('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradecomment_CREATE_USER', to=settings.AUTH_USER_MODEL)),
('credit_trade', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_comments', to='api.CreditTrade')),
('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradecomment_UPDATE_USER', to=settings.AUTH_USER_MODEL)),
('privileged_access', models.BooleanField(default=True)),
],
options={
'ordering': ['create_timestamp'],
'db_table': 'credit_trade_comment',
},
),
]
37 changes: 37 additions & 0 deletions backend/api/migrations/0013_auto_20180619_2053.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-06-19 20:53
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0012_credittradecomment'),
]

operations = [
migrations.AddField(
model_name='credittrade',
name='rescinded',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='credittradehistory',
name='rescinded',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='user',
name='cell_phone',
field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')]),
),
migrations.AlterField(
model_name='user',
name='phone',
field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')]),
),
]
22 changes: 22 additions & 0 deletions backend/api/migrations/0014_credittradecomment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-06-19 17:57
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0013_auto_20180619_2053'),
]

operations = [
migrations.AlterField(
model_name='credittradecomment',
name='credit_trade',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_comments', to='api.CreditTrade'),
)
]
Loading

0 comments on commit c80d686

Please sign in to comment.