Skip to content

Commit

Permalink
Merge pull request #9966 from hicommonwealth/release/v1.7.4-x
Browse files Browse the repository at this point in the history
Release/v1.7.4-1
  • Loading branch information
ilijabojanovic authored Nov 20, 2024
2 parents b3a801a + ed799f1 commit e384c99
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libs/model/src/community/DeleteCommunity.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ export function DeleteCommunity(): Command<typeof schemas.DeleteCommunity> {
const communityIdModels: ModelStatic<
ModelInstance<{ community_id: string }>
>[] = [
models.ContestManager,
models.CommunityAlert,
models.CommunityStake,
models.DiscordBotConfig,
models.Topic,
models.Webhook,
models.Vote,
models.Poll,
models.Thread,
models.Topic,
models.StarredCommunity,
models.Group,
models.Address,
Expand Down
9 changes: 4 additions & 5 deletions libs/model/src/community/JoinCommunity.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as schemas from '@hicommonwealth/schemas';
import { ChainBase, addressSwapper } from '@hicommonwealth/shared';
import { models } from '../database';
import { mustExist } from '../middleware/guards';
import { incrementProfileCount } from '../utils';
import { findCompatibleAddress } from '../utils/findBaseAddress';

export const JoinCommunityErrors = {
Expand Down Expand Up @@ -102,11 +101,11 @@ export function JoinCommunity(): Command<typeof schemas.JoinCommunity> {
{ transaction },
);

await incrementProfileCount(
community.id,
actor.user.id!,
await models.Community.increment('profile_count', {
by: 1,
where: { id: community_id },
transaction,
);
});

return created.id!;
},
Expand Down
2 changes: 2 additions & 0 deletions libs/model/src/models/associations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ export const buildAssociations = (db: DB) => {
db.ContestManager.withMany(db.Contest, {
foreignKey: 'contest_address',
asMany: 'contests',
onDelete: 'CASCADE',
});

db.Contest.withMany(db.ContestAction, {
foreignKey: ['contest_address', 'contest_id'],
asMany: 'actions',
onDelete: 'CASCADE',
});

db.CommunityStake.withMany(db.StakeTransaction, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const useTopicGating = ({
acc.push(current);
// IMP: this logic can break if `PermissionEnum` or the `GroupPermissions`
// schema is changed substantially and might not give off a ts issue.
} else if (current.permissions.length > existing.permissions.length) {
} else if (current?.permissions?.length > existing?.permissions?.length) {
// Replace with the current item if it has a longer permission string
const index = acc.indexOf(existing);
acc[index] = current;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.query(`
UPDATE "Communities" C
SET profile_count = (SELECT COUNT(DISTINCT (user_id)) FROM "Addresses" WHERE community_id = C.id);
`);
},

async down(queryInterface, Sequelize) {},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (t) => {
await queryInterface.sequelize.query(
`
ALTER TABLE "ContestActions"
DROP CONSTRAINT "ContestActions_contests_fkey",
ADD CONSTRAINT "ContestActions_contests_fkey"
FOREIGN KEY (contest_address, contest_id)
REFERENCES "Contests" (contest_address, contest_id)
ON UPDATE NO ACTION
ON DELETE CASCADE;
`,
{ transaction: t },
);

await queryInterface.sequelize.query(
`
ALTER TABLE "Contests"
DROP CONSTRAINT "Contests_contestmanagers_fkey",
ADD CONSTRAINT "Contests_contestmanagers_fkey"
FOREIGN KEY (contest_address)
REFERENCES "ContestManagers" (contest_address)
ON UPDATE NO ACTION
ON DELETE CASCADE;
`,
{ transaction: t },
);
});
},

async down(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (t) => {
await queryInterface.sequelize.query(
`
ALTER TABLE "ContestActions"
DROP CONSTRAINT "ContestActions_contests_fkey",
ADD CONSTRAINT "ContestActions_contests_fkey"
FOREIGN KEY (contest_address, contest_id)
REFERENCES "Contests" (contest_address, contest_id)
ON DELETE NO ACTION;
`,
{ transaction: t },
);

await queryInterface.sequelize.query(
`
ALTER TABLE "Contests"
DROP CONSTRAINT "Contests_contestmanagers_fkey",
ADD CONSTRAINT "Contests_contestmanagers_fkey"
FOREIGN KEY (contest_address)
REFERENCES "ContestManagers" (contest_address)
ON DELETE NO ACTION;
`,
{ transaction: t },
);
});
},
};
9 changes: 9 additions & 0 deletions packages/commonwealth/server/util/verifySessionSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,17 @@ const verifySessionSignature = async (
});
if (!user || !user.id) throw new Error('Failed to create user');
addressModel.user_id = user!.id;

await addressModel.save();
return;
}
}

// user already exists but new community joined
await incrementProfileCount(
addressModel.community_id!,
addressModel.user_id!,
);
} else {
// mark the address as verified
addressModel.verification_token_expires = null;
Expand Down

0 comments on commit e384c99

Please sign in to comment.