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

chore: remove waitlist UI, emails, and admin APIs #123

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,6 @@ making changes to the API.
You can view the registry at `http://jsr.test`. The API can be found at
`http://api.jsr.test`.

### Accepting waitlisted users to the local dev environment

**Important:** before proceeding, go to `jsr.test` in your browser, and sign up
for the waitlist. You'll need to authorize the application via OAuth before
proceeding.

Once you're signed up for the waitlist:

1. Run `psql`, and a new
[postgres shell](https://www.postgresql.org/docs/6.4/app-psql.htm#:~:text=psql%20is%20a%20character%2Dbased,is%20a%20Postgres%20client%20application.)
will open from where you can interact with databases. (NOTE: if `psql` alone
does not work, try `psql registry`, or `psql DATABASE_URL`, but replacing
`DATABASE_URL` with the value of your .env variable of that same name.)
2. Connect to the database by entering `\c registry` (unnecessary if you ran
`psql registry` above), and hitting Enter
3. Enter the following query: `UPDATE users SET waitlist_accepted_at = now();`
which will accept all pending users. Execute the query by pressing Enter.
4. Exit the psql shell by typing `exit` and pressing Enter.

All users are now invited and can browse `http://jsr.test`.

### Publishing a package to the local dev environment

1. Create a new directory with a `deno.json`
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

69 changes: 0 additions & 69 deletions api/src/api/admin.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
use crate::analysis::RegistryLoader;
use crate::buckets::Buckets;
use crate::emails::EmailArgs;
use crate::emails::EmailSender;
use crate::NpmUrl;
use crate::RegistryUrl;
use hyper::Body;
use hyper::Request;
use routerify::prelude::RequestExt;
use routerify::Router;
use std::borrow::Cow;
use std::sync::Arc;
use tracing::field;
use tracing::instrument;
Expand All @@ -35,12 +31,7 @@ pub fn admin_router() -> Router<Body, ApiError> {
.get("/aliases", util::auth(util::json(list_aliases)))
.post("/aliases", util::auth(util::json(create_alias)))
.get("/users", util::auth(util::json(list_users)))
.get("/users/waitlisted", util::auth(util::json(list_waitlisted)))
.patch("/users/:user_id", util::auth(util::json(update_user)))
.post(
"/users/:user_id/waitlist_accept",
util::auth(util::json(waitlist_accept_user)),
)
.get("/scopes", util::auth(util::json(list_scopes)))
.patch("/scopes/:scope", util::auth(util::json(patch_scopes)))
.get(
Expand Down Expand Up @@ -110,26 +101,6 @@ pub async fn list_users(req: Request<Body>) -> ApiResult<ApiList<ApiFullUser>> {
})
}

#[instrument(name = "GET /api/admin/users/waitlisted", skip(req), err)]
pub async fn list_waitlisted(
req: Request<Body>,
) -> ApiResult<ApiList<ApiFullUser>> {
let iam = req.iam();
iam.check_admin_access()?;

let db = req.data::<Database>().unwrap();
let (start, limit) = pagination(&req);
let maybe_search = search(&req);

let (total_users, users) =
db.list_users_waitlisted(start, limit, maybe_search).await?;

Ok(ApiList {
items: users.into_iter().map(|user| user.into()).collect(),
total: total_users,
})
}

#[instrument(
name = "PATCH /api/admin/users/:user_id",
skip(req),
Expand Down Expand Up @@ -170,46 +141,6 @@ pub async fn update_user(mut req: Request<Body>) -> ApiResult<ApiFullUser> {
}
}

#[instrument(
name = "PATCH /api/admin/users/:user_id/waitlist_accept",
skip(req),
err,
fields(user_id)
)]
pub async fn waitlist_accept_user(
req: Request<Body>,
) -> ApiResult<ApiFullUser> {
let iam = req.iam();
iam.check_admin_access()?;

let user_id = req.param_uuid("user_id")?;
Span::current().record("user_id", &field::display(&user_id));
let db = req.data::<Database>().unwrap();
let email_sender = req.data::<Option<EmailSender>>().unwrap();
let registry_url = req.data::<RegistryUrl>().unwrap();

let user = db.get_user(user_id).await?.ok_or(ApiError::UserNotFound)?;
if user.waitlist_accepted_at.is_some() {
return Ok(user.into());
}

let updated_user = db.user_waitlist_accept(user_id).await?;

if let Some(email_sender) = email_sender {
if let Some(email_addr) = user.email {
let email = EmailArgs::WaitlistAccept {
name: Cow::Borrowed(&updated_user.name),
registry_url: Cow::Borrowed(registry_url.0.as_str()),
registry_name: Cow::Borrowed(&email_sender.from_name),
support_email: Cow::Borrowed(&email_sender.from),
};
email_sender.send(email_addr, email).await?;
}
}

Ok(updated_user.into())
}

#[instrument(name = "GET /api/admin/scopes", skip(req), err)]
pub async fn list_scopes(
req: Request<Body>,
Expand Down
Loading
Loading