-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat: admin api v1 - create url #2213
Conversation
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.
mostly lgtm, thanks a lot for this!!
regarding an open question from before on whether this should or shouldn't be external API v2: after considering it more, I think I'd still somewhat (but not strongly) be in favour of it being admin API v1 instead. the functionality provided in this PR to create links under anyone else's account is not just equivalent to creating a link under your own account and then transferring it to someone else's, but involves possibly creating an entirely new account for that someone; plus, their email address need not even be whitelisted! perhaps it's a matter of personal opinion and risk tolerance, but to me this might just be too much power to give to just any public officer who can access Go?
plus, if we're not 100% confident that v2 should be released not just to specific admin users but rolled out to all ordinary public officers (like in v1), then it appears to me that by default they should be kept separate -- if v1 and v2 cater to different groups of people with different permissions and powers, they seem different enough to warrant separating this one out as an admin-only API. documentation-wise, labelling it as a new 'version' might also be misleading, as it implies to our current external API v1 users that there's a new version that they can upgrade to, when in fact it's exclusive to only certain privileged parties like Forms
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.
looking good!
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.
LGTM, great work pushing out such a large feature 🔥 let's test it on staging sometime as we prepare it for prod release!
Some deploy notes:
- Before deployment: set
ADMIN_API_EMAILS
on gov/edu/health staging - Before deployment: set
ADMIN_API_EMAILS
on gov/edu/health prod - After deployment: remove
ADMIN_API_EMAIL
on gov/edu/health staging - After deployment: remove
ADMIN_API_EMAIL
on gov/edu/health prod
src/server/modules/api/admin-v1/__tests__/AdminApiV1Controller.test.ts
Outdated
Show resolved
Hide resolved
* fix: package.json & package-lock.json to reduce vulnerabilities (#2207) The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-XML2JS-5414874 * feat: allow zip files and block password-protected files (#2203) * feat: admin api v1 - create url (#2213) * feat: api v2 endpoint and update admin auth middleware * chore: add and handle external user creation * chore: rename admin api env variable * chore: api v2 unit testing * chore: add integration tests * chore: update test api key string * chore: update unauthorized user error * chore: undo conditional user creation * chore: update admin email env var parsing * chore: port to admin api v1 and update unit and integration tests * chore: remove external user type and add domain validation error msg * chore: remainder port from v2 to admin v1 * chore: add missing return in external v1 * fix: ownership transfer condition and tests * chore: move api structure and update tests * chore: update readme * chore: add email domain validation to schema * chore: fix error type for generic errors * chore: undo types from external v1 * 1.76.0 --------- Co-authored-by: halfwhole <41856541+halfwhole@users.noreply.github.com> Co-authored-by: Snyk bot <snyk-bot@snyk.io>
Problem
This PR closes APIs for Forms to create shortlinks
Solution
This PR implements a new endpoint
{{host}}/api/v1/admin/urls
which is allows for whitelisted emails defined inADMIN_API_EMAILS
to call the endpoint to create new short URLs and transfer its ownership to a provided email address.Features:
Added new route to
{{host}}/api/v1/admin/urls
that usesapiKeyAdminAuthMiddleware
for authenticationapiKeyAdminAuthMiddleware
to throwjsonMessage
if api key is unauthorizedemail
attribute on top of existing validationsAdded
AdminApiV1Controller
that handles POST requests withshortUrl
,longUrl
, andemail
attributes in the JSON bodycreateUrl
method to find or create a new user withemail
provided, then creates a new link with the authenticated user before transferring ownership to the parsedemail
.Improvements:
Renamed
ADMIN_API_EMAIL
env variable toADMIN_API_EMAILS
to reflect its use to white list multiple emailsintegration-test-admin@open.gov.sg
to the white list for integration testsUpdated
isAdmin
method inApiKeyAuthService
to handle multiple white listed emailsTests
Unit Test Cases
Integration Test
createIntegrationTestAdminUser
to create a new integration test admin user which is using the definedintegration-test-admin@open.gov.sg
email