-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from drodil/new_access_rights
feat: add new resource types and rules for tags and collections
- Loading branch information
Showing
62 changed files
with
1,876 additions
and
739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
plugins/qeta-backend/migrations/20250114_collection_permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @param {import('knex').Knex} knex | ||
*/ | ||
exports.up = async function up(knex) { | ||
await knex.schema.alterTable('collections', table => { | ||
table.dropColumn('readAccess'); | ||
table.dropColumn('editAccess'); | ||
}); | ||
}; | ||
|
||
/** | ||
* @param {import('knex').Knex} knex | ||
*/ | ||
exports.down = async function down(knex) { | ||
await knex.schema.createTable('collections', table => { | ||
table.string('readAccess').defaultTo('private').notNullable(); | ||
table.string('editAccess').defaultTo('private').notNullable(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/** | ||
* @param {import('knex').Knex} knex | ||
*/ | ||
exports.up = async function up(knex) { | ||
// Combine comments to single table | ||
await knex.schema.createTable('comments', table => { | ||
table.string('author').notNullable(); | ||
table.text('content').notNullable(); | ||
table.datetime('created').notNullable(); | ||
table.datetime('updated').nullable(); | ||
table.string('updatedBy').nullable(); | ||
table.integer('postId').unsigned().nullable(); | ||
table.integer('answerId').unsigned().nullable(); | ||
table.increments('id'); | ||
table | ||
.foreign('postId') | ||
.references('id') | ||
.inTable('posts') | ||
.onDelete('CASCADE'); | ||
table | ||
.foreign('answerId') | ||
.references('id') | ||
.inTable('answers') | ||
.onDelete('CASCADE'); | ||
}); | ||
|
||
const postComments = await knex('post_comments').select(); | ||
for (const comment of postComments) { | ||
await knex('comments').insert({ | ||
author: comment.author, | ||
content: comment.content, | ||
created: comment.created, | ||
updated: comment.updated, | ||
updatedBy: comment.updatedBy, | ||
postId: comment.postId, | ||
}); | ||
} | ||
|
||
const answerComments = await knex('answer_comments').select(); | ||
for (const comment of answerComments) { | ||
await knex('comments').insert({ | ||
author: comment.author, | ||
content: comment.content, | ||
created: comment.created, | ||
updated: comment.updated, | ||
updatedBy: comment.updatedBy, | ||
answerId: comment.answerId, | ||
}); | ||
} | ||
|
||
await knex.schema.dropView('unique_authors'); | ||
|
||
await knex.schema.createView('unique_authors', view => { | ||
view.columns(['author']); | ||
view.as( | ||
knex.union([ | ||
knex('posts').select('author'), | ||
knex('answers').select('author'), | ||
knex('comments').select('author'), | ||
knex('post_views').select('author'), | ||
]), | ||
); | ||
}); | ||
|
||
await knex.schema.alterTable('post_comments', table => { | ||
table.dropForeign('postId', 'question_comments_questionid_foreign'); | ||
}); | ||
await knex.schema.alterTable('answer_comments', table => { | ||
table.dropForeign('answerId'); | ||
}); | ||
|
||
await knex.schema.dropTable('post_comments'); | ||
await knex.schema.dropTable('answer_comments'); | ||
}; | ||
|
||
/** | ||
* @param {import('knex').Knex} knex | ||
*/ | ||
exports.down = async function down(knex) { | ||
await knex.schema.createTable('post_comments', table => { | ||
table.string('author').notNullable(); | ||
table.text('content').notNullable(); | ||
table.datetime('created').notNullable(); | ||
table.datetime('updated').nullable(); | ||
table.string('updatedBy').nullable(); | ||
table.integer('postId').unsigned().notNullable(); | ||
table.increments('id'); | ||
table | ||
.foreign('postId') | ||
.references('id') | ||
.inTable('questions') | ||
.onDelete('CASCADE'); | ||
}); | ||
|
||
await knex.schema.createTable('answer_comments', table => { | ||
table.string('author').notNullable(); | ||
table.text('content').notNullable(); | ||
table.datetime('created').notNullable(); | ||
table.datetime('updated').nullable(); | ||
table.string('updatedBy').nullable(); | ||
table.integer('answerId').unsigned().notNullable(); | ||
table.increments('id'); | ||
table | ||
.foreign('answerId') | ||
.references('id') | ||
.inTable('answers') | ||
.onDelete('CASCADE'); | ||
}); | ||
|
||
const comments = await knex('comments').select(); | ||
for (const comment of comments) { | ||
if (comment.postId) { | ||
await knex('post_comments').insert({ | ||
author: comment.author, | ||
content: comment.content, | ||
created: comment.created, | ||
updated: comment.updated, | ||
updatedBy: comment.updatedBy, | ||
postId: comment.postId, | ||
}); | ||
} else { | ||
await knex('answer_comments').insert({ | ||
author: comment.author, | ||
content: comment.content, | ||
created: comment.created, | ||
updated: comment.updated, | ||
updatedBy: comment.updatedBy, | ||
answerId: comment.answerId, | ||
}); | ||
} | ||
} | ||
|
||
await knex.schema.dropView('unique_authors'); | ||
await knex.schema.createView('unique_authors', view => { | ||
view.columns(['author']); | ||
view.as( | ||
knex.union([ | ||
knex('posts').select('author'), | ||
knex('answers').select('author'), | ||
knex('answer_comments').select('author'), | ||
knex('post_comments').select('author'), | ||
knex('post_views').select('author'), | ||
]), | ||
); | ||
}); | ||
|
||
await knex.schema.dropTable('comments'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.