-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from mcarvin8/beta
feat: add covered lines, renumbering out-of-range lines numbers
- Loading branch information
Showing
9 changed files
with
593 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
import * as fs from 'node:fs'; | ||
|
||
export function getTotalLines(filePath: string): number { | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
return fileContent.split(/\r\n|\r|\n/).length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
global class PrepareMySandbox implements SandboxPostCopy { | ||
global PrepareMySandbox() { | ||
// Implementations of SandboxPostCopy must have a no-arg constructor. | ||
// This constructor is used during the sandbox copy process. | ||
} | ||
|
||
global void runApexClass(SandboxContext context) { | ||
System.debug('Org ID: ' + context.organizationId()); | ||
System.debug('Sandbox ID: ' + context.sandboxId()); | ||
System.debug('Sandbox Name: ' + context.sandboxName()); | ||
|
||
updateProfilesAndResetPasswordsForPublicGroupMembers(); | ||
// Additional logic to prepare the sandbox for use can be added here. | ||
} | ||
|
||
public void updateProfilesAndResetPasswordsForPublicGroupMembers() { | ||
String publicGroupId = '00G5a000003ji0R'; | ||
String newProfileId = '00e0b000001KWuY'; | ||
|
||
Group publicGroup = getPublicGroup(publicGroupId); | ||
|
||
if (publicGroup != null) { | ||
List<User> usersToUpdate = getUsersToUpdate(publicGroup, newProfileId); | ||
|
||
if (!usersToUpdate.isEmpty()) { | ||
update usersToUpdate; | ||
System.debug('Profile updated for ' + usersToUpdate.size() + ' users.'); | ||
|
||
// Reset passwords for updated users | ||
resetPasswords(usersToUpdate); | ||
} else { | ||
System.debug('No eligible active users found in the Public Group.'); | ||
} | ||
} else { | ||
System.debug('Public Group not found.'); | ||
} | ||
} | ||
|
||
private Group getPublicGroup(String groupId) { | ||
return [SELECT Id FROM Group WHERE Id = :groupId LIMIT 1]; | ||
} | ||
|
||
private List<User> getUsersToUpdate(Group publicGroup, String newProfileId) { | ||
List<User> usersToUpdate = new List<User>(); | ||
Set<Id> userIds = new Set<Id>(); | ||
|
||
// Get the current running User's Id | ||
Id currentUserId = UserInfo.getUserId(); | ||
|
||
for (GroupMember member : [SELECT UserOrGroupId FROM GroupMember WHERE GroupId = :publicGroup.Id]) { | ||
Id userOrGroupId = member.UserOrGroupId; | ||
if (userOrGroupId != null && userOrGroupId.getSObjectType() == User.SObjectType && userOrGroupId != currentUserId) { | ||
userIds.add(userOrGroupId); | ||
} | ||
} | ||
|
||
// Query and update active User profiles | ||
for (User user : [SELECT Id, ProfileId FROM User WHERE Id IN :userIds AND IsActive = true]) { | ||
user.ProfileId = newProfileId; | ||
usersToUpdate.add(user); | ||
} | ||
|
||
return usersToUpdate; | ||
} | ||
|
||
private void resetPasswords(List<User> users) { | ||
for (User u : users) { | ||
System.resetPassword(u.Id, true); // The second parameter generates a new password and sends an email | ||
} | ||
System.debug('Passwords reset for ' + users.size() + ' users.'); | ||
} | ||
} |
Oops, something went wrong.