Skip to content

Commit

Permalink
fix: check society member, #1034
Browse files Browse the repository at this point in the history
  • Loading branch information
hyifeng committed Sep 4, 2024
1 parent 1fec1cd commit a9447af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const { NODE_API_ENDPOINT } = require("../../env");
const { fetchApi } = require("../../utils/fech.api");

async function getSocietyMember(network, address, height) {
const url = `${NODE_API_ENDPOINT}/${network}/society/members/${address}/height/${height}`;
let url = `${NODE_API_ENDPOINT}/${network}/society/members/${address}`;
if (height) {
url = `${NODE_API_ENDPOINT}/${network}/society/members/${address}/height/${height}`;
}
return await fetchApi(url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const { NODE_API_ENDPOINT } = require("../../env");
const { fetchApi } = require("../../utils/fech.api");

async function getSocietyMembers(network, height) {
const url = `${NODE_API_ENDPOINT}/${network}/society/members/height/${height}`;
let url = `${NODE_API_ENDPOINT}/${network}/society/members`;
if (height) {
url = `${NODE_API_ENDPOINT}/${network}/society/members/height/${height}`;
}
return await fetchApi(url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ const { HttpError } = require("../../exc");
const { ContentType } = require("../../constants");
const { spaces: spaceServices } = require("../../spaces");
const { pinData, createSpaceNotifications } = require("./common");
const { Accessibility } = require("../../consts/space");
const { getSocietyMember } = require("../node.service/getSocietyMember");

async function checkSocietyMember({
networksConfig,
proposerNetwork,
proposer,
}) {
if (networksConfig.accessibility !== Accessibility.SOCIETY) {
return;
}
const societyMember = await getSocietyMember(proposerNetwork, proposer);
if (!societyMember.data) {
throw new HttpError(400, "You are not the society member");
}
}

async function createSocietyProposal({
space,
Expand All @@ -30,6 +46,12 @@ async function createSocietyProposal({

const proposer = realProposer || address;

await checkSocietyMember({
networksConfig,
proposerNetwork,
proposer,
});

const { cid, pinHash } = await pinData({ data, address, signature });

const postUid = await nextPostUid();
Expand Down
2 changes: 2 additions & 0 deletions backend/packages/node-api/src/features/society/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ router.get(
"/society/members/:address/height/:blockHashOrHeight?",
getSocietyMember,
);
router.get("/society/members/:address", getSocietyMember);
router.get("/society/members/height/:blockHashOrHeight?", getSocietyMembers);
router.get("/society/members", getSocietyMembers);

module.exports = router;

0 comments on commit a9447af

Please sign in to comment.