Skip to content

Commit

Permalink
fixed-lint-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raissg committed Sep 5, 2024
1 parent feffbd8 commit b875022
Showing 1 changed file with 50 additions and 58 deletions.
108 changes: 50 additions & 58 deletions src/upgrades/1.1.1/upload_privileges.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,75 @@
const db = require('../../database');

module.exports = {
name: 'Giving upload privileges',
timestamp: Date.UTC(2016, 6, 12),
method: async function () {
console.log('graissov: Executing method function');
try {
const privilegesAPI = require('../../privileges');
const meta = require('../../meta');
name: 'Giving upload privileges',
timestamp: Date.UTC(2016, 6, 12),
method: async function () {
console.log('graissov: Executing method function');
const privilegesAPI = require('../../privileges');
const meta = require('../../meta');

const cids = await getCategoryIds();
await processCategories(cids, privilegesAPI, meta);
// Return success status (optional depending on what is expected)
return;
} catch (err) {
// Throw error to handle it further up the chain
throw err;
}
},
const cids = await getCategoryIds();
await processCategories(cids, privilegesAPI, meta);
},
};

// Helper function to get category IDs
function getCategoryIds() {
console.log('graissov: Executing getCategoryIds function');
return new Promise((resolve, reject) => {
db.getSortedSetRange('categories:cid', 0, -1, (err, cids) => {
if (err) {
return reject(err);
}
resolve(cids);
});
});
console.log('graissov: Executing getCategoryIds function');
return new Promise((resolve, reject) => {
db.getSortedSetRange('categories:cid', 0, -1, (err, cids) => {
if (err) {
return reject(err);
}
resolve(cids);
});
});
}

// Helper function to process each category
async function processCategories(cids, privilegesAPI, meta) {
console.log('graissov: Executing processCategories function');
await Promise.all(cids.map(async (cid) => {
const data = await getCategoryData(cid, privilegesAPI);
await processGroups(data.groups, cid, privilegesAPI, meta);
}));
console.log('graissov: Executing processCategories function');
await Promise.all(cids.map(async (cid) => {
const data = await getCategoryData(cid, privilegesAPI);
await processGroups(data.groups, cid, privilegesAPI, meta);
}));
}

// Helper function to get category data
function getCategoryData(cid, privilegesAPI) {
console.log('graissov: Executing getCategoryData function');
return new Promise((resolve, reject) => {
privilegesAPI.categories.list(cid, (err, data) => {
if (err) {
return reject(err);
}
resolve(data);
});
});
console.log('graissov: Executing getCategoryData function');
return new Promise((resolve, reject) => {
privilegesAPI.categories.list(cid, (err, data) => {
if (err) {
return reject(err);
}
resolve(data);
});
});
}

// Helper function to process groups within a category
async function processGroups(groups, cid, privilegesAPI, meta) {
console.log('graissov: Executing processGroups function');
await Promise.all(groups.map(async (group) => {
if (group.name === 'guests' && parseInt(meta.config.allowGuestUploads, 10) !== 1) {
return; // Skip guests if uploads are not allowed
}
if (group.privileges['groups:read']) {
await giveUploadPrivilege(cid, group.name, privilegesAPI);
}
}));
console.log('graissov: Executing processGroups function');
await Promise.all(groups.map(async (group) => {
if (group.name === 'guests' && parseInt(meta.config.allowGuestUploads, 10) !== 1) {
return; // Skip guests if uploads are not allowed
}
if (group.privileges['groups:read']) {
await giveUploadPrivilege(cid, group.name, privilegesAPI);
}
}));
}

// Helper function to give upload privileges
function giveUploadPrivilege(cid, groupName, privilegesAPI) {
console.log('graissov: Executing giveUploadPrivilege function');
return new Promise((resolve, reject) => {
privilegesAPI.categories.give(['upload:post:image'], cid, groupName, (err) => {
if (err) {
return reject(err);
}
resolve();
});
});
console.log('graissov: Executing giveUploadPrivilege function');
return new Promise((resolve, reject) => {
privilegesAPI.categories.give(['upload:post:image'], cid, groupName, (err) => {
if (err) {
return reject(err);
}
resolve();
});
});
}

0 comments on commit b875022

Please sign in to comment.