Skip to content

Commit

Permalink
#387 DrawTool - Group Editing (#392)
Browse files Browse the repository at this point in the history
* #387 DrawTool - Group edit files Part 1

* #387 DrawTool - Group edit files Part 2
  • Loading branch information
tariqksoliman committed Jul 5, 2023
1 parent 9fac207 commit 8f794ce
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 56 deletions.
29 changes: 28 additions & 1 deletion API/Backend/Draw/models/filehistories.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const attributes = {
type: Sequelize.DataTypes.ARRAY(Sequelize.DataTypes.INTEGER),
allowNull: true,
},
author: {
type: Sequelize.STRING,
unique: false,
allowNull: true,
},
};

const options = {
Expand All @@ -57,5 +62,27 @@ var FilehistoriesTEST = sequelize.define(
options
);

// Adds to the table, never removes
const up = async () => {
// author column
await sequelize
.query(
`ALTER TABLE file_histories ADD COLUMN IF NOT EXISTS author varchar(255) NULL;`
)
.then(() => {
return null;
})
.catch((err) => {
logger(
"error",
`Failed to adding file_histories.author column. DB tables may be out of sync!`,
"file_histories",
null,
err
);
return null;
});
};

// export Filehistories model for use in other files.
module.exports = { Filehistories, FilehistoriesTEST };
module.exports = { Filehistories, FilehistoriesTEST, up };
48 changes: 48 additions & 0 deletions API/Backend/Draw/models/userfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ const attributes = {
allowNull: true,
defaultValue: null,
},
publicity_type: {
type: Sequelize.STRING,
unique: false,
allowNull: true,
},
public_editors: {
type: Sequelize.ARRAY(Sequelize.TEXT),
unique: false,
allowNull: true,
},
};

const options = {
Expand Down Expand Up @@ -153,6 +163,44 @@ const up = async () => {
);
return null;
});

// publicity_type column
await sequelize
.query(
`ALTER TABLE user_files ADD COLUMN IF NOT EXISTS publicity_type varchar(255) NULL;`
)
.then(() => {
return null;
})
.catch((err) => {
logger(
"error",
`Failed to adding user_files.publicity_type column. DB tables may be out of sync!`,
"user_files",
null,
err
);
return null;
});

// public_editors column
await sequelize
.query(
`ALTER TABLE user_files ADD COLUMN IF NOT EXISTS public_editors text[] NULL;`
)
.then(() => {
return null;
})
.catch((err) => {
logger(
"error",
`Failed to adding user_files.public_editors column. DB tables may be out of sync!`,
"user_files",
null,
err
);
return null;
});
};

