Commit 6f1b9c1c authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add _credential_deleted field to CredentialState

parent c107d39a
# Generated by Django 2.1.3 on 2018-11-07 16:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0015_credentialstate_state_target'),
]
operations = [
migrations.AddField(
model_name='credentialstate',
name='_credential_deleted',
field=models.BooleanField(default=False),
),
]
......@@ -622,6 +622,7 @@ class CredentialState(models.Model):
choices=TARGET_CHOICES,
default=NOT_DEPLOYED
)
state = models.CharField(
max_length=50,
choices=STATE_CHOICES,
......@@ -634,6 +635,10 @@ class CredentialState(models.Model):
on_delete=models.CASCADE,
)
_credential_deleted = models.BooleanField(
default=False,
)
target = models.ForeignKey(
NewDeploymentStateItem,
related_name='credential_states',
......@@ -661,12 +666,31 @@ class CredentialState(models.Model):
return new_state
def set_target(self, target):
if self._credential_deleted:
LOGGER.debug(self.msg('Unable to change state_target of credential marked for deletion'))
return
self.state_target = target
self.save()
if settings.DEBUG_CREDENTIALS:
LOGGER.debug(self.msg('State target changed to {}'.format(target)))
def set(self, state):
self.state = state
self.save()
if settings.DEBUG_CREDENTIALS:
LOGGER.debug(self.msg('State changed to {}'.format(state)))
def credential_deleted(self):
self.state_target = NOT_DEPLOYED
self._credential_deleted = True
self.save()
if settings.DEBUG_CREDENTIALS:
LOGGER.debug(self.msg('Credential marked as deleted'))
def msg(self, message):
return self.target.msg('Credential {}: {}'.format(self.credential, message))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment