Skip to content

Commit

Permalink
Minlopro: Playing w bash scripts & public Salesforce REST webservice
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomeandrey committed Dec 29, 2024
1 parent c995ebe commit 73252f7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/minlopro-core/main/classes/SystemInfoController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,21 @@ public without sharing class SystemInfoController {
throw new AuraHandledException(ex.getMessage());
}
}

public static List<User> getAdmins() {
Id adminsGroupId = getAdminsGroup()?.Id;
return [
SELECT Id, Name, Email, Username, Alias
FROM User
WHERE Id IN (SELECT UserOrGroupId FROM GroupMember WHERE GroupId = :adminsGroupId)
];
}

public static Set<Id> getAdminIds() {
return new Map<Id, User>(getAdmins()).keySet();
}

public static Group getAdminsGroup() {
return [SELECT Id, Name, DeveloperName FROM Group WHERE DeveloperName = 'OrgAdmins' LIMIT 1];
}
}
27 changes: 15 additions & 12 deletions src/minlopro/main/classes/rest-endpoints/PublicRestEndpoint.cls
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,22 @@ global without sharing class PublicRestEndpoint {
Logger.debug('Request Body = {0}', Lists.of(req.requestBody.toString()));
Logger.debug('Request Params = {0}', Lists.of(req.params.toString()));

// Verify request by key;
String verificationKey = req.params.get('verificationKey');
Logger.debug('Verifications Key = {0}', Lists.of(verificationKey));
if (String.isBlank(verificationKey) || !verificationKey.equals('wow_ooha')) {
res.statusCode = 401;
res.responseBody = Blob.valueOf('Verification Key is not confirmed!');
return;
CustomNotificationType notificationType = [
SELECT Id, DeveloperName
FROM CustomNotificationType
WHERE DeveloperName = 'Minlopro'
LIMIT 1
];
Messaging.CustomNotification notification = new Messaging.CustomNotification();
notification.setNotificationTypeId(notificationType.Id);
notification.setTitle('New Host Detected');
notification.setBody('Body = ' + req.requestBody.toString());
notification.setTargetId(UserInfo.getUserId());
Set<String> usernames = new Set<String>();
for (Id userId : SystemInfoController.getAdminIds()) {
usernames.add(String.valueOf(userId));
}

// Redirect to the new URL;
res.addHeader('Location', 'https://www.google.com');
res.addHeader('http-equiv', 'refresh');
res.statusCode = 301;
notification.send(usernames);
} catch (Exception ex) {
Logger.error(ex);
res.statusCode = 500;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomNotificationType xmlns="http://soap.sforce.com/2006/04/metadata">
<customNotifTypeName>Minlopro Notification</customNotifTypeName>
<desktop>true</desktop>
<masterLabel>Minlopro Notification</masterLabel>
<mobile>true</mobile>
<slack>false</slack>
</CustomNotificationType>

0 comments on commit 73252f7

Please sign in to comment.