Skip to content
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

lando-ui: merge remaining LandoUI code (Bug 1944562) #228

Open
wants to merge 27 commits into
base: api-merge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
502c130
fix(circleci): Using CIRCLE_TAG in develop and stage image tags to mo…
dlactin Dec 14, 2023
b470018
circleci: Using SHA1 in dev/stage image name instead of tag (#193)
dlactin Dec 21, 2023
fd16176
stack: move the uplift request form into a separate modal (Bug 180195…
cgsheeh Jan 8, 2024
b1be0a8
landing-preview: add a shim to display `blockers` dryrun info if avai…
cgsheeh Apr 26, 2024
dbc5f21
treestatus: implement Treestatus UI (Bug 1817473) (#186)
cgsheeh May 6, 2024
e590c40
circleci: update base image and use `compose` plugin (Bug 1895531) (#…
cgsheeh May 7, 2024
ee9ec2a
revision-status: use `blocked_reason` variable instead of pre-refacto…
cgsheeh May 7, 2024
b17885d
treestatus: check for user authentication before `require_auth0` API …
cgsheeh May 14, 2024
af9443b
treestatus: handle 404 from tree logs reponse properly (Bug 1896642) …
cgsheeh May 14, 2024
be9d1e3
circleci: change deploy step to run (Bug 1895570) (#201)
cgsheeh May 15, 2024
80abbcb
treestatus: convert logging of Treestatus API errors to `info` level …
cgsheeh May 16, 2024
44428c6
templates: hide Treestatus editing capabilities from unprivileged use…
cgsheeh Jul 19, 2024
47ecfaa
Merge remote-tracking branch 'lando-ui-repo/main' into ui-merge
cgsheeh Feb 19, 2025
9dca57e
add forms to treestatus app
cgsheeh Feb 19, 2025
f696125
comment out Flask forms tests
cgsheeh Feb 19, 2025
4d0d417
import treestatus forms from treestatus app namespace
cgsheeh Feb 20, 2025
f7128c5
comment out treestatus related forms
cgsheeh Feb 20, 2025
a7081ca
comment out treestatus Flask endpoint code
cgsheeh Feb 20, 2025
52070bd
comment out treestatus related tests in ui app
cgsheeh Feb 20, 2025
fe01245
ruff
cgsheeh Feb 20, 2025
5be7860
Merge branch 'api-merge' into ui-merge
cgsheeh Feb 24, 2025
a41a82b
Merge branch 'api-merge' into ui-merge
cgsheeh Mar 4, 2025
fd2eeba
remove license from `Treestatus.js`
cgsheeh Mar 5, 2025
76d2e12
add a bug number to TODO
cgsheeh Mar 5, 2025
810faee
fix typo in `token`
cgsheeh Mar 5, 2025
6e51aa9
use `user_is_authenticated` variable
cgsheeh Mar 5, 2025
57b2d7a
csrf_token -> csrf_input
cgsheeh Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/lando/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from django.utils.html import escape
from jinja2 import Environment

from lando.treestatus.forms import (
ReasonCategory,
TreeCategory,
)
from lando.ui.legacy.forms import UserSettingsForm

FAQ_URL = "https://wiki.mozilla.org/Phabricator/FAQ#Lando"
Expand All @@ -25,6 +29,22 @@
# return UserSettingsForm()


TREESTATUS_USER_GROUPS = {
"mozilliansorg_treestatus_admins",
"mozilliansorg_treestatus_users",
}


def is_treestatus_user(userinfo: dict) -> bool:
# TODO determine if this is correct.
try:
groups = userinfo["https://sso.mozilla.com/claim/groups"]
except KeyError:
return False

return not TREESTATUS_USER_GROUPS.isdisjoint(groups)


def escape_html(text: str) -> str:
return escape(text)

Expand Down Expand Up @@ -75,6 +95,15 @@ def reviewer_to_status_badge_class(reviewer: dict) -> str:
]


def treestatus_to_status_badge_class(tree_status: str) -> str:
"""Convert Tree statuses into status badges."""
return {
"open": "Badge Badge--positive",
"closed": "Badge Badge--negative",
"approval required": "Badge Badge--warning",
}.get(tree_status, "Badge Badge--warning")


def reviewer_to_action_text(reviewer: dict) -> str:
options = {
# status: (current_diff, for_other_diff),
Expand Down Expand Up @@ -110,6 +139,21 @@ def tostatusbadgename(status: dict) -> str:
return mapping.get(status["status"].lower(), status["status"].capitalize())


def reason_category_to_display(reason_category_str: str) -> str:
try:
return ReasonCategory(reason_category_str).to_display()
except ValueError:
# Return the bare string, in case of older data.
return reason_category_str


def tree_category_to_display(tree_category_str: str) -> str:
try:
return TreeCategory(tree_category_str).to_display()
except ValueError:
return tree_category_str


def avatar_url(url: str) -> str:
# If a user doesn't have a gravatar image for their auth0 email address,
# gravatar uses auth0's provided default which redirects to
Expand Down Expand Up @@ -297,6 +341,7 @@ def environment(**options):
"config": settings,
"get_messages": messages.get_messages,
"graph_height": graph_height,
"is_treestatus_user": is_treestatus_user,
"new_settings_form": UserSettingsForm,
"static_url": settings.STATIC_URL,
"url": reverse,
Expand All @@ -321,13 +366,16 @@ def environment(**options):
"linkify_transplant_details": linkify_transplant_details,
"message_type_to_notification_class": message_type_to_notification_class,
"repo_path": repo_path,
"reason_category_to_display": reason_category_to_display,
"reviewer_to_action_text": reviewer_to_action_text,
"reviewer_to_status_badge_class": reviewer_to_status_badge_class,
"revision_status_to_badge_class": revision_status_to_badge_class,
"revision_url": revision_url,
"static": static,
"tostatusbadgeclass": tostatusbadgeclass,
"tostatusbadgename": tostatusbadgename,
"tree_category_to_display": tree_category_to_display,
"treestatus_to_status_badge_class": treestatus_to_status_badge_class,
}
)
return env
27 changes: 27 additions & 0 deletions src/lando/static_src/legacy/css/pages/TreestatusPage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

@import "../colors";

.recent-changes-update-hidden {
// Hide the hidden elements in the recent changes view.
display: none;
}

.log-update-hidden {
// Hide the hidden elements in the log update view.
display: none;
}

.select-trees-box {
// Remove the spaces between tree boxes.
margin-bottom: 0rem !important;
}

.tree-category-header {
// Add some padding category header elements.
padding-top: 1rem;
}
8 changes: 8 additions & 0 deletions src/lando/static_src/legacy/js/components/Stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ $.fn.stack = function() {
window.location.href = '/' + e.target.id;
$radio.attr({'disabled': true});
});

// Show the uplift request form modal when the "Request Uplift" button is clicked.
$('.uplift-request-open').on("click", function () {
$('.uplift-request-modal').addClass("is-active");
});
$('.uplift-request-close').on("click", function () {
$('.uplift-request-modal').removeClass("is-active");
});
});
};
80 changes: 80 additions & 0 deletions src/lando/static_src/legacy/js/components/Treestatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

