Skip to content

Commit

Permalink
refactor: change to not archiving when the plugin is deleted.
Browse files Browse the repository at this point in the history
Signed-off-by: Jongmin Kim <[email protected]>
  • Loading branch information
whdalsrnt committed Dec 22, 2021
1 parent d02d353 commit 4d019c2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
38 changes: 3 additions & 35 deletions src/spaceone/repository/model/plugin_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Plugin(MongoModel):
name is unique per domain
"""
plugin_id = StringField(max_length=255, unique=True)
name = StringField(max_length=255)
state = StringField(max_length=40, default='ENABLED', choices=('ENABLED', 'DISABLED', 'DELETED'))
name = StringField(max_length=255, unique_with='domain_id')
state = StringField(max_length=40, default='ENABLED', choices=('ENABLED', 'DISABLED'))
image = StringField(max_length=255)
registry_type = StringField(max_length=255, default='DOCKER_HUB')
registry_config = DictField()
Expand All @@ -36,7 +36,6 @@ class Plugin(MongoModel):
domain_id = StringField(max_length=255)
created_at = DateTimeField(auto_now_add=True)
updated_at = DateTimeField(auto_now=True)
deleted_at = DateTimeField(default=None, null=True)

meta = {
'updatable_fields': [
Expand All @@ -47,8 +46,7 @@ class Plugin(MongoModel):
'capability',
'repository_id',
'labels',
'tags',
'deleted_at'
'tags'
],
'minimal_fields': [
'plugin_id',
Expand Down Expand Up @@ -79,33 +77,3 @@ class Plugin(MongoModel):
('tags.key', 'tags.value')
]
}

@queryset_manager
def objects(doc_cls, queryset):
return queryset.filter(state__ne='DELETED')

@classmethod
def create(cls, data):
""" Unique per domain
"""
plugin_vos = cls.filter(name=data['name'], domain_id=data['domain_id'])
if plugin_vos.count() > 0:
raise ERROR_NOT_UNIQUE(key='name', value=data['name'])

return super().create(data)

def update(self, data):
""" Unique per domain
"""
if 'name' in data:
plugin_vos = self.filter(name=data['name'], domain_id=data['domain_id'], plugin_id__ne=self.plugin_id)
if plugin_vos.count() > 0:
raise ERROR_NOT_UNIQUE(key='name', value=data['name'])

return super().update(data)

def delete(self):
self.update({
'state': 'DELETED',
'deleted_at': datetime.utcnow()
})
2 changes: 1 addition & 1 deletion src/spaceone/repository/model/policy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PolicyTag(EmbeddedDocument):
class Policy(MongoModel):
policy_id = StringField(max_length=255, required=True, unique=True)
name = StringField(max_length=255, unique_with='domain_id')
state = StringField(max_length=40, default='ENABLED', choices=('ENABLED', 'DISABLED', 'DELETED'))
state = StringField(max_length=40, default='ENABLED', choices=('ENABLED', 'DISABLED'))
permissions = ListField(StringField())
labels = ListField(StringField(max_length=255))
tags = ListField(EmbeddedDocumentField(PolicyTag))
Expand Down
1 change: 0 additions & 1 deletion test/factory/plugin_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ class Meta:
domain_id = utils.generate_id('domain')
created_at = factory.Faker('date_time')
updated_at = factory.Faker('date_time')
deleted_at = None

0 comments on commit 4d019c2

Please sign in to comment.