Skip to content

Commit

Permalink
Merge 4b5067f into 2a27873
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaboiangiu committed Nov 2, 2018
2 parents 2a27873 + 4b5067f commit 6f8a4f1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
17 changes: 10 additions & 7 deletions insitu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,32 @@ def check_owner_user(self, *args, **kwargs):
"""
Check if the user is the creator or if the is user is in the creator's
team
:param args:
:param kwargs:
:return:
"""
return (
self.requesting_user == self.created_by or
self.requesting_user in self.created_by.team.teammates.all()
)

@transition_check('validate', 'request_changes')
@transition_check('request_changes',)
def check_other_user(self, *args, **kwargs):
"""
Check if the user is different from the creator or if the is user is
not in the creator's team
:param args:
:param kwargs:
:return:
"""
return (
self.requesting_user != self.created_by and
self.requesting_user not in self.created_by.team.teammates.all()
)

@transition_check('validate',)
def check_validator_user(self, *args, **kwargs):
"""
Check if the user is the creator
"""
return (
self.requesting_user == self.created_by or
self.requesting_user not in self.created_by.team.teammates.all()
)

class Team(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE,
Expand Down
2 changes: 1 addition & 1 deletion insitu/templates/_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{% block head %}
{% endblock %}
<link rel="shortcut icon" href="{% static "/images/favicon.png" %}" type="image/x-icon" />
<link rel="shortcut icon" href="{% static 'images/favicon.png' %}" type="image/x-icon" />

<title>
{% block title %}
Expand Down
5 changes: 5 additions & 0 deletions insitu/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def test_transition(self):
{'source': 'changes', 'target': 'draft', 'user': self.creator},
{'source': 'draft', 'target': 'ready', 'user': self.creator},
{'source': 'ready', 'target': 'valid', 'user': self.other_user},
{'source': 'ready', 'target': 'valid', 'user': self.creator},
]

for transition in transitions:
Expand All @@ -307,6 +308,10 @@ def test_transition(self):
for item in items:
getattr(item, 'refresh_from_db')()
self.assertEqual((getattr(item, 'state')).name, transition['target'])
if transition['target'] == 'valid':
for item in items:
item.state = transition['source']
item.save()
self.logging(check_username=False)

def test_transition_with_draft_data(self):
Expand Down
5 changes: 5 additions & 0 deletions insitu/tests/test_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def test_transition(self):
{'source': 'changes', 'target': 'draft', 'user': self.creator},
{'source': 'draft', 'target': 'ready', 'user': self.creator},
{'source': 'ready', 'target': 'valid', 'user': self.other_user},
{'source': 'ready', 'target': 'valid', 'user': self.creator},
]

for transition in transitions:
Expand All @@ -268,6 +269,10 @@ def test_transition(self):
getattr(item, 'refresh_from_db')()
self.assertEqual((getattr(item, 'state')).name,
transition['target'])
if transition['target'] == 'valid':
for item in items:
item.state = transition['source']
item.save()
self.logging(check_username=False)

def test_transition_with_draft_data(self):
Expand Down
2 changes: 1 addition & 1 deletion insitu/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setUp(self):

def test_create_product_fields_required(self):
data = {}
resp = self.client.post(reverse('product:add'), data)
resp = self.client.post(reverse('product:add'), data, follow=True)
self.check_required_errors(resp, self.errors)

def test_get_create_product(self):
Expand Down
5 changes: 5 additions & 0 deletions insitu/tests/test_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def test_transition(self):
{'source': 'changes', 'target': 'draft', 'user': self.creator},
{'source': 'draft', 'target': 'ready', 'user': self.creator},
{'source': 'ready', 'target': 'valid', 'user': self.other_user},
{'source': 'ready', 'target': 'valid', 'user': self.creator},
]

for transition in transitions:
Expand All @@ -293,6 +294,10 @@ def test_transition(self):
for item in items:
getattr(item, 'refresh_from_db')()
self.assertEqual((getattr(item, 'state')).name, transition['target'])
if transition['target'] == 'valid':
for item in items:
item.state = transition['source']
item.save()
self.logging(check_username=False)

def test_transition_with_draft_data(self):
Expand Down
4 changes: 3 additions & 1 deletion insitu/views/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
ProtectedView,
ProtectedTemplateView, ProtectedDetailView,
ProtectedUpdateView, ProtectedCreateView,
ProtectedDeleteView)
ProtectedDeleteView,
LoggingProtectedCreateView,
)
from insitu.views.protected.permissions import (
IsAuthenticated,
IsSuperuser,
Expand Down

0 comments on commit 6f8a4f1

Please sign in to comment.