'use strict';

$.fn.treestatus = function() {
return this.each(function() {
// Register an on-click handler for each log update edit button.
$('.log-update-edit').on("click", function () {
// Toggle the elements from hidden/visible.
var closest_form = $(this).closest('.log-update-form');

closest_form.find('.log-update-hidden').toggle();
closest_form.find('.log-update-visible').toggle();
});

// Register an on-click handler for each recent changes edit button.
$('.recent-changes-edit').on("click", function () {
// Toggle the elements from hidden/visible.
var closest_form = $(this).closest('.recent-changes-form');

closest_form.find('.recent-changes-update-hidden').toggle();
closest_form.find('.recent-changes-update-visible').toggle();
});

// Toggle selected on all trees.
$('.select-all-trees').on("click", function () {
var checkboxes = $('.tree-select-checkbox');
checkboxes.prop('checked', true);
checkboxes.trigger('change');
});

// Toggle un-selected on all trees.
$('.unselect-all-trees').on("click", function () {
var checkboxes = $('.tree-select-checkbox');
checkboxes.prop('checked', false);
checkboxes.trigger('change');
});

// Update the select trees list after update.
var set_update_trees_list = function () {
// Clear the current state of the update form tree list.
var trees_list = $('.update-trees-list')
trees_list.empty();

// Get all the checked boxes in the select trees view.
$('.tree-select-checkbox:checked').each(function () {
var checkbox = $(this);

// Add a new `li` element for each selected tree.
trees_list.append(
$('<li></li>').text(checkbox.val())
);
});
};

// Show the update trees modal when "Update trees" is clicked.
$('.update-trees-button').on("click", function () {
$('.update-trees-modal').toggle();
});

// Close the update trees modal when the close button is clicked.
$('.update-trees-modal-close').on("click", function () {
$('.update-trees-modal').toggle();
});

// Add a tree to the list of trees on the update form when checkbox set.
$('.tree-select-checkbox').on("change", function () {
set_update_trees_list();

var checked_trees = $('.tree-select-checkbox:checked');
// Disaable the "Update trees" button when no trees are selected.
var is_tree_select_disabled = checked_trees.length > 0 ? false : true;
$('.update-trees-button').prop('disabled', is_tree_select_disabled);
});
});
};
2 changes: 2 additions & 0 deletions src/lando/static_src/legacy/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $(document).ready(function() {
let $secRequestSubmitted = $('.StackPage-secRequestSubmitted');
let $stack = $('.StackPage-stack');
let $timeline = $('.StackPage-timeline');
let $treestatus = $('.Treestatus');

// Initialize components
$flashMessages.flashMessages();
Expand All @@ -15,4 +16,5 @@ $(document).ready(function() {
$secRequestSubmitted.secRequestSubmitted();
$stack.stack();
$timeline.timeline();
$treestatus.treestatus();
});
Loading