// export User model for use in other files.
Expand Down
172 changes: 136 additions & 36 deletions API/Backend/Draw/routes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const pushToHistory = (
time,
undoToTime,
action_index,
user,
successCallback,
failureCallback
) => {
Expand Down Expand Up @@ -85,6 +86,7 @@ const pushToHistory = (
time: time,
action_index: action_index,
history: h,
author: user,
};
// Insert new entry into the history table
Table.create(newHistoryEntry)
Expand Down Expand Up @@ -252,6 +254,7 @@ const clipOver = function (
time,
null,
5,
req.user,
() => {
if (typeof successCallback === "function") successCallback();
},
Expand Down Expand Up @@ -392,6 +395,7 @@ const clipUnder = function (
time,
null,
7,
req.user,
() => {
if (typeof successCallback === "function") successCallback();
},
Expand Down Expand Up @@ -475,13 +479,28 @@ const add = function (
Files.findOne({
where: {
id: req.body.file_id,
[Sequelize.Op.or]: {
file_owner: req.user,
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
[Sequelize.Op.or]: [
{ file_owner: req.user },
{
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
},
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "list_edit",
public_editors: { [Sequelize.Op.contains]: [req.user] },
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "all_edit",
},
},
],
},
}).then((file) => {
if (!file) {
Expand Down Expand Up @@ -581,6 +600,7 @@ const add = function (
time,
null,
0,
req.user,
() => {
if (typeof successCallback === "function")
successCallback(created.id, created.intent);
Expand Down Expand Up @@ -665,13 +685,28 @@ const edit = function (req, res, successCallback, failureCallback) {
Files.findOne({
where: {
id: req.body.file_id,
[Sequelize.Op.or]: {
file_owner: req.user,
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
[Sequelize.Op.or]: [
{ file_owner: req.user },
{
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
},
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "list_edit",
public_editors: { [Sequelize.Op.contains]: [req.user] },
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "all_edit",
},
},
],
},
})
.then((file) => {
Expand Down Expand Up @@ -749,6 +784,7 @@ const edit = function (req, res, successCallback, failureCallback) {
time,
null,
1,
req.user,
() => {
successCallback(createdId, createdUUID, createdIntent);
},
Expand Down Expand Up @@ -822,13 +858,28 @@ router.post("/remove", function (req, res, next) {
Files.findOne({
where: {
id: req.body.file_id,
[Sequelize.Op.or]: {
file_owner: req.user,
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
[Sequelize.Op.or]: [
{ file_owner: req.user },
{
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
},
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "list_edit",
public_editors: { [Sequelize.Op.contains]: [req.user] },
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "all_edit",
},
},
],
},
}).then((file) => {
if (!file) {
Expand Down Expand Up @@ -861,6 +912,7 @@ router.post("/remove", function (req, res, next) {
time,
null,
2,
req.user,
() => {
logger("info", "Feature removed.", req.originalUrl, req);
res.send({
Expand Down Expand Up @@ -927,13 +979,28 @@ router.post("/undo", function (req, res, next) {
Files.findOne({
where: {
id: req.body.file_id,
[Sequelize.Op.or]: {
file_owner: req.user,
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
[Sequelize.Op.or]: [
{ file_owner: req.user },
{
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
},
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "list_edit",
public_editors: { [Sequelize.Op.contains]: [req.user] },
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "all_edit",
},
},
],
},
}).then((file) => {
if (!file) {
Expand Down Expand Up @@ -992,6 +1059,7 @@ router.post("/undo", function (req, res, next) {
time,
req.body.undo_time,
3,
req.user,
() => {
logger("info", "Undo successful.", req.originalUrl, req);
res.send({
Expand Down Expand Up @@ -1052,13 +1120,28 @@ router.post("/merge", function (req, res, next) {
Files.findOne({
where: {
id: req.body.file_id,
[Sequelize.Op.or]: {
file_owner: req.user,
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
[Sequelize.Op.or]: [
{ file_owner: req.user },
{
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
},
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "list_edit",
public_editors: { [Sequelize.Op.contains]: [req.user] },
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "all_edit",
},
},
],
},
}).then((file) => {
if (!file) {
Expand Down Expand Up @@ -1131,6 +1214,7 @@ router.post("/merge", function (req, res, next) {
time,
null,
6,
req.user,
() => {
logger(
"info",
Expand Down Expand Up @@ -1216,13 +1300,28 @@ router.post("/split", function (req, res, next) {
Files.findOne({
where: {
id: req.body.file_id,
[Sequelize.Op.or]: {
file_owner: req.user,
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
[Sequelize.Op.or]: [
{ file_owner: req.user },
{
[Sequelize.Op.and]: {
file_owner: "group",
file_owner_group: { [Sequelize.Op.overlap]: groups },
},
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "list_edit",
public_editors: { [Sequelize.Op.contains]: [req.user] },
},
},
{
[Sequelize.Op.and]: {
public: "1",
publicity_type: "all_edit",
},
},
],
},
})
.then((file) => {
Expand Down Expand Up @@ -1290,6 +1389,7 @@ router.post("/split", function (req, res, next) {
time,
null,
8,
req.user,
() => {
res.send({
status: "success",
Expand Down
Loading

0 comments on commit 8f794ce

Please sign in to comment.