Skip to content

Commit

Permalink
Approve organization account (pypi#11208)
Browse files Browse the repository at this point in the history
* admin-new-organization-approved email template

* admin-new-organization-declined email template

* new-organization-approved email template

* new-organization-declined email template

* Remove translations from admin-* emails

Realized that translations for admin-* emails don't really make sense.
Similar to commit bec7058.

* Test *new-organization-{approved,declined} emails

- admin-new-organization-approved
- admin-new-organization-declined
- new-organization-approved
- new-organization-declined

* Mockup of approve organization form for admin

* Add message textarea to approve organization form

* Add more context to approve organization form

* Rename view admin.organization.{approve => detail}

* Implement GET approve organization form

* Revamp UX for approve organization form

As @ewdurbin pointed out, the approve organziation form in the admin
interface should use the same design as the rest of the admin interface:

- Changed style to AdminLTE theme.
- Moved *Approve* or *Decline* dialog to *Actions* box.
- Added confirmation modals for *Approve* or *Decline*.
- Added *type orgnization name to confirm* to confirmation modals.

The *Actions* box and confirmation modals follow the same patterns used
in the user detail admin page.

* Implement POST approve organization form

* Get requesting user for approve organization form

Used Organization.events relationship per @sterbo's suggestion.

* Handle status in approve organization form

- Add "Approval Status" to "Organization Request" details
- Allow admin to change approval decision
- Disable "Approve" button if already approved
- Disable "Decline" button if already declined

* Store id instead of username in new events

`Organization.Event` with tag:

- organization.approve
- organization.decline

* GET /admin/organizations/ to list organizations

* Add "Organizations" to admin sidebar

Show only if `AdminFlagValue.DISABLE_ORGANIZATIONS` is unchecked.

* Test GET /admin/organizations/

* NFC: Rename tests *_{disallow => disable}_organizations

* "Organizations" admin 404 if disable-organizations

404 Not Found for "Organizations" admin if `disable-organizations` admin
flag is checked.

* NFC: `organization_*` prefix for admin org views

* GET /admin/organizations/?q=... faceted search

* GET /admin/organizations?q=... improved search UI

* Update tests for GET /admin/organizations/

* Link breadcrumb to GET /admin/organizations/

* Fix flaky tests for /admin/organizations/

- Avoid unstable sort using `.normalized_name.lower()` as key
- Avoid unreliable comparison of `paginate.Page` and `list`

Co-authored-by: Ee Durbin <ewdurbin@gmail.com>
  • Loading branch information
divbzero and ewdurbin authored May 1, 2022
1 parent 7cb17c9 commit ad9eb8f
Show file tree
Hide file tree
Showing 34 changed files with 2,160 additions and 49 deletions.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from warehouse import admin, config, static
from warehouse.accounts import services as account_services
from warehouse.accounts.interfaces import ITokenService
from warehouse.admin.flags import AdminFlag, AdminFlagValue
from warehouse.email import services as email_services
from warehouse.email.interfaces import IEmailSender
from warehouse.macaroons import services as macaroon_services
Expand Down Expand Up @@ -350,6 +351,16 @@ def db_request(pyramid_request, db_session):
return pyramid_request


@pytest.fixture()
def enable_organizations(db_request):
flag = db_request.db.query(AdminFlag).get(
AdminFlagValue.DISABLE_ORGANIZATIONS.value
)
flag.enabled = False
yield
flag.enabled = True


class _TestApp(_webtest.TestApp):
def xmlrpc(self, path, method, *args):
body = xmlrpc.client.dumps(args, methodname=method)
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/accounts/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ def test_recent_events(self, db_session):
time=datetime.datetime.now() - datetime.timedelta(days=91),
)

assert len(user.events) == 2
assert len(user.recent_events) == 1
assert user.events == [recent_event, stale_event]
assert user.recent_events == [recent_event]
assert user.events.all() == [recent_event, stale_event]
assert user.recent_events.all() == [recent_event]

def test_regular_user_not_prohibited_password_reset(self, db_session):
user = DBUserFactory.create()
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/admin/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ def test_includeme():

assert config.add_route.calls == [
pretend.call("admin.dashboard", "/admin/", domain=warehouse),
pretend.call(
"admin.organization.list", "/admin/organizations/", domain=warehouse
),
pretend.call(
"admin.organization.detail",
"/admin/organizations/{organization_id}/",
domain=warehouse,
),
pretend.call(
"admin.organization.approve",
"/admin/organizations/approve/",
"/admin/organizations/{organization_id}/approve/",
domain=warehouse,
),
pretend.call(
"admin.organization.decline",
"/admin/organizations/{organization_id}/decline/",
domain=warehouse,
),
pretend.call("admin.user.list", "/admin/users/", domain=warehouse),
Expand Down
Loading

0 comments on commit ad9eb8f

Please sign in to comment.