Skip to content

Commit

Permalink
Merge branch 'da/comp_comparison_v2' into fisma_sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpofo committed Jul 2, 2021
2 parents 5d6d0b7 + 3b5dcff commit aa354be
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 160 deletions.
24 changes: 14 additions & 10 deletions controls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,21 @@ def compare_components(request):
"""
Compare submitted components
"""
# TODO: need to figure out how to accumulate all checked boxes not one in pageobj
compare_list = request.POST.getlist('componentcomparecheckbox')
if compare_list:
element_list = list(Element.objects.filter(pk__in=compare_list).exclude(element_type='system').distinct())
compare_prime, element_list = element_list[0], element_list[1:]# The first component selected will be compared against the rest
compare_prime_smts = compare_prime.statements(StatementTypeEnum.CONTROL_IMPLEMENTATION_PROTOTYPE.name)
elif len(compare_list) <= 1:

checks = json.loads(request.POST.get('hiddenChecks'))
compare_list = list(checks.values())
if len(compare_list) <= 1:
# add messages
messages.add_message(request, messages.WARNING, f"Not enough components were selected to compare!")
return HttpResponseRedirect("/controls/components")
else:
ele_q = Element.objects.filter(pk__in=compare_list).exclude(element_type='system').distinct()
# Maintain sort order of compare_list otherwise Django will order ascending
element_list = sorted(ele_q, key=lambda x: compare_list.index(str(x.id)))
compare_prime, element_list = element_list[0], element_list[
1:] # The first component selected will be compared against the rest
compare_prime_smts = compare_prime.statements(StatementTypeEnum.CONTROL_IMPLEMENTATION_PROTOTYPE.name)
difference_tuples = []
differences = []
for component in element_list:
differences = []
# compare each component's statements to prime
Expand All @@ -458,14 +461,15 @@ def compare_components(request):
else:
diff = f"<span><ins style='background:#e6ffe6;'>{smt.body}</ins><span>"
differences.append(diff)
difference_tuples.extend(zip([component.name] * len(cmt_smts), cmt_smts, differences))
difference_tuples.extend(zip([component.id] * len(cmt_smts),[component.name] * len(cmt_smts), cmt_smts, differences))
if request.method == 'POST':
context = {
"element_list": element_list,
"compare_prime": compare_prime,
"prime_smts": compare_prime_smts,
"secondary_smts": cmt_smts,
"differences": difference_tuples
"differences": difference_tuples,
"compare_list": compare_list
}
return render(request, "components/compare_components.html", context)

Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jsonschema # MIT License
filetype # MIT License
# Common Django Packages
# Django==2.2.12 # BSD License
Django==3.2.4 # BSD License
Django==3.2.5 # BSD License
django-debug-toolbar # BSD License
django-allauth # MIT License
django-bootstrap3 # BSD 3-Clause License
Expand Down
112 changes: 66 additions & 46 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ appdirs==1.4.4 \
--hash=sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41 \
--hash=sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128
# via fs
asgiref==3.3.4 \
--hash=sha256:92906c611ce6c967347bbfea733f13d6313901d54dcca88195eaeb52b2a8e8ee \
--hash=sha256:d1216dfbdfb63826470995d31caed36225dcaf34f182e0fa257a4dd9e86f1b78
asgiref==3.4.1 \
--hash=sha256:4ef1ab46b484e3c706329cedeff284a5d40824200638503f5768edb6de7d58e9 \
--hash=sha256:ffc141aa908e6f175673e7b1b3b7af4fdb0ecb738fc5c8b88f69f055c2415214
# via django
attrs==21.2.0 \
--hash=sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1 \
Expand Down Expand Up @@ -187,9 +187,9 @@ dj-database-url==0.5.0 \
--hash=sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163 \
--hash=sha256:851785365761ebe4994a921b433062309eb882fedd318e1b0fcecc607ed02da9
# via -r requirements.in
django==3.2.4 \
--hash=sha256:66c9d8db8cc6fe938a28b7887c1596e42d522e27618562517cc8929eb7e7f296 \
--hash=sha256:ea735cbbbb3b2fba6d4da4784a0043d84c67c92f1fdf15ad6db69900e792c10f
django==3.2.5 \
--hash=sha256:3da05fea54fdec2315b54a563d5b59f3b4e2b1e69c3a5841dda35019c01855cd \
--hash=sha256:c58b5f19c5ae0afe6d75cbdd7df561e6eb929339985dbbda2565e1cabb19a62e
# via
# -r requirements.in
# django-allauth
Expand Down Expand Up @@ -545,41 +545,41 @@ pbr==5.6.0 \
--hash=sha256:42df03e7797b796625b1029c0400279c7c34fd7df24a7d7818a1abb5b38710dd \
--hash=sha256:c68c661ac5cc81058ac94247278eeda6d2e6aecb3e227b0387c30d277e7ef8d4
# via stevedore
pillow==8.2.0 \
--hash=sha256:01425106e4e8cee195a411f729cff2a7d61813b0b11737c12bd5991f5f14bcd5 \
--hash=sha256:031a6c88c77d08aab84fecc05c3cde8414cd6f8406f4d2b16fed1e97634cc8a4 \
--hash=sha256:083781abd261bdabf090ad07bb69f8f5599943ddb539d64497ed021b2a67e5a9 \
--hash=sha256:0d19d70ee7c2ba97631bae1e7d4725cdb2ecf238178096e8c82ee481e189168a \
--hash=sha256:0e04d61f0064b545b989126197930807c86bcbd4534d39168f4aa5fda39bb8f9 \
--hash=sha256:12e5e7471f9b637762453da74e390e56cc43e486a88289995c1f4c1dc0bfe727 \
--hash=sha256:22fd0f42ad15dfdde6c581347eaa4adb9a6fc4b865f90b23378aa7914895e120 \
--hash=sha256:238c197fc275b475e87c1453b05b467d2d02c2915fdfdd4af126145ff2e4610c \
--hash=sha256:3b570f84a6161cf8865c4e08adf629441f56e32f180f7aa4ccbd2e0a5a02cba2 \
--hash=sha256:463822e2f0d81459e113372a168f2ff59723e78528f91f0bd25680ac185cf797 \
--hash=sha256:4d98abdd6b1e3bf1a1cbb14c3895226816e666749ac040c4e2554231068c639b \
--hash=sha256:5afe6b237a0b81bd54b53f835a153770802f164c5570bab5e005aad693dab87f \
--hash=sha256:5b70110acb39f3aff6b74cf09bb4169b167e2660dabc304c1e25b6555fa781ef \
--hash=sha256:5cbf3e3b1014dddc45496e8cf38b9f099c95a326275885199f427825c6522232 \
--hash=sha256:624b977355cde8b065f6d51b98497d6cd5fbdd4f36405f7a8790e3376125e2bb \
--hash=sha256:63728564c1410d99e6d1ae8e3b810fe012bc440952168af0a2877e8ff5ab96b9 \
--hash=sha256:66cc56579fd91f517290ab02c51e3a80f581aba45fd924fcdee01fa06e635812 \
--hash=sha256:6c32cc3145928c4305d142ebec682419a6c0a8ce9e33db900027ddca1ec39178 \
--hash=sha256:8b56553c0345ad6dcb2e9b433ae47d67f95fc23fe28a0bde15a120f25257e291 \
--hash=sha256:8bb1e155a74e1bfbacd84555ea62fa21c58e0b4e7e6b20e4447b8d07990ac78b \
--hash=sha256:95d5ef984eff897850f3a83883363da64aae1000e79cb3c321915468e8c6add5 \
--hash=sha256:a013cbe25d20c2e0c4e85a9daf438f85121a4d0344ddc76e33fd7e3965d9af4b \
--hash=sha256:a787ab10d7bb5494e5f76536ac460741788f1fbce851068d73a87ca7c35fc3e1 \
--hash=sha256:a7d5e9fad90eff8f6f6106d3b98b553a88b6f976e51fce287192a5d2d5363713 \
--hash=sha256:aac00e4bc94d1b7813fe882c28990c1bc2f9d0e1aa765a5f2b516e8a6a16a9e4 \
--hash=sha256:b91c36492a4bbb1ee855b7d16fe51379e5f96b85692dc8210831fbb24c43e484 \
--hash=sha256:c03c07ed32c5324939b19e36ae5f75c660c81461e312a41aea30acdd46f93a7c \
--hash=sha256:c5236606e8570542ed424849f7852a0ff0bce2c4c8d0ba05cc202a5a9c97dee9 \
--hash=sha256:c6b39294464b03457f9064e98c124e09008b35a62e3189d3513e5148611c9388 \
--hash=sha256:cb7a09e173903541fa888ba010c345893cd9fc1b5891aaf060f6ca77b6a3722d \
--hash=sha256:d68cb92c408261f806b15923834203f024110a2e2872ecb0bd2a110f89d3c602 \
--hash=sha256:dc38f57d8f20f06dd7c3161c59ca2c86893632623f33a42d592f097b00f720a9 \
--hash=sha256:e98eca29a05913e82177b3ba3d198b1728e164869c613d76d0de4bde6768a50e \
--hash=sha256:f217c3954ce5fd88303fc0c317af55d5e0204106d86dea17eb8205700d47dec2
pillow==8.3.0 \
--hash=sha256:063d17a02a0170c2f880fbd373b2738b089c6adcbd1f7418667bc9e97524c11b \
--hash=sha256:1037288a22cc8ec9d2918a24ded733a1cc4342fd7f21d15d37e6bbe5fb4a7306 \
--hash=sha256:25f6564df21d15bcac142b4ed92b6c02e53557539f535f31c1f3bcc985484753 \
--hash=sha256:28f184c0a65be098af412f78b0b6f3bbafd1614e1dc896e810d8357342a794b7 \
--hash=sha256:3251557c53c1ed0c345559afc02d2b0a0aa5788042e161366ed90b27bc322d3d \
--hash=sha256:331f8321418682386e4f0d0e6369f732053f95abddd2af4e1b1ef74a9537ef37 \
--hash=sha256:333313bcc53a8a7359e98d5458dfe37bfa301da2fd0e0dc41f585ae0cede9181 \
--hash=sha256:34ce3d993cb4ca840b1e31165b38cb19c64f64f822a8bc5565bde084baff3bdb \
--hash=sha256:490c9236ef4762733b6c2e1f1fcb37793cb9c57d860aa84d6994c990461882e5 \
--hash=sha256:519b3b24dedc81876d893475bade1b92c4ce7c24b9b82224f0bd8daae682e039 \
--hash=sha256:53f6e4b73b3899015ac4aa95d99da0f48ea18a6d7c8db672e8bead3fb9570ef5 \
--hash=sha256:561339ed7c324bbcb29b5e4f4705c97df950785394b3ac181f5bf6a08088a672 \
--hash=sha256:6f7517a220aca8b822e25b08b0df9546701a606a328da5bc057e5f32a3f9b07c \
--hash=sha256:713b762892efa8cd5d8dac24d16ac2d2dbf981963ed1b3297e79755f03f8cbb8 \
--hash=sha256:72858a27dd7bd1c40f91c4f85db3b9f121c8412fd66573121febb00d074d0530 \
--hash=sha256:778a819c2d194e08d39d67ddb15ef0d32eba17bf7d0c2773e97bd221b2613a3e \
--hash=sha256:803606e206f3e366eea46b1e7ab4dac74cfac770d04de9c35319814e11e47c46 \
--hash=sha256:856fcbc3201a6cabf0478daa0c0a1a8a175af7e5173e2084ddb91cc707a09dd1 \
--hash=sha256:8f65d2a98f198e904dbe89ecb10862d5f0511367d823689039e17c4d011de11e \
--hash=sha256:94db5ea640330de0945b41dc77fb4847b4ab6e87149126c71b36b112e8400898 \
--hash=sha256:950e873ceefbd283cbe7bc5b648b832d1dcf89eeded6726ebec42bc7d67966c0 \
--hash=sha256:a7beda44f177ee602aa27e0a297da1657d9572679522c8fb8b336b734653516e \
--hash=sha256:aef0838f28328523e9e5f2c1852dd96fb85768deb0eb8f908c54dad0f44d2f6f \
--hash=sha256:b42ea77f4e7374a67e1f27aaa9c62627dff681f67890e5b8f0c1e21b1500d9d2 \
--hash=sha256:bccd0d604d814e9494f3bf3f077a23835580ed1743c5175581882e7dd1f178c3 \
--hash=sha256:c2d78c8230bda5fc9f6b1d457c7f8f3432f4fe85bed86f80ba3ed73d59775a88 \
--hash=sha256:c3529fb98a40f89269175442c5ff4ef81d22e91b2bdcbd33833a350709b5130c \
--hash=sha256:cc8e926d6ffa65d0dddb871b7afe117f17bc045951e66afde60eb0eba923db9e \
--hash=sha256:ce90aad0a3dc0f13a9ff0ab1f43bcbea436089b83c3fadbe37c6f1733b938bf1 \
--hash=sha256:cec702974f162026bf8de47f6f4b7ce9584a63c50002b38f195ee797165fea77 \
--hash=sha256:d9ef8119ce44f90d2f8ac7c58f7da480ada5151f217dc8da03681b73fc91dec3 \
--hash=sha256:eccaefbd646022b5313ca4b0c5f1ae6e0d3a52ef66de64970ecf3f9b2a1be751 \
--hash=sha256:fb91deb5121b6dde88599bcb3db3fdad9cf33ff3d4ccc5329ee1fe9655a2f7ff \
--hash=sha256:fc25d59ecf23ea19571065306806a29c43c67f830f0e8a121303916ba257f484
# via -r requirements.in
psycopg2-binary==2.9.1 \
--hash=sha256:0b7dae87f0b729922e06f85f667de7bf16455d411971b2043bbd9577af9d1975 \
Expand Down Expand Up @@ -712,8 +712,28 @@ pyparsing==2.4.7 \
--hash=sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1 \
--hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b
# via packaging
pyrsistent==0.17.3 \
--hash=sha256:2e636185d9eb976a18a8a8e96efce62f2905fea90041958d8cc2a189756ebf3e
pyrsistent==0.18.0 \
--hash=sha256:097b96f129dd36a8c9e33594e7ebb151b1515eb52cceb08474c10a5479e799f2 \
--hash=sha256:2aaf19dc8ce517a8653746d98e962ef480ff34b6bc563fc067be6401ffb457c7 \
--hash=sha256:404e1f1d254d314d55adb8d87f4f465c8693d6f902f67eb6ef5b4526dc58e6ea \
--hash=sha256:48578680353f41dca1ca3dc48629fb77dfc745128b56fc01096b2530c13fd426 \
--hash=sha256:4916c10896721e472ee12c95cdc2891ce5890898d2f9907b1b4ae0f53588b710 \
--hash=sha256:527be2bfa8dc80f6f8ddd65242ba476a6c4fb4e3aedbf281dfbac1b1ed4165b1 \
--hash=sha256:58a70d93fb79dc585b21f9d72487b929a6fe58da0754fa4cb9f279bb92369396 \
--hash=sha256:5e4395bbf841693eaebaa5bb5c8f5cdbb1d139e07c975c682ec4e4f8126e03d2 \
--hash=sha256:6b5eed00e597b5b5773b4ca30bd48a5774ef1e96f2a45d105db5b4ebb4bca680 \
--hash=sha256:73ff61b1411e3fb0ba144b8f08d6749749775fe89688093e1efef9839d2dcc35 \
--hash=sha256:772e94c2c6864f2cd2ffbe58bb3bdefbe2a32afa0acb1a77e472aac831f83427 \
--hash=sha256:773c781216f8c2900b42a7b638d5b517bb134ae1acbebe4d1e8f1f41ea60eb4b \
--hash=sha256:a0c772d791c38bbc77be659af29bb14c38ced151433592e326361610250c605b \
--hash=sha256:b29b869cf58412ca5738d23691e96d8aff535e17390128a1a52717c9a109da4f \
--hash=sha256:c1a9ff320fa699337e05edcaae79ef8c2880b52720bc031b219e5b5008ebbdef \
--hash=sha256:cd3caef37a415fd0dae6148a1b6957a8c5f275a62cca02e18474608cb263640c \
--hash=sha256:d5ec194c9c573aafaceebf05fc400656722793dac57f254cd4741f3c27ae57b4 \
--hash=sha256:da6e5e818d18459fa46fac0a4a4e543507fe1110e808101277c5a2b5bab0cd2d \
--hash=sha256:e79d94ca58fcafef6395f6352383fa1a76922268fa02caa2272fff501c2fdc78 \
--hash=sha256:f3ef98d7b76da5eb19c37fda834d50262ff9167c65658d1d8f974d2e4d90676b \
--hash=sha256:f4c8cabb46ff8e5d61f56a037974228e978f26bfefce4f61a4b1ac0ba7a2ab72
# via jsonschema
python-dateutil==2.8.1 \
--hash=sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c \
Expand Down Expand Up @@ -868,9 +888,9 @@ tzlocal==2.1 \
--hash=sha256:643c97c5294aedc737780a49d9df30889321cbe1204eac2c2ec6134035a92e44 \
--hash=sha256:e2cb6c6b5b604af38597403e9852872d7f534962ae2954c7f35efcb1ccacf4a4
# via rfc5424-logging-handler
urllib3==1.26.5 \
--hash=sha256:753a0374df26658f99d826cfe40394a686d05985786d946fbe4165b5148f5a7c \
--hash=sha256:a7acd0977125325f516bda9735fa7142b909a8d01e8b2e4c8108d0984e6e0098
urllib3==1.26.6 \
--hash=sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4 \
--hash=sha256:f57b4c16c62fa2760b7e3d97c35b255512fb6b59a259730f36ba32ce9f8e342f
# via
# requests
# selenium
Expand Down
26 changes: 26 additions & 0 deletions siteapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,32 @@ def test_create_portfolio_project(self):
self.click_element("#create-portfolio-button")
wait_for_sleep_after(lambda: self.assertRegex(self.browser.title, "Security Projects"))

