Skip to content

Commit

Permalink
Merge pull request #3758 from lukaszkarykowski/accept_asset_team/test
Browse files Browse the repository at this point in the history
HAL-2220 | new system to accept released assets to status in use team and test
  • Loading branch information
jetalone85 authored May 15, 2023
2 parents 84e9a1d + 56775d1 commit 52ba954
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
43 changes: 42 additions & 1 deletion src/ralph/accounts/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
ACCEPTANCE_BACK_OFFICE_RETURN_STATUS = settings.ACCEPT_ASSETS_FOR_CURRENT_USER_CONFIG['BACK_OFFICE_ACCEPT_RETURN_STATUS'] # noqa: E509
ACCEPTANCE_ACCESS_CARD_TRANSITION_ID = settings.ACCEPT_ASSETS_FOR_CURRENT_USER_CONFIG['TRANSITION_ACCESS_CARD_ID'] # noqa: E509
ACCEPTANCE_ACCESS_CARD_ACCEPT_STATUS = settings.ACCEPT_ASSETS_FOR_CURRENT_USER_CONFIG['ACCESS_CARD_ACCEPT_ACCEPT_STATUS'] # noqa: E509
ACCEPTANCE_BACK_OFFICE_TEAM_ACCEPT_STATUS = settings.ACCEPT_ASSETS_FOR_CURRENT_USER_CONFIG['BACK_OFFICE_TEAM_ACCEPT_STATUS'] # noqa: E509
ACCEPTANCE_TEAM_ACCEPT_TRANSITION_ID = settings.ACCEPT_ASSETS_FOR_CURRENT_USER_CONFIG['TRANSITION_TEAM_ACCEPT_ID'] # noqa: E509
ACCEPTANCE_BACK_OFFICE_TEST_ACCEPT_STATUS = settings.ACCEPT_ASSETS_FOR_CURRENT_USER_CONFIG['BACK_OFFICE_TEST_ACCEPT_STATUS'] # noqa: E509
ACCEPTANCE_TEST_ACCEPT_TRANSITION_ID = settings.ACCEPT_ASSETS_FOR_CURRENT_USER_CONFIG['TRANSITION_TEST_ACCEPT_ID'] # noqa: E509


def transition_exists(transition_id):
Expand All @@ -40,6 +44,12 @@ def transition_exists(transition_id):
acceptance_access_card_transition_exists = partial(
transition_exists, ACCEPTANCE_ACCESS_CARD_TRANSITION_ID
)
acceptance_team_asset_transition_exists = partial(
transition_exists, ACCEPTANCE_TEAM_ACCEPT_TRANSITION_ID
)
acceptance_test_asset_transition_exists = partial(
transition_exists, ACCEPTANCE_TEST_ACCEPT_TRANSITION_ID
)


def get_assets(user, status):
Expand All @@ -64,7 +74,6 @@ def get_access_cards(user, status):
get_assets_to_accept = partial(
get_assets, status=ACCEPTANCE_BACK_OFFICE_ACCEPT_STATUS
)

get_simcards_to_accept = partial(
get_simcards, status=ACCEPTANCE_SIMCARD_ACCEPT_STATUS
)
Expand All @@ -77,6 +86,12 @@ def get_access_cards(user, status):
get_access_cards_to_accept = partial(
get_access_cards, status=ACCEPTANCE_ACCESS_CARD_ACCEPT_STATUS
)
get_team_assets_to_accept = partial(
get_assets, status=ACCEPTANCE_BACK_OFFICE_TEAM_ACCEPT_STATUS
)
get_test_assets_to_accept = partial(
get_assets, status=ACCEPTANCE_BACK_OFFICE_TEST_ACCEPT_STATUS
)


def get_acceptance_url(user):
Expand Down Expand Up @@ -142,3 +157,29 @@ def get_access_card_acceptance_url(user):
query = urlencode([('select', a.id) for a in assets_to_accept])
return '?'.join((url, query))
return None


def get_team_asset_acceptance_url(user):
assets_to_accept = get_team_assets_to_accept(user)
admin_instance = ralph_site.get_admin_instance_for_model(
BackOfficeAsset
)
url_name = admin_instance.get_transition_bulk_url_name()
if assets_to_accept:
url = reverse(url_name, args=(ACCEPTANCE_TEAM_ACCEPT_TRANSITION_ID,))
query = urlencode([('select', a.id) for a in assets_to_accept])
return '?'.join((url, query))
return None


