Skip to content

Commit

Permalink
shipper: add a maintainer API endpoint to enable/disable builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswpark committed Jun 29, 2021
1 parent 6fdf7f0 commit 387a9c5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shipper/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
path('maintainers/api/token_check/', maintainer_api_token_check, name='maintainer_api_token_check'),
path('maintainers/api/chunked_upload/', ChunkedBuildUpload.as_view(), name='chunked_build_upload'),
path('maintainers/api/chunked_upload/<uuid:pk>/', ChunkedBuildUpload.as_view(), name='chunkedupload-detail'),
path('maintainers/api/build/enabled_status_modify/', maintainer_api_build_enabled_status_modify,
name='maintainer_api_build_enabled_status_modify'),
]
47 changes: 47 additions & 0 deletions shipper/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,53 @@ def maintainer_api_token_check(request):
)


@csrf_exempt
@api_view(["GET"])
def maintainer_api_build_enabled_status_modify(request):
build_id = request.data.get("build_id")
enable = bool(request.data.get("enable"))
if build_id is None or enable is None:
return Response(
{
'error': 'missing_parameters',
'message': 'One or more of the required parameters is blank! Required parameters: build ID, '
'enabled flag'
},
status=HTTP_400_BAD_REQUEST
)

build = get_object_or_404(Build, pk=build_id)

# Check if maintainer has permission to modify this build/device
if request.user not in build.device.maintainers.all():
return Response(
{
'error': 'insufficient_permissions',
'message': 'You are not authorized to modify builds associated with this device!'
},
status=HTTP_401_UNAUTHORIZED
)

# Switch build status
build.enabled = enable
build.save()

if enable:
return Response(
{
'message': 'Successfully enabled the build!'
},
status=HTTP_200_OK
)
else:
return Response(
{
'message': 'Successfully disabled the build!'
},
status=HTTP_200_OK
)


def get_codename_from_filename(filename):
fields = os.path.splitext(filename)[0].split('-')
# Check field count
Expand Down

0 comments on commit 387a9c5

Please sign in to comment.