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

[GSoC][Feature Request] : Plugin Architecture for Server #730

Merged
merged 57 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
0f0878c
Test : lib/resolvers/group_chat_query/groupChatMessages.js
SiddheshKukade Jun 1, 2022
32b5132
Add Test : Added Valid JSON Check
SiddheshKukade Jun 1, 2022
102b9fb
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade Jun 3, 2022
f45b1b8
Create README.md
SiddheshKukade Jun 6, 2022
2303ef0
Merge pull request #15 from SiddheshKukade/SiddheshKukade-patch-1
SiddheshKukade Jun 6, 2022
f1c5c4b
Create README.md
SiddheshKukade Jun 6, 2022
31f5d82
Merge pull request #18 from SiddheshKukade/SiddheshKukade-patch-3
SiddheshKukade Jun 6, 2022
21ba18d
Update is-auth.js
SiddheshKukade Jun 7, 2022
02678fc
AddedDocs
SiddheshKukade Jun 7, 2022
053e797
Merge pull request #19 from SiddheshKukade/SiddheshKukade-patch-4
SiddheshKukade Jun 9, 2022
2b608ac
Update index.js
SiddheshKukade Jun 9, 2022
d104941
completed
SiddheshKukade Jun 9, 2022
ad7de9b
Merge pull request #27 from SiddheshKukade/SiddheshKukade-patch-3-1
SiddheshKukade Jun 9, 2022
672f8c4
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade Jul 7, 2022
8811ac7
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade Jul 14, 2022
dea8345
sample
SiddheshKukade Jul 15, 2022
120e110
Merge branch 'develop' of https://github.com/SiddheshKukade/talawa-ap…
SiddheshKukade Jul 15, 2022
2899e9d
update/index.js
SiddheshKukade Jul 16, 2022
9793dc0
update/index.js
SiddheshKukade Jul 16, 2022
f237fb6
update/is-auth.js
SiddheshKukade Jul 16, 2022
8695f85
Update/readme.md
SiddheshKukade Jul 16, 2022
df571ce
update/image-readme
SiddheshKukade Jul 16, 2022
6cc93d9
Add/query-schema
SiddheshKukade Jul 16, 2022
c61c5cc
Update/Plugin-graphQL-schema
SiddheshKukade Jul 16, 2022
d486d5a
Add/Plugin-MongoDB-Model
SiddheshKukade Jul 16, 2022
26deefa
Add/createPlugin-and-refractoring
SiddheshKukade Jul 16, 2022
7d8983d
Add/getPlugins
SiddheshKukade Jul 16, 2022
d6ad5c6
Add/Mutation/UpdatePluginStatus
SiddheshKukade Jul 16, 2022
01e3caf
Add/Mutation/updateTempPluginInstalledOrgs
SiddheshKukade Jul 16, 2022
cabd4c9
Add/Mutation/Schema
SiddheshKukade Jul 16, 2022
cfc4663
Add/import/mutations
SiddheshKukade Jul 16, 2022
ce8d2dc
Add/plugins
SiddheshKukade Jul 16, 2022
dd3e302
Fix/path-err
SiddheshKukade Jul 16, 2022
2d3f5b7
Fix/Erros
SiddheshKukade Jul 16, 2022
1474b54
update/lockfile
SiddheshKukade Jul 16, 2022
f37cb43
Merge branch 'develop' of https://github.com/SiddheshKukade/talawa-ap…
SiddheshKukade Jul 16, 2022
da439d7
Add/plugin-model
SiddheshKukade Jul 23, 2022
289d71c
Update is-auth.js
SiddheshKukade Jul 23, 2022
00cf874
Removed extra queries
SiddheshKukade Jul 24, 2022
13eaa91
Documentation added for plugin queries and models
SiddheshKukade Jul 24, 2022
d7932e1
Fix/`delelte cr in prettier/prettier`
SiddheshKukade Jul 24, 2022
a371df0
Merge branch 'develop' of https://github.com/SiddheshKukade/talawa-ap…
SiddheshKukade Jul 24, 2022
36ff8aa
updated : mutation
SiddheshKukade Jul 24, 2022
cc657d6
Add/test `getPlugins`
SiddheshKukade Jul 25, 2022
990e72a
Fix/`lint error`
SiddheshKukade Jul 25, 2022
dd39ab2
test `updatePluginInstalledOrgs`
SiddheshKukade Jul 25, 2022
4a17fdc
Test/ `updateInstallStatus`
SiddheshKukade Jul 25, 2022
5957a8c
Fix/Erros-1
SiddheshKukade Jul 27, 2022
b4a6f7c
Fix/Erros-2
SiddheshKukade Jul 27, 2022
f9edd50
Fix/Erros-3
SiddheshKukade Jul 27, 2022
797cbd3
Test/`Queries.js`
SiddheshKukade Jul 27, 2022
ff9749b
Test/`Mutation.js`
SiddheshKukade Jul 27, 2022
524f1ee
remove extra `console.log`
SiddheshKukade Aug 1, 2022
28f3641
Merge branch 'develop' into develop
SiddheshKukade Aug 4, 2022
5ba6b90
Delete admin-plugin-query.js
SiddheshKukade Aug 6, 2022
5dd5482
Delete super-admin-plugin-query.js
SiddheshKukade Aug 6, 2022
54afb73
Fix/Package-lock
SiddheshKukade Aug 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"endOfLine": "auto"
}
Empty file added image/README.md
Empty file.
1 change: 0 additions & 1 deletion lib/middleware/is-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,4 @@ const isAuth = (req) => {
userId,
};
};

module.exports = isAuth;
35 changes: 35 additions & 0 deletions lib/models/Plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
/**
* @name pluginSchema
* @description Schema for MongoDB database
* @param {string} pluginName Name of the plugin preferred having underscores "_"
* @param {string} pluginCreatedBy name of the plugin creator ex.John Doe
* @param {string} pluginDesc brief description of the plugin and it's features
* @param {Boolean} pluginInstallStatus shows if the plugin is enabled or not
* @param {String[]} installedOrgs list of orgIDs on which the plugin is enabled
*/
const pluginSchema = new Schema({
pluginName: {
type: String,
required: true,
},
pluginCreatedBy: {
type: String,
required: true,
},
pluginDesc: {
type: String,
required: true,
},
pluginInstallStatus: {
type: Boolean,
required: true,
default: false,
},
installedOrgs: [
{ type: Schema.Types.ObjectId, required: false, default: [] },
],
});

module.exports = mongoose.model('PluginTemp', pluginSchema);
49 changes: 0 additions & 49 deletions lib/models/Plugins.js

This file was deleted.

10 changes: 8 additions & 2 deletions lib/resolvers/Mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ const removeUserFromGroupChat = require('./group_chat_mutations/removeUserFromGr
const updateLanguage = require('./language_mutation/updateLanguage');
const blockPluginCreationBySuperadmin = require('../resolvers/user_mutations/blockForPlugin');

const createPlugin = require('./plugin_mutations/createPlugin');
const createMessageChat = require('./message_chat_mutation/createMessageChat');
const addLanguageTranslation = require('./language_maintainer_mutation/addLanguageTranslation');

const createPlugin = require('./plugin_mutations/createPlugin');
const updatePluginStatus = require('./plugin_mutations/updatePluginStatus');
const updatePluginInstalledOrgs = require('./plugin_mutations/updatePluginInstalledOrgs');

const Mutation = {
signUp,
login,
Expand Down Expand Up @@ -135,10 +138,13 @@ const Mutation = {
addUserToGroupChat,
removeUserFromGroupChat,
blockPluginCreationBySuperadmin,
createPlugin,

createMessageChat,
addLanguageTranslation,

createPlugin,
updatePluginStatus,
updatePluginInstalledOrgs,
};

module.exports = Mutation;
7 changes: 2 additions & 5 deletions lib/resolvers/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ const postsByOrganizationConnection = require('../resolvers/post_organization_qu
const { users, user, me } = require('./user_query/users');
const { usersConnection } = require('./user_query/users');
const { organizationsMemberConnection } = require('./user_query/users');
const plugin = require('./plugin_query/super-admin-plugin-query');
const adminPlugin = require('./plugin_query/admin-plugin-query');
const myLanguage = require('../resolvers/user_query/myLanguage');
const userLanguage = require('../resolvers/user_query/userLanguage');
const getlanguage = require('../resolvers/language_maintainer_query/getlanguage');
const directChatsByUserID = require('./direct_chat_query/directChatsByUserID');
const directChatsMessagesByChatID = require('./direct_chat_query/directChatsMessagesByChatID');
const checkAuth = require('./auth_query/checkAuth');

const getPlugins = require('./plugin_query/getPlugins');
const Query = {
me,
user,
Expand Down Expand Up @@ -69,10 +67,9 @@ const Query = {

myLanguage,
userLanguage,
plugin,
adminPlugin,

getlanguage,
getPlugins,
};

module.exports = Query;
82 changes: 17 additions & 65 deletions lib/resolvers/plugin_mutations/createPlugin.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,23 @@
const User = require('../../models/User');
const Plugin = require('../../models/Plugins');
const PluginField = require('../../models/PluginsField');
const Organization = require('../../models/Organization');

const { UnauthorizedError } = require('errors');
const { NotFoundError } = require('errors');
const requestContext = require('talawa-request-context');

const Plugin = require('../../models/Plugin');
/**
* @name createPlugin creates a Plugin and return the same
* @description creates a document of Plugin type and stores it in database
* @param {any} parent parent of current request
* @param {object} args payload provided with the request
* @param {any} context context of entire application
*/
// eslint-disable-next-line no-unused-vars
module.exports = async (parent, args, context) => {
let org = await Organization.findOne({
_id: args.plugin.orgId,
});

if (!org) {
throw new NotFoundError(
requestContext.translate('organization.notFound'),
'organization.notFound',
'organization'
);
}

const user = await User.findOne({
_id: context.userId,
pluginCreationAllowed: true,
});

if (!user) {
throw new NotFoundError(
requestContext.translate('user.notFound'),
'user.notFound',
'user'
);
}

const isSuperAdmin = user.userType === 'SUPERADMIN';
if (!isSuperAdmin) {
const isAdmin = org.admins.includes(user.id);
if (!isAdmin) {
throw new UnauthorizedError(
requestContext.translate('user.notAuthorized'),
'user.notAuthorized',
'userAuthorization'
);
}
}

let pluginAddnFields = [];
if (args.plugin.fields.length > 0) {
for (let i = 0; i < args.plugin.fields.length; i++) {
let pluginField = new PluginField({
key: args.plugin.fields[i].key,
value: args.plugin.fields[i].value,
});

pluginAddnFields.push(pluginField);
}
}

//create MongoDB document
let plugin = new Plugin({
orgId: args.plugin.orgId,
pluginName: args.plugin.pluginName,
pluginKey: args.plugin.pluginKey,
additionalInfo: pluginAddnFields,
pluginName: args.pluginName,
pluginCreatedBy: args.pluginCreatedBy,
pluginDesc: args.pluginDesc,
pluginInstallStatus: args.pluginInstallStatus,
installedOrgs: args.installedOrgs,
});

plugin = await plugin.save();

//store the plugin
plugin = await Plugin.save();
return {
...plugin._doc,
};
Expand Down
47 changes: 47 additions & 0 deletions lib/resolvers/plugin_mutations/updatePluginInstalledOrgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const Plugin = require('../../models/Plugin');
/**
* @name updatePluginInstalledOrgs
* @description updates the installedOrgs list of the specific plugin and adds or removes the current orgId from the list.
* @param {any} parent parent of current request
* @param {object} args payload provided with the request
* @param {any} context context of entire application
*/
// eslint-disable-next-line no-unused-vars
module.exports = async (parent, args, context) => {
let plug = await Plugin.findById(args.id);
const plugOrgList = plug?.installedOrgs;
const isDuplicate = plugOrgList?.includes(args.orgId);
// remove the entry if duplicate
if (isDuplicate) {
// eslint-disable-next-line no-unused-vars
const result = await Plugin.findByIdAndUpdate(
args.id,
{ $pull: { installedOrgs: args.orgId } },
{ new: true },
(err, res) => {
if (err) {
console.log(err);
} else {
console.log('Updated Plugin with installed orgs : ', res);
}
}
);
} else {
// eslint-disable-next-line no-unused-vars
const result = await Plugin.findByIdAndUpdate(
args.id,
{ $push: { installedOrgs: args.orgId } },
{ new: true },
(err, res) => {
if (err) {
console.log(err);
} else {
console.log('Updated Plugin with installed orgs : ', res);
}
}
);
}

plug = await Plugin.findById(args.id);
return plug;
};
27 changes: 27 additions & 0 deletions lib/resolvers/plugin_mutations/updatePluginStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Plugin = require('../../models/Plugin');
/**
* @name updatePluginStatus
* @description toggles the installStatus of the plugin
* @param {any} parent parent of current request
* @param {object} args payload provided with the request
* @param {any} context context of entire application
*/
// eslint-disable-next-line no-unused-vars
module.exports = async (parent, args, context) => {
console.log('Argment s ', args);
// eslint-disable-next-line no-unused-vars
const result = await Plugin.findByIdAndUpdate(
args.id,
{ pluginInstallStatus: args.status },
{ new: true },
(err, res) => {
if (err) {
console.log(err);
} else {
console.log('Updated Plugin : ', res);
}
}
);
const plug = await Plugin.findById(args.id);
return plug;
};
29 changes: 0 additions & 29 deletions lib/resolvers/plugin_query/admin-plugin-query.js

This file was deleted.

8 changes: 8 additions & 0 deletions lib/resolvers/plugin_query/getPlugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Plugin = require('../../models/Plugin');
/**
* @name getPlugins a GraphQL Query
* @description returns list of plugin from database
*/
module.exports = async () => {
return await Plugin.find();
};
Loading