Skip to content

Commit

Permalink
Merge branch '#181'
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmartyrk committed Mar 31, 2021
2 parents 5e6b559 + 4c53f96 commit 076f7d2
Show file tree
Hide file tree
Showing 14 changed files with 2,483 additions and 2,322 deletions.
3 changes: 3 additions & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@
"voteCountMin": "CITIZENOS_FEATURES_SENDTOPARLIAMENT_VOTECOUNTMIN",
"from": "CITIZENOS_FEATURES_SENDTOPARLIAMENT_FROM"
}
},
"encryption": {
"salt": "CITIZENOS_ENCRYPTION_SALT"
}
}
3 changes: 3 additions & 0 deletions config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,8 @@
"maxFileSize": 50000,
"baseFolder": null,
"baseURL": null
},
"encryption": {
"salt": "superSecretSalt"
}
}
3 changes: 3 additions & 0 deletions config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,8 @@
"maxFileSize": 50000,
"baseFolder": "",
"baseURL": ""
},
"encryption": {
"salt": "superSecretSalt"
}
}
203 changes: 184 additions & 19 deletions db/config/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 10.15 (Ubuntu 10.15-1.pgdg16.04+1)
-- Dumped by pg_dump version 10.15 (Ubuntu 10.15-0ubuntu0.18.04.1)
-- Dumped from database version 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1)
-- Dumped by pg_dump version 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1)

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down Expand Up @@ -31,17 +31,17 @@ COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


--
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;


--
-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: -
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed';
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';


--
Expand Down Expand Up @@ -748,21 +748,98 @@ CREATE TABLE public."Topics" (
description text,
status public."enum_Topics_status" DEFAULT 'inProgress'::public."enum_Topics_status" NOT NULL,
visibility public."enum_Topics_visibility" DEFAULT 'private'::public."enum_Topics_visibility" NOT NULL,
"creatorId" uuid NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
categories character varying(255)[] DEFAULT (ARRAY[]::character varying[])::character varying(255)[],
"sourcePartnerId" uuid,
"sourcePartnerObjectId" character varying(255),
"creatorId" uuid NOT NULL,
"tokenJoin" character varying(8) NOT NULL,
"padUrl" character varying(255) NOT NULL,
"endsAt" timestamp with time zone,
"sourcePartnerId" uuid,
hashtag character varying(60) DEFAULT NULL::character varying,
"sourcePartnerObjectId" character varying(255),
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
"authorIds" uuid[]
);


--
-- Name: COLUMN "Topics".title; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics".title IS 'Title of the Topic.';


--
-- Name: COLUMN "Topics".description; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics".description IS 'Short description of what the Topic is about.';


--
-- Name: COLUMN "Topics".status; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics".status IS 'Topic statuses.';


--
-- Name: COLUMN "Topics".visibility; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics".visibility IS 'Who can see (read) the Topic apart from the Members.';


--
-- Name: COLUMN "Topics"."sourcePartnerId"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics"."sourcePartnerId" IS 'The Partner id of the site from which the Topic was created';


--
-- Name: COLUMN "Topics"."sourcePartnerObjectId"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics"."sourcePartnerObjectId" IS 'The Partner object/entity id for mapping';


--
-- Name: COLUMN "Topics"."creatorId"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics"."creatorId" IS 'User ID of the creator of the Topic.';


--
-- Name: COLUMN "Topics"."tokenJoin"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics"."tokenJoin" IS 'Token for joining the Topic. Used for sharing public urls for Users to join the Topic.';


--
-- Name: COLUMN "Topics"."padUrl"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics"."padUrl" IS 'Etherpad Pad absolute url.';


--
-- Name: COLUMN "Topics"."endsAt"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics"."endsAt" IS 'Deadline for the Topic. If NULL then no deadline at all.';


--
-- Name: COLUMN "Topics".hashtag; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Topics".hashtag IS 'Hashtag to search related content from external sources.';


--
-- Name: COLUMN "Topics"."authorIds"; Type: COMMENT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -806,24 +883,94 @@ CREATE TABLE public."Users" (
id uuid NOT NULL,
name character varying(255),
company character varying(255),
language character varying(5) DEFAULT 'en'::character varying,
email character varying(254),
password character varying(64),
"passwordResetCode" uuid,
"emailIsVerified" boolean DEFAULT false NOT NULL,
"emailVerificationCode" uuid NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
language character varying(5) DEFAULT 'en'::character varying,
source public."enum_Users_source" NOT NULL,
"sourceId" character varying(255),
"imageUrl" character varying(255),
"termsVersion" character varying(255),
"termsAcceptedAt" timestamp with time zone,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
"authorId" character varying(255)
);


--
-- Name: COLUMN "Users".name; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users".name IS 'Full name of the user.';


--
-- Name: COLUMN "Users".company; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users".company IS 'Company name.';


--
-- Name: COLUMN "Users".language; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users".language IS 'Language code.';


--
-- Name: COLUMN "Users".email; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users".email IS 'User registration email.';


--
-- Name: COLUMN "Users".password; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users".password IS 'Password hash. NULL if User was created on invitation and has not registered.';


--
-- Name: COLUMN "Users"."emailIsVerified"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users"."emailIsVerified" IS 'Flag indicating if e-mail verification has been completed.';


--
-- Name: COLUMN "Users"."emailVerificationCode"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users"."emailVerificationCode" IS 'E-mail verification code that is sent out with e-mail as a link.';


--
-- Name: COLUMN "Users".source; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users".source IS 'User creation source.';


