Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix to the Unit tests and security
  • Loading branch information
robotichead committed Oct 25, 2021
1 parent 4567b3f commit 157f7c3
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 30 deletions.
2 changes: 1 addition & 1 deletion NearBeach/__init__.py
@@ -1,2 +1,2 @@
name = "NearBeach"
__version__ = "0.28.14"
__version__ = "0.28.15"
2 changes: 1 addition & 1 deletion NearBeach/static/NearBeach/NearBeach.min.js

Large diffs are not rendered by default.

Binary file modified NearBeach/static/NearBeach/NearBeach.min.js.gz
Binary file not shown.
Expand Up @@ -3,7 +3,6 @@
{% block content %}
<new-request-for-change v-bind:group-results="{{ group_results }}"
v-bind:user-group-results="{{user_group_results}}"
v-bind:user-results="{{user_results}}"
v-bind:root-url="`{% url 'dashboard' %}`"
v-bind:static-url="`{% static '' %}`"
></new-request-for-change>
Expand Down
5 changes: 1 addition & 4 deletions NearBeach/tests/test_object_data.py
Expand Up @@ -40,10 +40,7 @@ def test_incorrect_location_data(self):

# Get data of wrong location
response = c.post(reverse('associated_objects', args=['taks', 1]))
self.assertEqual(response.status_code, 200)
print("\n\n")
print(response.content)
print("\n\n")
self.assertEqual(response.status_code, 400)

def test_team_leader_searches(self):
c = Client()
Expand Down
8 changes: 7 additions & 1 deletion NearBeach/views/object_data_views.py
Expand Up @@ -299,7 +299,13 @@ def admin_add_user(request):

user_results = User.objects.filter(
is_active=True,
).values()
).values(
'id',
'username',
'first_name',
'last_name',
'email',
)

# Convert data to json format
group_results = json.dumps(list(group_results), cls=DjangoJSONEncoder)
Expand Down
33 changes: 24 additions & 9 deletions NearBeach/views/request_for_change_views.py
Expand Up @@ -21,7 +21,15 @@ def get_rfc_context(rfc_id):
"""
# Get data
rfc_results = request_for_change.objects.get(rfc_id=rfc_id)
rfc_change_lead = User.objects.get(id=rfc_results.rfc_lead.id)
rfc_change_lead = User.objects.filter(
id=rfc_results.rfc_lead.id
).values(
'id',
'email',
'first_name',
'last_name',
'username',
)
user_list = User.objects.filter(
is_active=True,
id__in=user_group.objects.filter(
Expand All @@ -31,15 +39,25 @@ def get_rfc_context(rfc_id):
request_for_change_id=rfc_id,
).values('group_id')
).values('username_id')
).values(
'id',
'email',
'first_name',
'last_name',
'username',
)

# Convert from ORM to JSON
rfc_change_lead = json.dumps(list(rfc_change_lead), cls=DjangoJSONEncoder)
user_list = json.dumps(list(user_list), cls=DjangoJSONEncoder)

# Context
c = {
'nearbeach_title': 'RFC %s' % rfc_id,
'rfc_id': rfc_id,
'rfc_results': serializers.serialize('json', [rfc_results]),
'rfc_change_lead': serializers.serialize('json', [rfc_change_lead]),
'user_list': serializers.serialize('json', user_list),
'rfc_change_lead': rfc_change_lead,
'user_list': user_list,
}

return c
Expand All @@ -52,7 +70,6 @@ def new_request_for_change(request, *args, **kwargs):
:param request:
:return:
"""
# CHECK USER PERMISSIONS

# Get template
t = loader.get_template('NearBeach/request_for_change/new_request_for_change.html')
Expand All @@ -71,16 +88,14 @@ def new_request_for_change(request, *args, **kwargs):
'group__group_name',
).distinct()

user_results = User.objects.filter( # This should only be group leaders
is_active=True,
)
# Convert ORM to JSON
user_group_results = json.dumps(list(user_group_results), cls=DjangoJSONEncoder)

# Context
c = {
'group_results': serializers.serialize('json', group_results),
'nearbeach_title': 'New RFC',
'user_group_results': json.dumps(list(user_group_results), cls=DjangoJSONEncoder),
'user_results': serializers.serialize('json', user_results),
'user_group_results': user_group_results,
}

