Migrate wekan-oidc to async API for Meteor 3.0

This commit is contained in:
Harry Adel 2026-01-29 20:16:12 +02:00
parent eb0c9ac1e6
commit 0fcdf47545
3 changed files with 25 additions and 24 deletions

View file

@ -57,7 +57,7 @@ module.exports = {
// isAdmin: [true, false] -> admin group becomes admin in wekan // isAdmin: [true, false] -> admin group becomes admin in wekan
// isOrganization: [true, false] -> creates org and adds to user // isOrganization: [true, false] -> creates org and adds to user
// displayName: "string" // displayName: "string"
addGroupsWithAttributes: function (user, groups){ addGroupsWithAttributes: async function (user, groups){
teamArray=[]; teamArray=[];
orgArray=[]; orgArray=[];
isAdmin = []; isAdmin = [];
@ -76,7 +76,7 @@ addGroupsWithAttributes: function (user, groups){
isAdmin.push(group.isAdmin || false); isAdmin.push(group.isAdmin || false);
if (isOrg) if (isOrg)
{ {
org = Org.findOne({"orgDisplayName": group.displayName}); org = await Org.findOneAsync({"orgDisplayName": group.displayName});
if(org) if(org)
{ {
if(contains(orgs, org, "org")) if(contains(orgs, org, "org"))
@ -89,7 +89,7 @@ addGroupsWithAttributes: function (user, groups){
else if(forceCreate) else if(forceCreate)
{ {
createObject(initAttributes, "Org"); createObject(initAttributes, "Org");
org = Org.findOne({'orgDisplayName': group.displayName}); org = await Org.findOneAsync({'orgDisplayName': group.displayName});
} }
else else
{ {
@ -102,7 +102,7 @@ addGroupsWithAttributes: function (user, groups){
else else
{ {
//start team routine //start team routine
team = Team.findOne({"teamDisplayName": group.displayName}); team = await Team.findOneAsync({"teamDisplayName": group.displayName});
if (team) if (team)
{ {
if(contains(teams, team, "team")) if(contains(teams, team, "team"))
@ -115,7 +115,7 @@ addGroupsWithAttributes: function (user, groups){
else if(forceCreate) else if(forceCreate)
{ {
createObject(initAttributes, "Team"); createObject(initAttributes, "Team");
team = Team.findOne({'teamDisplayName': group.displayName}); team = await Team.findOneAsync({'teamDisplayName': group.displayName});
} }
else else
{ {
@ -129,28 +129,28 @@ addGroupsWithAttributes: function (user, groups){
// hence user will get admin privileges in wekan // hence user will get admin privileges in wekan
// E.g. Admin rights will be withdrawn if no group in oidc provider has isAdmin set to true // E.g. Admin rights will be withdrawn if no group in oidc provider has isAdmin set to true
users.update({ _id: user._id }, { $set: {isAdmin: isAdmin.some(i => (i === true))}}); await users.updateAsync({ _id: user._id }, { $set: {isAdmin: isAdmin.some(i => (i === true))}});
teams = {'teams': {'$each': teamArray}}; teams = {'teams': {'$each': teamArray}};
orgs = {'orgs': {'$each': orgArray}}; orgs = {'orgs': {'$each': orgArray}};
users.update({ _id: user._id }, { $push: teams}); await users.updateAsync({ _id: user._id }, { $push: teams});
users.update({ _id: user._id }, { $push: orgs}); await users.updateAsync({ _id: user._id }, { $push: orgs});
// remove temporary oidc data from user collection // remove temporary oidc data from user collection
users.update({ _id: user._id }, { $unset: {"services.oidc.groups": []}}); await users.updateAsync({ _id: user._id }, { $unset: {"services.oidc.groups": []}});
return; return;
}, },
changeUsername: function(user, name) changeUsername: async function(user, name)
{ {
username = {'username': name}; username = {'username': name};
if (user.username != username) users.update({ _id: user._id }, { $set: username}); if (user.username != username) await users.updateAsync({ _id: user._id }, { $set: username});
}, },
changeFullname: function(user, name) changeFullname: async function(user, name)
{ {
username = {'profile.fullname': name}; username = {'profile.fullname': name};
if (user.username != username) users.update({ _id: user._id }, { $set: username}); if (user.username != username) await users.updateAsync({ _id: user._id }, { $set: username});
}, },
addEmail: function(user, email) addEmail: async function(user, email)
{ {
user_email = user.emails || []; user_email = user.emails || [];
var contained = false; var contained = false;
@ -173,7 +173,7 @@ 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};
users.update({ _id: user._id }, { $set: user_email}); await users.updateAsync({ _id: user._id }, { $set: user_email});
} }
} }
} }

View file

@ -295,24 +295,24 @@ var getTokenContent = function (token) {
return content; return content;
} }
Meteor.methods({ Meteor.methods({
'groupRoutineOnLogin': function(info, userId) 'groupRoutineOnLogin': async function(info, userId)
{ {
check(info, Object); check(info, Object);
check(userId, String); check(userId, String);
var propagateOidcData = process.env.PROPAGATE_OIDC_DATA || false; var propagateOidcData = process.env.PROPAGATE_OIDC_DATA || false;
if (propagateOidcData) { if (propagateOidcData) {
users= Meteor.users; users= Meteor.users;
user = users.findOne({'services.oidc.id': userId}); user = await users.findOneAsync({'services.oidc.id': userId});
if(user) { if(user) {
//updates/creates Groups and user admin privileges accordingly if not undefined //updates/creates Groups and user admin privileges accordingly if not undefined
if (info.groups) { if (info.groups) {
addGroupsWithAttributes(user, info.groups); await addGroupsWithAttributes(user, info.groups);
} }
if(info.email) addEmail(user, info.email); if(info.email) await addEmail(user, info.email);
if(info.fullname) changeFullname(user, info.fullname); if(info.fullname) await changeFullname(user, info.fullname);
if(info.username) changeUsername(user, info.username); if(info.username) await changeUsername(user, info.username);
} }
} }
} }
@ -328,8 +328,9 @@ Meteor.methods({
const defaultBoardId = defaultBoardParams.shift() const defaultBoardId = defaultBoardParams.shift()
if (!defaultBoardId) return if (!defaultBoardId) return
const board = Boards.findOne(defaultBoardId) const board = await Boards.findOneAsync(defaultBoardId)
const userId = Users.findOne({ 'services.oidc.id': oidcUserId })?._id const user = await Users.findOneAsync({ 'services.oidc.id': oidcUserId })
const userId = user?._id
const memberIndex = _.pluck(board?.members, 'userId').indexOf(userId); const memberIndex = _.pluck(board?.members, 'userId').indexOf(userId);
if(!board || !userId || memberIndex > -1) return if(!board || !userId || memberIndex > -1) return

View file

@ -1,6 +1,6 @@
Package.describe({ Package.describe({
summary: "OpenID Connect (OIDC) flow for Meteor", summary: "OpenID Connect (OIDC) flow for Meteor",
version: "1.0.12", version: "1.1.0",
name: "wekan-oidc", name: "wekan-oidc",
git: "https://github.com/wekan/wekan-oidc.git", git: "https://github.com/wekan/wekan-oidc.git",
}); });