def get_test_asset_acceptance_url(user):
assets_to_accept = get_test_assets_to_accept(user)
admin_instance = ralph_site.get_admin_instance_for_model(
BackOfficeAsset
)
url_name = admin_instance.get_transition_bulk_url_name()
if assets_to_accept:
url = reverse(url_name, args=(ACCEPTANCE_TEST_ACCEPT_TRANSITION_ID,))
query = urlencode([('select', a.id) for a in assets_to_accept])
return '?'.join((url, query))
return None
38 changes: 37 additions & 1 deletion src/ralph/admin/templatetags/dashboard_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
get_loan_acceptance_url,
get_return_acceptance_url,
get_simcard_acceptance_url,
get_simcards_to_accept
get_simcards_to_accept,
get_team_asset_acceptance_url,
get_team_assets_to_accept,
get_test_asset_acceptance_url,
get_test_assets_to_accept

)
from ralph.assets.models import BaseObject, Service, ServiceEnvironment
from ralph.back_office.models import BackOfficeAsset
Expand Down Expand Up @@ -106,6 +111,30 @@ def get_user_equipment_to_accept_return_tile_data(user):
}


def get_user_team_equipment_to_accept_tile_data(user):
assets_to_accept_count = get_team_assets_to_accept(user).count()
if not assets_to_accept_count:
return None
return {
'class': 'team-equipment-to-accept',
'label': _('Team hardware pick up'),
'count': assets_to_accept_count,
'url': get_team_asset_acceptance_url(user),
}


def get_user_test_equipment_to_accept_tile_data(user):
assets_to_accept_count = get_test_assets_to_accept(user).count()
if not assets_to_accept_count:
return None
return {
'class': 'test-equipment-to-accept',
'label': _('Test hardware pick up'),
'count': assets_to_accept_count,
'url': get_test_asset_acceptance_url(user),
}


def get_available_space_in_data_centers(data_centers):
available = Rack.objects.filter(
server_room__data_center__in=data_centers,
Expand Down Expand Up @@ -219,6 +248,13 @@ def ralph_summary(context):
accept_for_return_tile_data = get_user_equipment_to_accept_return_tile_data(user=user) # noqa
if accept_for_return_tile_data:
results.append(accept_for_return_tile_data)
accept_for_team_asset_tile_data = get_user_team_equipment_to_accept_tile_data(user=user) # noqa
if accept_for_team_asset_tile_data:
results.append(accept_for_team_asset_tile_data)
accept_for_test_asset_tile_data = get_user_test_equipment_to_accept_tile_data(user=user) # noqa
if accept_for_test_asset_tile_data:
results.append(accept_for_test_asset_tile_data)

return {'results': results}


Expand Down
12 changes: 12 additions & 0 deletions src/ralph/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,18 @@ def get_sentinels(sentinels_string):
'BACK_OFFICE_ACCEPT_RETURN_STATUS': os.environ.get(
'RETURN_ASSESTS_FOR_CURRENT_USER_BACK_OFFICE_ACCEPT_STATUS', 14
),
'BACK_OFFICE_TEAM_ACCEPT_STATUS': os.environ.get(
'ACCEPT_TEAM_ASSETS_FOR_CURRENT_USER_BACK_OFFICE_ACCEPT_STATUS', 103
),
'TRANSITION_TEAM_ACCEPT_ID': os.environ.get(
'ACCEPT_TEAM_ASSETS_FOR_CURRENT_USER_TRANSITION_ID', None
),
'BACK_OFFICE_TEST_ACCEPT_STATUS': os.environ.get(
'ACCEPT_TEST_ASSETS_FOR_CURRENT_USER_BACK_OFFICE_ACCEPT_STATUS', 105
),
'TRANSITION_TEST_ACCEPT_ID': os.environ.get(
'ACCEPT_TEST_ASSETS_FOR_CURRENT_USER_TRANSITION_ID', None
),
}
RELEASE_REPORT_CONFIG = {
# report with name 'release' is by default
Expand Down

0 comments on commit 52ba954

Please sign in to comment.