return HttpResponse(t.render(c, request))
Expand Down
21 changes: 18 additions & 3 deletions NearBeach/views/search_views.py
Expand Up @@ -440,12 +440,18 @@ def search_user(request):

# Get Data
user_results = User.objects.filter(
).values(
'id',
'email',
'first_name',
'last_name',
'username',
).order_by('last_name', 'first_name')[:50]

# Context
c = {
'nearbeach_title': 'Search User',
'user_results': serializers.serialize('json', user_results),
'user_results': json.dumps(list(user_results), cls=DjangoJSONEncoder),
}

return HttpResponse(t.render(c, request))
Expand Down Expand Up @@ -475,9 +481,18 @@ def search_user_data(request):
)

# Only have 50 results and order by alphabetical order
user_results.order_by('last_name', 'first_name')[:50]
user_results = user_results.values(
'id',
'email',
'first_name',
'last_name',
'username',
).order_by(
'last_name',
'first_name'
)[:50]

# Send back json data
json_results = serializers.serialize('json', user_results)
json_results = json.dumps(list(user_results), cls=DjangoJSONEncoder)

return HttpResponse(json_results, content_type='application/json')
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nearbeach",
"version": "0.28.14",
"version": "0.28.15",
"description": "NearBeach - an Open Source project management system built with Django web framework",
"main": "/src/js/app.js",
"directories": {
Expand Down
2 changes: 0 additions & 2 deletions src/js/components/request_for_change/NewRequestForChange.vue
Expand Up @@ -26,7 +26,6 @@
>
<rfc-details v-bind:group-results="groupResults"
v-bind:user-group-results="userGroupResults"
v-bind:user-results="userResults"
v-on:update_validation="updateValidation($event)"
v-on:update_values="updateValues($event)"
></rfc-details>
Expand Down Expand Up @@ -98,7 +97,6 @@
return [];
},
},
userResults: Array,
},
components: {
FormWizard,
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/request_for_change/RfcInformation.vue
Expand Up @@ -112,10 +112,10 @@
<img src="/static/NearBeach/images/placeholder/people_tax.svg" alt="default profile" class="default-user-profile" />
</td>
<td>
<strong>{{rfcChangeLead[0]['fields']['username']}}: </strong>{{rfcChangeLead[0]['fields']['first_name']}} {{rfcChangeLead[0]['fields']['last_name']}}
<strong>{{rfcChangeLead[0]['username']}}: </strong>{{rfcChangeLead[0]['first_name']}} {{rfcChangeLead[0]['last_name']}}
<div class="spacer"></div>
<p class="user-card-email">
{{rfcChangeLead[0]['fields']['email']}}
{{rfcChangeLead[0]['email']}}
</p>
</td>
</tr>
Expand Down
Expand Up @@ -218,7 +218,7 @@
getUserName: function(user_id) {
//Filter for the user by using the user_id
var single_user = this.userList.filter(row => {
return row['pk'] == user_id;
return row['id'] == user_id;
});
//If there are no results - default to ---
Expand All @@ -227,7 +227,7 @@
}
//User was filtered out - return their name
return `${single_user[0]['fields']['username']}: ${single_user[0]['fields']['first_name']} ${single_user[0]['fields']['last_name']}`;
return `${single_user[0]['username']}: ${single_user[0]['first_name']} ${single_user[0]['last_name']}`;
},
updateChangeTaskList: function(data) {
//Update change task list
Expand Down
1 change: 0 additions & 1 deletion src/js/components/request_for_change/tabs/RfcDetails.vue
Expand Up @@ -143,7 +143,6 @@
return [];
},
},
userResults: Array,
},
mixins: [
searchMixin
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/search/SearchUsers.vue
Expand Up @@ -21,10 +21,10 @@
v-bind:href="`/user_information/${user['pk']}/`"
>
<strong>
{{user['fields']['username']}}: {{user['fields']['first_name']}} {{user['fields']['last_name']}}
{{user['username']}}: {{user['first_name']}} {{user['last_name']}}
</strong>
<div class="spacer"></div>
<p class="small-text">{{user['fields']['email']}}</p>
<p class="small-text">{{user['email']}}</p>
</a>
</div>

Expand Down

0 comments on commit 157f7c3

Please sign in to comment.