Commit 59c1d697 authored by Boiget Boiget's avatar Boiget Boiget

Fix lint errors

parent a346cb05
Pipeline #2324 passed with stages
in 5 minutes and 9 seconds
import axios from 'axios';
import { Meteor } from 'meteor/meteor';
const _checkFolderActive = function (response) {
// checks that 'Group Folder' API is responding
if (response.data === undefined || response.data.ocs === undefined) {
console.log(`Nexcloud: ERROR, make sure 'Group Folders' application is active`);
return false;
}
return true;
};
class NextcloudClient {
constructor() {
const ncURL = Meteor.settings.public.nextcloudURL || '';
......@@ -50,7 +59,6 @@ class NextcloudClient {
)
.then((response) => {
const infos = response.data.ocs.meta;
console.log(response.data.ocs.meta);
if (infos.status === 'ok') {
console.log(`Nextcloud: group ${groupName} added`);
} else {
......@@ -65,15 +73,7 @@ class NextcloudClient {
});
}
_checkFolderActive(response) {
if (response.data === undefined || response.data.ocs === undefined) {
console.log(`Nexcloud: ERROR, make sure 'Group Folders' application is active`);
return false;
}
return true;
}
_addGroupToFolder(groupName, folderId) {
_addGroupToFolder(groupName, folderName, folderId) {
return axios
.post(
`${this.appsURL}/groupfolders/folders/${folderId}/groups`,
......@@ -107,11 +107,10 @@ class NextcloudClient {
},
},
)
.then((response) => response.data.ocs.meta.status === 'ok');
} else {
console.log(`Nextcloud: could not assign group ${groupName} to folder ${folderName}`);
return false;
.then((resp) => resp.data.ocs.meta.status === 'ok');
}
console.log(`Nextcloud: could not assign group ${groupName} to folder ${folderName}`);
return false;
});
}
......@@ -134,9 +133,9 @@ class NextcloudClient {
)
.then((response) => {
const infos = response.data.ocs.meta;
if (this._checkFolderActive(response) && infos.status === 'ok') {
if (_checkFolderActive(response) && infos.status === 'ok') {
console.log(`Nextcloud: group folder ${folderName} added`);
return this._addGroupToFolder(groupName, response.data.ocs.data.id).then((resp) => {
return this._addGroupToFolder(groupName, folderName, response.data.ocs.data.id).then((resp) => {
if (resp === true) {
console.log(`Nextcloud: access and permissions set for group folder ${folderName}`);
} else {
......@@ -144,10 +143,9 @@ class NextcloudClient {
}
return resp;
});
} else {
console.log(`Nextcloud: ERROR adding group folder ${folderName}`);
return false;
}
console.log(`Nextcloud: ERROR adding group folder ${folderName}`);
return false;
})
.catch((error) => {
console.log(`Nextcloud: ERROR adding group folder ${folderName}`);
......@@ -167,7 +165,7 @@ class NextcloudClient {
},
})
.then((response) => {
if (this._checkFolderActive(response) && response.data.ocs.meta.status === 'ok') {
if (_checkFolderActive(response) && response.data.ocs.meta.status === 'ok') {
// find groupFolder ID for groupName
const folders = Object.values(response.data.ocs.data).filter((entry) => {
return entry.mount_point === groupName && Object.keys(entry.groups).includes(groupName);
......@@ -184,19 +182,19 @@ class NextcloudClient {
'OCS-APIRequest': true,
},
})
.then((response) => {
const infos = response.data.ocs.meta;
.then((resp) => {
const infos = resp.data.ocs.meta;
if (infos.status === 'ok') {
console.log(`Nextcloud: removed group folder ${folder.id} (${folder.mount_point})`);
return true;
} else {
console.log(`Nextcloud: ERROR deleting group folder ${folder.id} (${infos.message})`);
return false;
}
console.log(`Nextcloud: ERROR deleting group folder ${folder.id} (${infos.message})`);
return false;
});
}),
).then((responses) => !responses.includes(false));
} else return false;
}
return false;
});
}
......@@ -226,4 +224,5 @@ class NextcloudClient {
}
const nextEnabled = Meteor.settings.public.enableNextcloud === true;
export default nextClient = Meteor.isServer && nextEnabled ? new NextcloudClient() : null;
const nextClient = Meteor.isServer && nextEnabled ? new NextcloudClient() : null;
export default nextClient;
......@@ -65,7 +65,7 @@ export const unfavGroup = new ValidatedMethod({
},
});
const _createGroup = function ({ name, type, content, description, nextcloud, userId }) {
function _createGroup({ name, type, content, description, nextcloud, userId }) {
try {
const groupId = Groups.insert({
name,
......@@ -78,7 +78,7 @@ const _createGroup = function ({ name, type, content, description, nextcloud, us
nextcloud,
});
Roles.addUsersToRoles(userId, 'admin', groupId);
favGroup._execute({ userId: userId }, { groupId });
favGroup._execute({ userId }, { groupId });
} catch (error) {
if (error.code === 11000) {
throw new Meteor.Error('api.groups.createGroup.duplicateName', i18n.__('api.groups.groupAlreadyExist'));
......@@ -86,7 +86,7 @@ const _createGroup = function ({ name, type, content, description, nextcloud, us
throw error;
}
}
};
}
export const createGroup = new ValidatedMethod({
name: 'groups.createGroup',
......@@ -116,15 +116,15 @@ export const createGroup = new ValidatedMethod({
'api.groups.createGroup.nextcloudError',
i18n.__('api.nextcloud.addGroupFolderError'),
);
else _createGroup({ name, type, content, description, nextcloud, userId: this.userId });
else return _createGroup({ name, type, content, description, nextcloud, userId: this.userId });
});
} else {
const msg =
response === 'group exists' ? i18n.__('api.nextcloud.groupExists') : i18n.__('api.nextcloud.addGroupError');
throw new Meteor.Error('api.groups.createGroup.nextcloudError', msg);
}
const msg =
response === 'group exists' ? i18n.__('api.nextcloud.groupExists') : i18n.__('api.nextcloud.addGroupError');
throw new Meteor.Error('api.groups.createGroup.nextcloudError', msg);
});
} else _createGroup({ name, type, content, description, nextcloud, userId: this.userId });
}
return _createGroup({ name, type, content, description, nextcloud, userId: this.userId });
},
});
......@@ -158,8 +158,8 @@ export const removeGroup = new ValidatedMethod({
Meteor.users.update({ favGroups: { $all: [groupId] } }, { $pull: { favGroups: groupId } }, { multi: true });
if (nextClient && group.nextcloud) {
// remove group from nextcloud if it exists
return nextClient.groupExists(group.name).then((res) => {
if (res) {
return nextClient.groupExists(group.name).then((resExists) => {
if (resExists) {
return nextClient.removeGroupFolder(group.name).then((response) => {
if (response)
return nextClient.removeGroup(group.name).then((res) => {
......@@ -169,19 +169,20 @@ export const removeGroup = new ValidatedMethod({
i18n.__('api.nextcloud.removeGroupError'),
);
});
else
throw new Meteor.Error(
'api.groups.removeGroup.nextcloudError',
i18n.__('api.nextcloud.removeGroupFolderError'),
);
throw new Meteor.Error(
'api.groups.removeGroup.nextcloudError',
i18n.__('api.nextcloud.removeGroupFolderError'),
);
});
}
return null;
});
}
return null;
},
});
const _updateGroup = function (groupId, groupData) {
function _updateGroup(groupId, groupData) {
try {
Groups.update({ _id: groupId }, { $set: groupData });
} catch (error) {
......@@ -191,7 +192,7 @@ const _updateGroup = function (groupId, groupData) {
throw error;
}
}
};
}
export const updateGroup = new ValidatedMethod({
name: 'groups.updateGroup',
......@@ -246,8 +247,8 @@ export const updateGroup = new ValidatedMethod({
const nextRequired = data.nextcloud === true || (data.nextcloud === undefined && group.nextcloud === true);
if (nextClient && nextRequired) {
const groupName = groupData.name || group.name;
return nextClient.groupExists(groupName).then((res) => {
if (res === false) {
return nextClient.groupExists(groupName).then((resExists) => {
if (resExists === false) {
return nextClient.addGroup(groupName).then((response) => {
if (response === 'ok') {
return nextClient.addGroupFolder(groupName, groupName).then((res) => {
......@@ -256,19 +257,20 @@ export const updateGroup = new ValidatedMethod({
'api.groups.updateGroup.nextcloudError',
i18n.__('api.nextcloud.addGroupFolderError'),
);
else _updateGroup(groupId, groupData);
_updateGroup(groupId, groupData);
});
} else {
const msg =
response === 'group exists'
? i18n.__('api.nextcloud.groupExists')
: i18n.__('api.nextcloud.addGroupError');
throw new Meteor.Error('api.groups.updateGroup.nextcloudError', msg);
}
const msg =
response === 'group exists'
? i18n.__('api.nextcloud.groupExists')
: i18n.__('api.nextcloud.addGroupError');
throw new Meteor.Error('api.groups.updateGroup.nextcloudError', msg);
});
} else _updateGroup(groupId, groupData);
}
return _updateGroup(groupId, groupData);
});
} else _updateGroup(groupId, groupData);
}
return _updateGroup(groupId, groupData);
},
});
......
......@@ -19,14 +19,14 @@ Meteor.startup(() => {
const rememberMe = window.localStorage.getItem('rememberMe') || 'false';
if (rememberMe === 'false') {
// warns user when he closes window / reloads page
window.onbeforeunload = function (event) {
window.onbeforeunload = function onBeforeUnload(event) {
// Cancel the event as stated by the standard.
event.preventDefault();
// Safari
return '';
};
// disconnect user if 'remember me' is disabled
window.onunload = function () {
window.onunload = function onUnload() {
Meteor.logout();
window.localStorage.clear('Meteor.loginToken');
window.localStorage.clear('Meteor.loginTokenExpires');
......
......@@ -46,7 +46,8 @@
},
"nextcloud": {
"nextcloudUser": "",
"nextcloudPassword": ""
"nextcloudPassword": "",
"nextcloudQuota": ""
},
"private": {
"fillWithFakeData": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment