Skip to content

Commit

Permalink
Merge 89c8ddd into 73632a1
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurek committed Sep 8, 2014
2 parents 73632a1 + 89c8ddd commit ee21c21
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/ralph/account/views.py
Expand Up @@ -57,10 +57,6 @@ class BaseUser(Base):
submodule_name = 'user_preference'
module_name = 'user_preference'

@ralph_permission([])
def dispatch(self, *args, **kwargs):
return super(TemplateView, self).dispatch(*args, **kwargs)

def get_sidebar_items(self):
has_perm = self.request.user.get_profile().has_perm
preferences = [(
Expand Down
4 changes: 0 additions & 4 deletions src/ralph/ui/views/common.py
Expand Up @@ -221,16 +221,12 @@ def dispatch(self, request, *args, **kwargs):
if 'ralph.cmdb' in settings.INSTALLED_APPS:
from ralph.cmdb.menu import menu_class as cmdb_menu
self.menus.append(cmdb_menu(request))
profile = request.user.get_profile()
has_perm = profile.has_perm
if request.user.is_staff:
self.menus.append(AdminMenu(request))
self.menus.append(UserMenu(request))
for app in pluggableapp.app_dict.values():
if not isinstance(app, RalphModule):
continue
if not has_perm(app.required_permission):
continue
menu_module = importlib.import_module(
'.'.join([app.module_name, 'menu'])
)
Expand Down
7 changes: 7 additions & 0 deletions src/ralph/util/api_pricing.py
Expand Up @@ -125,6 +125,7 @@ def get_virtual_usages(parent_venture_name=None):
yield {
'name': device.name,
'device_id': device.id,
'venture_id': device.venture_id,
'service_ci_uid': device.service.uid if device.service else None,
'environment': device.device_environment,
'hypervisor_id': device.parent.id,
Expand Down Expand Up @@ -383,12 +384,17 @@ def get_services():
"""
service_type = CIType.objects.get(name='Service')
profit_center_type = CIType.objects.get(name='ProfitCenter')
environment_type = CIType.objects.get(name='Environment')
for service in CI.objects.filter(
type=service_type
).select_related('relations'):
profit_center = service.child.filter(
parent__type=profit_center_type
).values_list('parent__uid', flat=True)
# TODO: verify relation
environments = service.parent.filter(
child__type=environment_type,
)
yield {
'ci_uid': service.uid,
'name': service.name,
Expand All @@ -401,4 +407,5 @@ def get_services():
'id',
flat=True,
)),
'environments': [e.child.id for e in environments]
}
8 changes: 7 additions & 1 deletion src/ralph/util/tests/tests.py
Expand Up @@ -215,7 +215,7 @@ def test_get_owners(self):
def test_get_services(self):
service = utils.ServiceFactory()
profit_center = utils.ProfitCenterFactory()
utils.ServiceBusinessLineRelationFactory(
utils.ServiceProfitCenterRelationFactory(
parent=profit_center,
child=service,
)
Expand All @@ -229,13 +229,18 @@ def test_get_services(self):
ci=service,
type=models_ci.CIOwnershipType.technical,
)
environments = utils.ServiceEnvironmentRelationFactory.create_batch(
2,
parent=service,
)
result = [a for a in api_pricing.get_services()]
service_dict = {
'name': service.name,
'ci_uid': service.uid,
'profit_center': profit_center.uid,
'business_owners': [bo.owner.id for bo in business_ownership],
'technical_owners': [to.owner.id for to in technical_ownership],
'environments': [e.child.id for e in environments],
}
self.assertEquals(result, [service_dict])

Expand All @@ -248,6 +253,7 @@ def test_get_services_without_profit_center(self):
'profit_center': None,
'technical_owners': [],
'business_owners': [],
'environments': [],
}
self.assertEquals(result, [service_dict])

Expand Down
18 changes: 16 additions & 2 deletions src/ralph/util/tests/utils.py
Expand Up @@ -31,6 +31,12 @@ def type(self):
return models_ci.CIType.objects.get(name='Service')


class EnvironmentFactory(CIFactory):
@factory.lazy_attribute
def type(self):
return models_ci.CIType.objects.get(name='Environment')


class CIOwnerFactory(DjangoModelFactory):
FACTORY_FOR = models_ci.CIOwner
first_name = 'Some'
Expand All @@ -45,9 +51,17 @@ class ServiceOwnershipFactory(DjangoModelFactory):
ci = factory.SubFactory(ServiceFactory)


class ServiceBusinessLineRelationFactory(DjangoModelFactory):
class ServiceEnvironmentRelationFactory(DjangoModelFactory):
FACTORY_FOR = models_ci.CIRelation
parent = factory.SubFactory(ServiceFactory)
child = factory.SubFactory(EnvironmentFactory)
type = models_ci.CI_RELATION_TYPES.HASROLE
readonly = False


class ServiceProfitCenterRelationFactory(DjangoModelFactory):
FACTORY_FOR = models_ci.CIRelation
parent = factory.SubFactory(BusinessLineFactory)
parent = factory.SubFactory(ProfitCenterFactory)
child = factory.SubFactory(ServiceFactory)
type = models_ci.CI_RELATION_TYPES.CONTAINS
readonly = False

0 comments on commit ee21c21

Please sign in to comment.