Skip to content

Commit fe4dab1

Browse files
committed
Updated migration: migrate all users, ordered by last login descending. More error handling has been added
1 parent 199032b commit fe4dab1

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

packages/lib/auth0.cfc

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,25 @@ component {
209209
return result;
210210
}
211211

212-
public array function listMFA(required string email) {
212+
public any function listMFA(required string email) {
213213
var token = getAuthToken();
214-
var userId = getUserByEmail(email)[1].user_id;
215-
216-
var result = makeRequest(
217-
method = "GET",
218-
endpoint = "/api/v2/users/#userID#/authentication-methods",
219-
token = token
220-
);
221-
214+
var auth0user = getUserByEmail(email)
215+
var result = {};
216+
if (ArrayLen(auth0user) > 0) {
217+
var userId = auth0user[1].user_id;
218+
try {
219+
result = makeRequest(
220+
method = "GET",
221+
endpoint = "/api/v2/users/#userID#/authentication-methods",
222+
token = token
223+
);
224+
} catch (any e) {
225+
226+
}
227+
}else {
228+
// If the user does not exist in Auth0
229+
return { "error": true, "message": "noUser" };
230+
}
222231
return result;
223232
}
224233

@@ -435,7 +444,7 @@ component {
435444
);
436445
successCount++;
437446
} catch (any e) {
438-
arrayAppend(errors, e.message);
447+
application.fc.lib.error.logData(application.fc.lib.error.normalizeError(e));
439448
}
440449
}
441450
} else {
@@ -775,8 +784,9 @@ component {
775784
INNER JOIN dmProfile p ON concat(u.userID, '_CLIENTUD')=p.username
776785
INNER JOIN farUser_aGroups ug ON u.objectid=ug.parentid AND ug.data=:groupID
777786
WHERE u.userstatus IN ('active','pending') AND
778-
p.lastLogin >= DATE_SUB(NOW(), INTERVAL 12 MONTH)
779-
ORDER BY u.objectid ASC
787+
p.emailAddress IS NOT NULL AND
788+
p.emailAddress <> ''
789+
ORDER BY p.lastLogin DESC
780790
", { groupID=arguments.oldGroupID }, { datasource=application.dsn_read, maxRows=arguments.maxRows });
781791
}
782792
else {
@@ -785,8 +795,11 @@ component {
785795
FROM farUser u
786796
INNER JOIN dmProfile p ON concat(u.userID, '_CLIENTUD')=p.username
787797
WHERE u.userstatus IN ('active','pending') AND
788-
p.lastLogin >= DATE_SUB(NOW(), INTERVAL 12 MONTH)
789-
ORDER BY u.objectid ASC
798+
(u.lGroups IS NULL OR u.lGroups = '') AND
799+
u.userID <> 'root' AND
800+
p.emailAddress IS NOT NULL AND
801+
p.emailAddress <> ''
802+
ORDER BY p.lastLogin DESC
790803
", { }, { datasource=application.dsn_read, maxRows=arguments.maxRows });
791804
}
792805
}
@@ -893,15 +906,23 @@ component {
893906
public void function runMigration(required string oldGroupName, required query qUsers, boolean sendCompletion) {
894907
var safeBatchSize = 300;
895908
if (qUsers.recordCount <= 20) {
909+
try {
896910
processBatch(arguments.qUsers, arguments.oldGroupName, arguments.sendCompletion);
911+
} catch (any e) {
912+
application.fc.lib.error.logData(application.fc.lib.error.normalizeError(e));
913+
}
897914
} else {
898915
var totalRows = qUsers.recordCount;
899916
var currentIndex = 1;
900917

901918
while (currentIndex <= totalRows) {
919+
try {
902920
var endIndex = min(currentIndex + safeBatchSize - 1, totalRows);
903921
var batchQuery = createBatchQuery(qUsers, currentIndex, endIndex);
904922
processBatch(batchQuery, arguments.oldGroupName, arguments.sendCompletion);
923+
} catch (any e) {
924+
application.fc.lib.error.logData(application.fc.lib.error.normalizeError(e));
925+
}
905926
currentIndex += safeBatchSize;
906927
}
907928
}

webskin/a0Login/webtopBodyStatus.cfm

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@
149149
</table>
150150
</cfoutput>
151151

152+
<cfoutput>
153+
<h2>Delete all users from auth0</h2>
154+
<!--- <button type="submit" class="btn">Delete Users</button><br> --->
155+
</cfoutput>
156+
<ft:processForm action="Delete Users">
157+
<cfset aDeleteAuth0Users=application.fc.lib.auth0.deleteAuth0Users() />
158+
<cfdump var="#aDeleteAuth0Users#">
159+
</ft:processForm>
160+
<ft:form>
161+
<ft:buttonPanel>
162+
<ft:button value="Delete Users" />
163+
</ft:buttonPanel>
164+
</ft:form>
165+
166+
152167
<cfset aGroups = application.security.userdirectories.clientud.getAllGroups() />
153168
<cfparam name="url.migratable_group" default="">
154169
<cfoutput>
@@ -164,7 +179,7 @@
164179
<cfif len(url.migratable_group)>
165180
<button type="submit" class="btn" name="migrate" value="one">Migrate one user</button>
166181
<button type="submit" class="btn" name="migrate" value="ten">Migrate ten users</button>
167-
<button type="submit" class="btn" name="migrate" value="all">Migrate users logged in the last 12 months</button>
182+
<button type="submit" class="btn" name="migrate" value="all">Migrate all users</button>
168183
</cfif>
169184
</form>
170185
</cfoutput>

0 commit comments

Comments
 (0)