2023-06-16 18:07:48 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2023 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License")
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2024-08-14 22:22:59 +03:00
|
|
|
from chromestatus_openapi.models import (
|
|
|
|
FeatureLinksResponse,
|
|
|
|
FeatureLinksSample,
|
|
|
|
FeatureLinksSummaryResponse,
|
|
|
|
)
|
|
|
|
|
|
|
|
from framework import basehandlers, permissions
|
2023-06-16 18:07:48 +03:00
|
|
|
from internals.core_enums import *
|
|
|
|
from internals.core_models import FeatureEntry
|
2024-08-14 22:22:59 +03:00
|
|
|
from internals.feature_links import (
|
|
|
|
get_by_feature_id,
|
|
|
|
get_feature_links_samples,
|
|
|
|
get_feature_links_summary,
|
|
|
|
)
|
|
|
|
|
2023-06-16 18:07:48 +03:00
|
|
|
|
|
|
|
class FeatureLinksAPI(basehandlers.APIHandler):
|
|
|
|
"""FeatureLinksAPI will return the links and its information to the client."""
|
|
|
|
|
2023-06-30 14:34:28 +03:00
|
|
|
def get_feature_links(self, feature_id: int, update_stale_links: bool):
|
2023-06-16 18:07:48 +03:00
|
|
|
feature = FeatureEntry.get_by_id(feature_id)
|
|
|
|
if not feature:
|
|
|
|
self.abort(404, msg='Feature not found')
|
2023-08-04 06:41:15 +03:00
|
|
|
return get_by_feature_id(feature_id, update_stale_links)
|
2023-06-16 18:07:48 +03:00
|
|
|
|
|
|
|
def do_get(self, **kwargs):
|
|
|
|
|
|
|
|
feature_id = self.get_int_arg('feature_id', None)
|
2023-06-30 14:34:28 +03:00
|
|
|
update_stale_links = self.get_bool_arg('update_stale_links', True)
|
2023-06-16 18:07:48 +03:00
|
|
|
if feature_id:
|
2023-06-30 14:34:28 +03:00
|
|
|
data, has_stale_links = self.get_feature_links(
|
|
|
|
feature_id, update_stale_links)
|
2024-08-14 22:22:59 +03:00
|
|
|
return FeatureLinksResponse.from_dict({
|
2023-06-30 14:34:28 +03:00
|
|
|
"data": data,
|
|
|
|
"has_stale_links": has_stale_links
|
2024-08-14 22:22:59 +03:00
|
|
|
})
|
2023-06-16 18:07:48 +03:00
|
|
|
else:
|
|
|
|
self.abort(400, msg='Missing feature_id')
|
2023-08-04 06:41:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
class FeatureLinksSummaryAPI(basehandlers.APIHandler):
|
2023-08-29 17:21:21 +03:00
|
|
|
"""FeatureLinksSummaryAPI will return summary of links to the client."""
|
2023-08-04 06:41:15 +03:00
|
|
|
|
|
|
|
@permissions.require_admin_site
|
|
|
|
def do_get(self, **kwargs):
|
2024-08-14 22:22:59 +03:00
|
|
|
return FeatureLinksSummaryResponse.from_dict(get_feature_links_summary())
|
2023-08-29 17:21:21 +03:00
|
|
|
|
|
|
|
class FeatureLinksSamplesAPI(basehandlers.APIHandler):
|
|
|
|
"""FeatureLinksSamplesAPI will return sample links to the client."""
|
|
|
|
|
|
|
|
@permissions.require_admin_site
|
|
|
|
def do_get(self, **kwargs):
|
|
|
|
domain = self.request.args.get('domain', None)
|
|
|
|
type = self.request.args.get('type', None)
|
|
|
|
is_error = self.get_bool_arg('is_error', None)
|
|
|
|
if domain:
|
2024-08-25 21:30:07 +03:00
|
|
|
return FeatureLinksSample.from_dict(get_feature_links_samples(domain, type, is_error))
|