--
-- Name: COLUMN "Users"."sourceId"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users"."sourceId" IS 'User id in the source system. For Facebook their user id, for Google their user id and so on. Null is allowed as there is not point for CitizenOS to provide one.';


--
-- Name: COLUMN "Users"."imageUrl"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."Users"."imageUrl" IS 'User profile image url.';


--
-- Name: COLUMN "Users"."termsVersion"; Type: COMMENT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -907,10 +1054,18 @@ CREATE TABLE public."VoteLists" (
"optionGroupId" character varying(8) NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
"deletedAt" timestamp with time zone,
"userHash" character varying(64)
);


--
-- Name: COLUMN "VoteLists"."userHash"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."VoteLists"."userHash" IS 'Hash from users PID that allows filtering votes from different users, but same person';


--
-- Name: VoteLists_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -961,10 +1116,18 @@ CREATE TABLE public."VoteUserContainers" (
container bytea NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
"deletedAt" timestamp with time zone,
"PID" text NOT NULL
);


--
-- Name: COLUMN "VoteUserContainers"."PID"; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public."VoteUserContainers"."PID" IS 'User personal ID';


--
-- Name: Votes; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1285,7 +1448,7 @@ ALTER TABLE ONLY public."VoteOptions"
--

ALTER TABLE ONLY public."VoteUserContainers"
ADD CONSTRAINT "VoteUserContainers_pkey" PRIMARY KEY ("userId", "voteId");
ADD CONSTRAINT "VoteUserContainers_pkey" PRIMARY KEY ("voteId", "PID");


--
Expand Down Expand Up @@ -1858,4 +2021,6 @@ COPY public."SequelizeMeta" (name) FROM stdin;
20200225152502-remove-vote-user-container-activity.js
202010261616-alter-user-add-auhorID.js
20210310104918-create-group-invite-user.js
202103251231-alter-vote-lists-add-userhash.js
20210329141948-alter-vote-user-containers.js
\.
24 changes: 24 additions & 0 deletions db/migrations/202103251231-alter-vote-lists-add-userhash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const config = require('config');

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.addColumn('VoteLists', 'userHash', {
type: Sequelize.STRING(64),
comment: 'Hash from users PID that allows filtering votes from different users, but same person'
}, { transaction: t }),
queryInterface.sequelize.query(`CREATE EXTENSION IF NOT EXISTS pgcrypto;`, {transaction: t}),
queryInterface.sequelize.query(`UPDATE "VoteLists" vlt SET "userHash" = encode(hmac(v.id || uc."connectionUserId", '${config.encryption.salt}', 'sha256'), 'hex') FROM "VoteLists" vl JOIN "Votes" v ON v.id = vl."voteId" AND v."authType" = 'hard' JOIN "UserConnections" uc ON uc."userId"::text = vl."userId"::text AND uc."connectionId" = 'esteid' WHERE vl."optionGroupId" = vlt."optionGroupId" AND vl."optionId" = vlt."optionId";`, {transaction: t})
])
})
},
down: (queryInterface) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.removeColumn('VoteLists', 'userHash', { transaction: t })
])
})
}
};
42 changes: 42 additions & 0 deletions db/migrations/20210329141948-alter-vote-user-containers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.addColumn('VoteUserContainers', 'PID', {
type: Sequelize.TEXT,
comment: 'User personal ID'
}, { transaction: t }),
queryInterface.sequelize.query(`UPDATE "VoteUserContainers" vuc SET "PID" = vuc."userId"::text WHERE vuc."userId" IS NOT NULL;`, {transaction: t}),
queryInterface.sequelize.query(`UPDATE "VoteUserContainers" vuc SET "PID" = uc."connectionUserId"::text FROM "UserConnections" uc WHERE uc."userId"::text = vuc."userId"::text AND uc."connectionId" = 'esteid';`, {transaction: t}),
queryInterface.sequelize.query(`DELETE FROM "VoteUserContainers" a USING (SELECT "voteId", "PID", MAX("createdAt") as "createdAt" FROM "VoteUserContainers" GROUP BY "voteId", "PID") b WHERE a."voteId" = b."voteId" AND a."PID" = b."PID" AND a."createdAt" < b."createdAt";`, {transaction: t}),
queryInterface.changeColumn('VoteUserContainers', 'PID', {
type: Sequelize.TEXT,
allowNull: false,
}, {transaction: t}),
queryInterface.removeConstraint('VoteUserContainers','VoteUserContainers_pkey', {transaction: t}),
queryInterface.addConstraint('VoteUserContainers',{
fields: ['voteId', 'PID'],
type: 'primary key',
name: 'VoteUserContainers_pkey',
transaction: t
})
])
})
},
down: (queryInterface) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.removeConstraint('VoteUserContainers','VoteUserContainers_pkey', {transaction: t}),
queryInterface.addConstraint('VoteUserContainers',{
fields: ['voteId', 'userId'],
type: 'primary key',
name: 'VoteUserContainers_pkey',
transaction: t
}),
queryInterface.removeColumn('VoteUserContainers', 'PID', { transaction: t })
])
})
}
};
3 changes: 2 additions & 1 deletion db/models/Vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ module.exports = function (sequelize, DataTypes) {
description: this.dataValues.description,
type: this.dataValues.type,
authType: this.dataValues.authType,
downloads: this.dataValues.downloads // TODO: should be virtual?
downloads: this.dataValues.downloads, // TODO: should be virtual?
votersCount: this.dataValues.votersCount// TODO: should be virtual?
};

// If Vote eagerly loads VoteOptions...
Expand Down
Loading

0 comments on commit 076f7d2

Please sign in to comment.