|
@@ -1,53 +1,153 @@
|
|
-module.exports = {
|
|
|
|
- addGroups: function (user, groups){
|
|
|
|
- teamArray=[]
|
|
|
|
- teams = user.teams
|
|
|
|
- if (!teams)
|
|
|
|
|
|
+// creates Object if not present in collection
|
|
|
|
+// initArr = [displayName, shortName, website, isActive]
|
|
|
|
+// objString = ["Org","Team"] for method mapping
|
|
|
|
+function createObject(initArr, objString)
|
|
|
|
+{
|
|
|
|
+ functionName = objString === "Org" ? 'setCreateOrgFromOidc' : 'setCreateTeamFromOidc';
|
|
|
|
+ creationString = 'setCreate'+ objString + 'FromOidc';
|
|
|
|
+ return Meteor.call(functionName,
|
|
|
|
+ initArr[0],//displayName
|
|
|
|
+ initArr[1],//desc
|
|
|
|
+ initArr[2],//shortName
|
|
|
|
+ initArr[3],//website
|
|
|
|
+ initArr[4]//xxxisActive
|
|
|
|
+ );
|
|
|
|
+}
|
|
|
|
+//checks whether obj is in collection of userObjs
|
|
|
|
+//params
|
|
|
|
+//e.g. userObjs = user.teams
|
|
|
|
+//e.g. obj = Team.findOne...
|
|
|
|
+//e.g. collection = "team"
|
|
|
|
+function contains(userObjs, obj, collection)
|
|
|
|
+{
|
|
|
|
+ id = collection+'Id';
|
|
|
|
+
|
|
|
|
+ if(!userObjs.length)
|
|
{
|
|
{
|
|
- for (group of groups){
|
|
|
|
- team = Team.findOne({"teamDisplayName": group});
|
|
|
|
- if (team)
|
|
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ for (const [count, hash] of Object.entries(userObjs))
|
|
|
|
+ {
|
|
|
|
+ if (hash[id] === obj._id)
|
|
{
|
|
{
|
|
- team_hash = {'teamId': team._id, 'teamDisplayName': group}
|
|
|
|
- teamArray.push(team_hash);
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- teams = {'teams': teamArray}
|
|
|
|
- users.update({ _id: user._id }, { $set: teams});
|
|
|
|
- return;
|
|
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+module.exports = {
|
|
|
|
+ // Soft version of adding teams to user via Oidc
|
|
|
|
+ // teams won't be created if nonexistent
|
|
|
|
+ // groups are treated as teams in the general case
|
|
|
|
+ addGroups: function (user, groups){
|
|
|
|
+ teamArray=[];
|
|
|
|
+ teams = user.teams;
|
|
|
|
+ orgArray=[];
|
|
|
|
+ for (group of groups){
|
|
|
|
+ team = Team.findOne({"teamDisplayName": group});
|
|
|
|
+ if(team)
|
|
|
|
+ {
|
|
|
|
+ if (contains(teams,team,"team"))
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ teamArray.push({'teamId': Team.findOne({'teamDisplayName': group})._id, 'teamDisplayName': group});
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ teams = {'teams': { '$each': teamArray}};
|
|
|
|
+ users.update({ _id: user._id }, { $push: teams});
|
|
|
|
+},
|
|
|
|
|
|
- for (group of groups){
|
|
|
|
- team = Team.findOne({"teamDisplayName": group})
|
|
|
|
- team_contained= false;
|
|
|
|
- if (team)
|
|
|
|
|
|
+// This function adds groups as organizations or teams to users and
|
|
|
|
+// creates them if not already existing
|
|
|
|
+// DEFAULT after creation orgIsActive & teamIsActive: true
|
|
|
|
+// PODC provider needs to send group data within "wekanGroup" scope
|
|
|
|
+// PARAMS to be set for groups within your Oidc provider:
|
|
|
|
+// isAdmin: [true, false] -> admin group becomes admin in wekan
|
|
|
|
+// isOrganization: [true, false] -> creates org and adds to user
|
|
|
|
+// displayName: "string"
|
|
|
|
+addGroupsWithAttributes: function (user, groups){
|
|
|
|
+ teamArray=[];
|
|
|
|
+ orgArray=[];
|
|
|
|
+ teams = user.teams;
|
|
|
|
+ orgs = user.orgs;
|
|
|
|
+ for (group of groups)
|
|
|
|
+ {
|
|
|
|
+ isOrg = group.isOrganisation || false;
|
|
|
|
+ forceCreate = group.forceCreate|| false;
|
|
|
|
+ if (isOrg)
|
|
|
|
+ {
|
|
|
|
+ org = Org.findOne({"orgDisplayName": group.displayName});
|
|
|
|
+ if(org)
|
|
{
|
|
{
|
|
- team_hash = {'teamId': team._id, 'teamDisplayName': group}
|
|
|
|
- for (const [count,teams_hash] of Object.entries(teams))
|
|
|
|
|
|
+ if(contains(orgs, org, "org"))
|
|
{
|
|
{
|
|
- if (teams_hash["teamId"] === team._id)
|
|
|
|
- {
|
|
|
|
- team_contained=true;
|
|
|
|
- break;
|
|
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (team_contained)
|
|
|
|
|
|
+ else if(forceCreate)
|
|
|
|
+ {
|
|
|
|
+ initAttributes = [
|
|
|
|
+ group.displayName,
|
|
|
|
+ group.desc || group.displayName,
|
|
|
|
+ group.shortName ||group.displayName,
|
|
|
|
+ group.website || group.displayName, group.isActive || false]
|
|
|
|
+ createObject(initAttributes, "Org");
|
|
|
|
+ org = Org.findOne({'orgDisplayName': group.displayName});
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ orgHash = {'orgId': org._id, 'orgDisplayName': group.displayName};
|
|
|
|
+ orgArray.push(orgHash);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //start team routine
|
|
|
|
+ team = Team.findOne({"teamDisplayName": group.displayName});
|
|
|
|
+ if (team)
|
|
|
|
+ {
|
|
|
|
+ if(contains(teams, team, "team"))
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(forceCreate)
|
|
|
|
+ {
|
|
|
|
+ initAttributes = [
|
|
|
|
+ group.displayName,
|
|
|
|
+ group.desc || group.displayName,
|
|
|
|
+ group.shortName ||group.displayName,
|
|
|
|
+ group.website || group.displayName,
|
|
|
|
+ group.isActive || false]
|
|
|
|
+ createObject(initAttributes, "Team");
|
|
|
|
+ team = Team.findOne({'teamDisplayName': group.displayName});
|
|
|
|
+ }
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- console.log("TEAM to be added:", team);
|
|
|
|
- teams.push({'teamId': Team.findOne({'teamDisplayName': group})._id, 'teamDisplayName': group});
|
|
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
+ teamHash = {'teamId': team._id, 'teamDisplayName': group.displayName};
|
|
|
|
+ teamArray.push(teamHash);
|
|
|
|
+ }
|
|
|
|
+ // user is assigned to group which has set isAdmin: true in oidc data
|
|
|
|
+ // hence user will get admin privileges in wekan
|
|
|
|
+ if(group.isAdmin){
|
|
|
|
+ users.update({ _id: user._id }, { $set: {isAdmin: true}});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- console.log("XXXXXXXXXXX Team Array: ", teams);
|
|
|
|
- teams = {'teams': teams}
|
|
|
|
- users.update({ _id: user._id }, { $set: teams});
|
|
|
|
- }
|
|
|
|
|
|
+ teams = {'teams': {'$each': teamArray}};
|
|
|
|
+ orgs = {'orgs': {'$each': orgArray}};
|
|
|
|
+ users.update({ _id: user._id }, { $push: teams});
|
|
|
|
+ users.update({ _id: user._id }, { $push: orgs});
|
|
|
|
+ return;
|
|
},
|
|
},
|
|
|
|
+
|
|
changeUsername: function(user, name)
|
|
changeUsername: function(user, name)
|
|
{
|
|
{
|
|
username = {'username': name};
|
|
username = {'username': name};
|
|
@@ -81,7 +181,6 @@ addEmail: function(user, email)
|
|
{
|
|
{
|
|
user_email.unshift({'address': email, 'verified': true});
|
|
user_email.unshift({'address': email, 'verified': true});
|
|
user_email = {'emails': user_email};
|
|
user_email = {'emails': user_email};
|
|
- console.log(user_email);
|
|
|
|
users.update({ _id: user._id }, { $set: user_email});
|
|
users.update({ _id: user._id }, { $set: user_email});
|
|
}
|
|
}
|
|
}
|
|
}
|