def test_portfolio_projects(self):
"""
Ensure key parts of the portfolio page
"""
# Login as authenticated user
self.client.force_login(user=self.user)
# Reset login
self.browser.get(self.url("/accounts/logout/"))
self._login()
# If the above is not done a new project cannot be created
self._new_project()

portfolio_id = Project.objects.last().portfolio.id
url = reverse('portfolio_projects', args=[portfolio_id])
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'portfolios/detail.html')
self.assertContains(response, 'Owner', 1)
# Context
bool_context_objects = ["can_invite_to_portfolio", "can_edit_portfolio"]
for context in bool_context_objects:
self.assertEqual(response.context[context], True)

self.assertEqual(response.context["portfolio"].id, portfolio_id)


def test_grant_portfolio_access(self):
# Grant another member access to portfolio
self._login()
Expand Down
20 changes: 12 additions & 8 deletions siteapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from django.utils import timezone
from django.views.decorators.http import require_http_methods
from django.views.generic import ListView
from guardian.core import ObjectPermissionChecker
from guardian.decorators import permission_required_or_403
from guardian.shortcuts import get_perms_for_model, get_perms, assign_perm

Expand Down Expand Up @@ -156,7 +157,7 @@ def subvars(s):
if settings.OKTA_CONFIG:
return HttpResponseRedirect("/oidc/authenticate")
return render(request, "index.html", {
"hide_registration": SystemSettings.hide_registration,
"hide_registration": SystemSettings.hide_registration,
"sitename": Sitename.objects.last(),
"signup_form": signup_form,
"login_form": login_form,
Expand Down Expand Up @@ -1889,20 +1890,23 @@ def g(request, pk):
def portfolio_projects(request, pk):
"""List of projects within a portfolio"""
portfolio = Portfolio.objects.get(pk=pk)
projects = Project.objects.filter(portfolio=portfolio).select_related('root_task') \
projects = Project.objects.filter(portfolio=portfolio).select_related('root_task').prefetch_related('portfolio') \
.exclude(is_organization_project=True).order_by('-created')
user_projects = [project for project in projects if request.user.has_perm('view_project', project)]
# # Prefetch the permissions
perm_checker = ObjectPermissionChecker(request.user)
perm_checker.prefetch_perms(projects)

user_projects = [project for project in projects if perm_checker.has_perm('view_project', project)]
anonymous_user = User.objects.get(username='AnonymousUser')
users_with_perms = portfolio.users_with_perms()

return render(request, "portfolios/detail.html", {
"portfolio": portfolio,
"projects": projects if request.user.has_perm('view_portfolio', portfolio) else user_projects,
"can_invite_to_portfolio": request.user.has_perm('can_grant_portfolio_owner_permission', portfolio),
"can_edit_portfolio": request.user.has_perm('change_portfolio', portfolio),
"send_invitation": Invitation.form_context_dict(request.user, portfolio, [request.user, anonymous_user]),
"projects": projects if perm_checker.has_perm('view_portfolio', portfolio) else user_projects,
"can_invite_to_portfolio": perm_checker.has_perm('can_grant_portfolio_owner_permission', portfolio),
"can_edit_portfolio": perm_checker.has_perm('change_portfolio', portfolio),
"send_invitation": Invitation.form_context_dict(perm_checker, portfolio, [request.user, anonymous_user]),
"users_with_perms": users_with_perms,
"display_users_with_perms": len(users_with_perms),
})


Expand Down
20 changes: 12 additions & 8 deletions templates/components/compare_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ <h2 class="sub-header">Compared components</h2>
</tr>
</thead>
<tbody>
{% for cmp_name, smt, diff in comp_differences %}
<tr>
<td scope="row" style="width: 110px;"><b>{{ cmp_name }}</b></td>
<td style="width: 90px;">{{ smt.sid }}{% if smt.pid %}.{{ smt.pid }}{% endif %}</td>
<td style="width: 190px;">{{ smt.sid_class }}</td>
<td><a href="#diff_{{ forloop.counter }}" class="" data-toggle="collapse" style="text-decoration: none;font-weight: normal; font-size: 9pt; color: black;">{{ diff|safe }}</a></td>
</tr>
{% endfor %}

{% for comp_id, cmp_name, smt, diff in comp_differences %}

<tr>
<td scope="row" style="width: 110px;"><b>{{ cmp_name }}</b></td>
<td style="width: 90px;">{{ smt.sid }}{% if smt.pid %}.{{ smt.pid }}{% endif %}</td>
<td style="width: 190px;">{{ smt.sid_class }}</td>
<td><a href="#diff_{{ forloop.counter }}" class="" data-toggle="collapse" style="text-decoration: none;font-weight: normal; font-size: 9pt; color: black;">{{ diff|safe }}{{ id_list }}</a></td>
</tr>

{% endfor %}

</tbody>
</table>
</div>
Expand Down
Loading

0 comments on commit aa354be

Please sign in to comment.