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

feat: privacy field in proposal data #467

Merged
merged 9 commits into from
Nov 30, 2024
2 changes: 2 additions & 0 deletions src/ingestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default async function ingestor(req) {
body: message.body,
discussion: message.discussion || '',
choices: message.choices,
privacy: message.privacy || '',
labels: message.labels || [],
start: message.start,
end: message.end,
Expand All @@ -169,6 +170,7 @@ export default async function ingestor(req) {
name: message.title,
body: message.body,
discussion: message.discussion || '',
privacy: message.privacy || '',
choices: message.choices,
labels: message.labels || [],
metadata: {
Expand Down
10 changes: 9 additions & 1 deletion src/writer/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export async function verify(body): Promise<any> {
if (msg.payload.type !== space.voting.type) return Promise.reject('invalid voting type');
}

if (space.voting?.privacy !== 'any' && msg.payload.privacy) {
return Promise.reject('not allowed to set privacy');
}

try {
if (await isMalicious(msg.payload, space.id)) {
return Promise.reject('invalid proposal content');
Expand Down Expand Up @@ -207,6 +211,10 @@ export async function action(body, ipfs, receipt, id): Promise<void> {
const plugins = JSON.stringify(metadata.plugins || {});
const spaceNetwork = spaceSettings.network;
const proposalSnapshot = parseInt(msg.payload.snapshot || '0');
let privacy = spaceSettings.voting?.privacy || '';
if (privacy === 'any') {
privacy = msg.payload.privacy;
}

let quorum = spaceSettings.voting?.quorum || 0;
if (!quorum && spaceSettings.plugins?.quorum) {
Expand Down Expand Up @@ -238,7 +246,7 @@ export async function action(body, ipfs, receipt, id): Promise<void> {
end: parseInt(msg.payload.end || '0'),
quorum,
quorum_type: (quorum && spaceSettings.voting?.quorumType) || '',
privacy: spaceSettings.voting?.privacy || '',
privacy,
snapshot: proposalSnapshot || 0,
app: kebabCase(msg.payload.app || ''),
scores: JSON.stringify([]),
Expand Down
10 changes: 10 additions & 0 deletions src/writer/update-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export async function verify(body): Promise<any> {

if (proposal.author !== body.address) return Promise.reject('Not the author');

if (space.voting?.privacy !== 'any' && msg.payload.privacy) {
return Promise.reject('not allowed to set privacy');
}

const spaceUpdateError = getSpaceUpdateError({
type: msg.payload.type,
space
Expand All @@ -63,6 +67,11 @@ export async function action(body, ipfs): Promise<void> {
const updated = parseInt(msg.timestamp);
const metadata = msg.payload.metadata || {};
const plugins = JSON.stringify(metadata.plugins || {});
const spaceSettings = await getSpace(msg.space);
let privacy = spaceSettings.voting?.privacy || '';
if (privacy === 'any') {
privacy = msg.payload.privacy;
}

const proposal = {
ipfs,
Expand All @@ -74,6 +83,7 @@ export async function action(body, ipfs): Promise<void> {
discussion: msg.payload.discussion,
choices: JSON.stringify(msg.payload.choices),
labels: msg.payload.labels?.length ? JSON.stringify(msg.payload.labels) : null,
privacy,
scores: JSON.stringify([]),
scores_by_strategy: JSON.stringify([]),
flagged: +containsFlaggedLinks(msg.payload.body)
Expand Down
Loading