-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a table to keep product channel versions and APIs to update them #1465
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
rendered_hook_payload, | ||
) | ||
from shipit_api.common.config import HG_PREFIX, PROJECT_NAME, PULSE_ROUTE_REBUILD_PRODUCT_DETAILS, SCOPE_PREFIX | ||
from shipit_api.common.models import DisabledProduct, Phase, Release, Signoff, XPIRelease | ||
from shipit_api.common.models import DisabledProduct, Phase, Release, Signoff, Version, XPIRelease | ||
from shipit_api.public.api import get_disabled_products, list_releases | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -375,3 +375,55 @@ def get_signoff_emails(phases): | |
additional_shipit_emails.update({signoff.completed_by for signoff in _phase.signoffs if signoff.completed_by is not None}) | ||
|
||
return list(additional_shipit_emails) | ||
|
||
|
||
def get_product_channel_version(product, channel): | ||
version = Version.query.filter_by(product_name=product, product_channel=channel).first() | ||
if version: | ||
return version.current_version | ||
else: | ||
return {"error": f"No version found for {product} {channel}."}, 404 | ||
|
||
|
||
def update_product_channel_version(product, channel, body): | ||
required_permission = f"{SCOPE_PREFIX}/update_product_channel_version/{product}" | ||
if not current_user.has_permissions(required_permission): | ||
user_permissions = ", ".join(current_user.get_permissions()) | ||
abort(401, f"required permission: {required_permission}, user permissions: {user_permissions}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: What's the difference between aborting and returning an error? |
||
version = Version.query.filter_by(product_name=product, product_channel=channel).first() | ||
if version and version.current_version != body["version"]: | ||
version.current_version = body["version"] | ||
current_app.db.session.commit() | ||
logger.info(f"Regenerating product details after updating {version.product_name} {version.product_channel} version to {version.current_version}") | ||
_rebuild_product_details({}) | ||
notify_via_matrix(product, f"Updated {version.product_name} {version.product_channel} version to `{version.current_version}`.") | ||
return { | ||
"message": f"The version for {product} {channel} was updated successfully.", | ||
"version": version.current_version, | ||
"product": version.product_name, | ||
"channel": version.product_channel, | ||
}, 200 | ||
elif version and version.current_version == body["version"]: | ||
return {"error": f"The {product} {channel} version is already {body['version']}!"}, 409 | ||
else: | ||
return {"error": f"No version found for {product} {channel}."}, 404 | ||
|
||
|
||
def create_product_channel_version(product, channel, body): | ||
required_permission = f"{SCOPE_PREFIX}/create_product_channel_version/{product}" | ||
if not current_user.has_permissions(required_permission): | ||
user_permissions = ", ".join(current_user.get_permissions()) | ||
abort(401, f"required permission: {required_permission}, user permissions: {user_permissions}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
existing_version = Version.query.filter_by(product_name=product, product_channel=channel).first() | ||
if existing_version: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could improve readability here:
|
||
return {"error": f"A {product} {channel} version already exists."}, 409 | ||
else: | ||
new_version = Version(product_name=product, product_channel=channel, current_version=body["version"]) | ||
current_app.db.session.add(new_version) | ||
current_app.db.session.commit() | ||
return { | ||
"message": f"A {product} {channel} version was created successfully.", | ||
"version": new_version.current_version, | ||
"product": new_version.product_name, | ||
"channel": new_version.product_channel, | ||
}, 201 |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -99,7 +99,8 @@ | |||||||||||||||||||
AUTH0_AUTH_SCOPES = assign_ldap_groups_to_scopes() | ||||||||||||||||||||
|
||||||||||||||||||||
# other scopes | ||||||||||||||||||||
AUTH0_AUTH_SCOPES.update({"rebuild_product_details": LDAP_GROUPS["firefox-signoff"], "update_release_status": []}) | ||||||||||||||||||||
AUTH0_AUTH_SCOPES.update({"rebuild_product_details": LDAP_GROUPS["firefox-signoff"], "update_release_status": [], "create_product_channel_version/firefox": []}) | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another follow-up: We will need to grant releng scopes to seed the initial Thunderbird version once the Thunderbird bits are implemented.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
# Github scopes | ||||||||||||||||||||
# The following scope gives permission to all github queries, inlcuding private repos | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: All other functions here seem to return a tuple with (data, exitcode) should we follow the same pattern here?