Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3399189
D11327.id38140.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D11327.id38140.diff
View Options
diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js
--- a/keyserver/src/responders/user-responders.js
+++ b/keyserver/src/responders/user-responders.js
@@ -130,7 +130,7 @@
} from '../session/cookies.js';
import type { Viewer } from '../session/viewer.js';
import {
- accountUpdater,
+ passwordUpdater,
checkAndSendVerificationEmail,
checkAndSendPasswordResetEmail,
updatePassword,
@@ -180,7 +180,7 @@
viewer: Viewer,
request: PasswordUpdate,
): Promise<void> {
- await accountUpdater(viewer, request);
+ await passwordUpdater(viewer, request);
}
async function sendVerificationEmailResponder(viewer: Viewer): Promise<void> {
diff --git a/keyserver/src/scripts/merge-users.js b/keyserver/src/scripts/merge-users.js
deleted file mode 100644
--- a/keyserver/src/scripts/merge-users.js
+++ /dev/null
@@ -1,195 +0,0 @@
-// @flow
-
-import type { ServerThreadInfo } from 'lib/types/thread-types.js';
-import { updateTypes } from 'lib/types/update-types-enum.js';
-import { type UpdateData } from 'lib/types/update-types.js';
-
-import { endScript } from './utils.js';
-import { createUpdates } from '../creators/update-creator.js';
-import { dbQuery, SQL } from '../database/database.js';
-import type { SQLStatementType } from '../database/types.js';
-import { deleteAccount } from '../deleters/account-deleters.js';
-import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js';
-import { createScriptViewer } from '../session/scripts.js';
-import {
- changeRole,
- commitMembershipChangeset,
- type MembershipRow,
-} from '../updaters/thread-permission-updaters.js';
-import RelationshipChangeset from '../utils/relationship-changeset.js';
-
-async function main() {
- try {
- await mergeUsers('7147', '15972', { username: true, password: true });
- endScript();
- } catch (e) {
- endScript();
- console.warn(e);
- }
-}
-
-type ReplaceUserInfo = Partial<{
- +username: boolean,
- +password: boolean,
-}>;
-async function mergeUsers(
- fromUserID: string,
- toUserID: string,
- replaceUserInfo?: ReplaceUserInfo,
-) {
- let updateUserRowQuery: ?SQLStatementType = null;
- let updateDatas: UpdateData[] = [];
- if (replaceUserInfo) {
- const replaceUserResult = await replaceUser(
- fromUserID,
- toUserID,
- replaceUserInfo,
- );
- ({ sql: updateUserRowQuery, updateDatas } = replaceUserResult);
- }
-
- const usersGettingUpdate = new Set<string>();
- const usersNeedingUpdate = new Set<string>();
- const needUserInfoUpdate = replaceUserInfo && replaceUserInfo.username;
- const setGettingUpdate = (threadInfo: ServerThreadInfo) => {
- if (!needUserInfoUpdate) {
- return;
- }
- for (const { id } of threadInfo.members) {
- usersGettingUpdate.add(id);
- usersNeedingUpdate.delete(id);
- }
- };
- const setNeedingUpdate = (threadInfo: ServerThreadInfo) => {
- if (!needUserInfoUpdate) {
- return;
- }
- for (const { id } of threadInfo.members) {
- if (!usersGettingUpdate.has(id)) {
- usersNeedingUpdate.add(id);
- }
- }
- };
-
- const newThreadRolePairs = [];
- const { threadInfos } = await fetchServerThreadInfos();
- for (const threadID in threadInfos) {
- const threadInfo = threadInfos[threadID];
- const fromUserExistingMember = threadInfo.members.find(
- memberInfo => memberInfo.id === fromUserID,
- );
- if (!fromUserExistingMember) {
- setNeedingUpdate(threadInfo);
- continue;
- }
- const { role } = fromUserExistingMember;
- if (!role) {
- // Only transfer explicit memberships
- setNeedingUpdate(threadInfo);
- continue;
- }
- const toUserExistingMember = threadInfo.members.find(
- memberInfo => memberInfo.id === toUserID,
- );
- if (!toUserExistingMember || !toUserExistingMember.role) {
- setGettingUpdate(threadInfo);
- newThreadRolePairs.push([threadID, role]);
- } else {
- setNeedingUpdate(threadInfo);
- }
- }
-
- const fromViewer = createScriptViewer(fromUserID);
- await deleteAccount(fromViewer);
-
- if (updateUserRowQuery) {
- await dbQuery(updateUserRowQuery);
- }
-
- const time = Date.now();
- for (const userID of usersNeedingUpdate) {
- updateDatas.push({
- type: updateTypes.UPDATE_USER,
- userID,
- time,
- updatedUserID: toUserID,
- });
- }
- await createUpdates(updateDatas);
-
- const changesets = await Promise.all(
- newThreadRolePairs.map(([threadID, role]) =>
- changeRole(threadID, [toUserID], role),
- ),
- );
- const membershipRows: Array<MembershipRow> = [];
- const relationshipChangeset = new RelationshipChangeset();
- for (const currentChangeset of changesets) {
- const {
- membershipRows: currentMembershipRows,
- relationshipChangeset: currentRelationshipChangeset,
- } = currentChangeset;
- membershipRows.push(...currentMembershipRows);
- relationshipChangeset.addAll(currentRelationshipChangeset);
- }
- if (membershipRows.length > 0 || relationshipChangeset.getRowCount() > 0) {
- const toViewer = createScriptViewer(toUserID);
- const changeset = { membershipRows, relationshipChangeset };
- await commitMembershipChangeset(toViewer, changeset);
- }
-}
-
-type ReplaceUserResult = {
- sql: ?SQLStatementType,
- updateDatas: UpdateData[],
-};
-async function replaceUser(
- fromUserID: string,
- toUserID: string,
- replaceUserInfo: ReplaceUserInfo,
-): Promise<ReplaceUserResult> {
- if (Object.keys(replaceUserInfo).length === 0) {
- return {
- sql: null,
- updateDatas: [],
- };
- }
-
- const fromUserQuery = SQL`
- SELECT username, hash
- FROM users
- WHERE id = ${fromUserID}
- `;
- const [fromUserResult] = await dbQuery(fromUserQuery);
- const [firstResult] = fromUserResult;
- if (!firstResult) {
- throw new Error(`couldn't fetch fromUserID ${fromUserID}`);
- }
-
- const changedFields: { [string]: string } = {};
- if (replaceUserInfo.username) {
- changedFields.username = firstResult.username;
- }
- if (replaceUserInfo.password) {
- changedFields.hash = firstResult.hash;
- }
-
- const updateUserRowQuery = SQL`
- UPDATE users SET ${changedFields} WHERE id = ${toUserID}
- `;
-
- const updateDatas: UpdateData[] = [];
- if (replaceUserInfo.username) {
- updateDatas.push({
- type: updateTypes.UPDATE_CURRENT_USER,
- userID: toUserID,
- time: Date.now(),
- });
- }
- return {
- sql: updateUserRowQuery,
- updateDatas,
- };
-}
-
-void main();
diff --git a/keyserver/src/scripts/rename-user.js b/keyserver/src/scripts/rename-user.js
deleted file mode 100644
--- a/keyserver/src/scripts/rename-user.js
+++ /dev/null
@@ -1,40 +0,0 @@
-// @flow
-
-import { updateTypes } from 'lib/types/update-types-enum.js';
-
-import { main } from './utils.js';
-import { createUpdates } from '../creators/update-creator.js';
-import { dbQuery, SQL } from '../database/database.js';
-import { fetchKnownUserInfos } from '../fetchers/user-fetchers.js';
-import { createScriptViewer } from '../session/scripts.js';
-
-const userID = '5';
-const newUsername = 'commbot';
-
-async function renameUser() {
- const [adjacentUsers] = await Promise.all([
- fetchKnownUserInfos(createScriptViewer(userID)),
- dbQuery(
- SQL`UPDATE users SET username = ${newUsername} WHERE id = ${userID}`,
- ),
- ]);
-
- const updateDatas = [];
- const time = Date.now();
- updateDatas.push({
- type: updateTypes.UPDATE_CURRENT_USER,
- userID,
- time,
- });
- for (const adjacentUserID in adjacentUsers) {
- updateDatas.push({
- type: updateTypes.UPDATE_USER,
- userID: adjacentUserID,
- time,
- updatedUserID: userID,
- });
- }
- await createUpdates(updateDatas);
-}
-
-main([renameUser]);
diff --git a/keyserver/src/updaters/account-updaters.js b/keyserver/src/updaters/account-updaters.js
--- a/keyserver/src/updaters/account-updaters.js
+++ b/keyserver/src/updaters/account-updaters.js
@@ -34,7 +34,7 @@
import { fetchKnownUserInfos } from '../fetchers/user-fetchers.js';
import type { Viewer } from '../session/viewer.js';
-async function accountUpdater(
+async function passwordUpdater(
viewer: Viewer,
update: PasswordUpdate,
): Promise<void> {
@@ -66,18 +66,6 @@
UPDATE users SET ${changedFields} WHERE id = ${viewer.userID}
`;
await dbQuery(saveQuery);
-
- const updateDatas = [
- {
- type: updateTypes.UPDATE_CURRENT_USER,
- userID: viewer.userID,
- time: Date.now(),
- },
- ];
- await createUpdates(updateDatas, {
- viewer,
- updatesForCurrentSession: 'broadcast',
- });
}
// eslint-disable-next-line no-unused-vars
@@ -256,7 +244,7 @@
}
export {
- accountUpdater,
+ passwordUpdater,
checkAndSendVerificationEmail,
checkAndSendPasswordResetEmail,
updateUserSettings,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 2:15 AM (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609288
Default Alt Text
D11327.id38140.diff (8 KB)
Attached To
Mode
D11327: [keyserver] Remove deprectaed uses of updateTypes.UPDATE_CURRENT_USER
Attached
Detach File
Event Timeline
Log In to Comment