Grails: Audit plugin: dateCreated has different value than stored in database - grails

I have used "org.grails.plugins:audit-logging:3.0.5" plugin. There's a table named User and I have to take its exact dateCreated value (automatically populated from plugin) and send it into SQS message. However different value in seconds is sent. Here's my code:
User user = new User()
user.status = "something"
def newUser = user.save(failOnError: true, flush: true)
msgBody.timeStamp = newUser.dateCreated
If there's 2020-09-14 20:44:58 dateCreated in database, 2020-09-14 20:44:57 is being sent in msgBody. Please help.
msgBody is an object sent from frontend(angularjs) to backend as JSON.

Related

Stripe checkout session seems to be adding a new customer even if they already exist

I have used the following code in .Net Core to create a Stripe checkout session, it seems to work fine for one customer buying one subscription.
I have a scenario though where a customer would be paying for subscriptions for other people, so may well use the checkout portal multiple times. When this happens Stripe will add the customer email address as a new customer each time, so rather than have one customer who can log in to the customer portal and see all subscriptions they have paid for, they can only log in to the 1st occurance of the customer with that email address.
Is there a way to use the checkout session so that if a customer email already exists it is not added again as a new customer?
var options = new SessionCreateOptions
{
SuccessUrl = successUrl+"&email=" + email,
CancelUrl = cancelUrl,
Mode = "subscription",
AllowPromotionCodes = true,
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = priceId,
Quantity = 1,
},
}
};
var service = new SessionService(this.client);
try
{
var session = await service.CreateAsync(options);
Response.Headers.Add("Location", session.Url);
return new StatusCodeResult(303);
}
Checkout does not automatically de-duplicate customers for you. How your customer records are managed is up to you.
If you want to have a Checkout session associated with an existing customer, you need to provide that customer id when you create the session.
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer

Searching LDAP from Jenkins scripted pipeline

we store a GitHub account in one of the AD User attribute. When receiving a Pull Request webhook from GitHub I want to find a user based on GitHub Account and notify user about tests results. How to do that?
if I understand you correctly you want to take email attribute value by another user attribute. can't test the following code but it should give you an idea how to do that.
import javax.naming.directory.InitialDirContext
import javax.naming.directory.DirContext
Properties ldapProps = [
'java.naming.factory.initial' :'com.sun.jndi.ldap.LdapCtxFactory',
'java.naming.security.authentication':'simple',
'java.naming.provider.url' :'ldap://ldap-host:389',
'java.naming.security.principal' :'ldap-access-username',
'java.naming.security.credentials' :'ldap-access-password',
] as Properties
String user = 'user-to-search'
String attr = 'mail' //attribute name for email could be different in your ldap
String ldapFilter = "CN=${user}" //put instead of `CN` git attribute
String[] attrValues = [] //array because could be several values for one attribute
DirContext ldapCtx = new InitialDirContext(ldapProps)
ldapCtx.search("", ldapFilter, null).each{ldapUser->
def ldapAttr = ldapUser.getAttributes().get(attr)
attrValues = ldapAttr?.getAll()?.collect{it.toString()}
}
ldapCtx.close()
println "found values: $attrValues"

Get Data from Odata service with Logged in User

I have one Odata service , which is providing me the data and I am able to display this data on table. We are going to deploy this application to Launchpad. Now we have this requirement in which logged in user must get the data according to his/her login ID. So If my user ID is XXXXX , I should get the records only for XXXXX. I am unable to understand the process flow. Shall we implement the logic in Odata itself or should I get all the data and filter the model on UI, before displaying it.
Regards,
MS
In oData itself you can access login user by sy-uname. using that user you can filter your data.
OR
In front end you can access login user by below code
var vUrl = "proxy/sap/bc/ui2/start_up";
var oxmlHttp = null;
oxmlHttp = new XMLHttpRequest();
oxmlHttp.onreadystatechange = function() {
if (oxmlHttp.readyState == 4 && oxmlHttp.status == 200) {
var oUserData = JSON.parse(oxmlHttp.responseText);
vUser = oUserData.id;
}
};
oxmlHttp.open( "GET", vUrl, false );
oxmlHttp.send(null);
You have to handle this in Odata only. Get User id from UI using
var storename = sap.ushell.Container.getService("UserInfo").getId();
and set it to Odata to filter and send back the results.
You should handle such requirements in the Service level (OData level), not in the UI.
In DPC_EXT class variable SY-UNAME gives you the logged in user. So you should filter your records by deriving more information from that.

Grails Audit Logging: Selective auditing and onChange method

We are using grails audit logging plugin for auditing few domain objects in our project
https://grails.org/plugin/audit-logging
Facing couple of issues related to it:
We have a user domain object which we want to audit.
We also create lot of users during our system set up. So, when we make auditable = true for User domain, it audits that as well - creates a new row in audit_log_event table for each user that gets created.
Is there a way to avoid this? We just want to audit when a user is created/updated by an admin user (basically when the admin user is logged in)
For some of the attributes of a domain object that we are auditing, we want to make some modification in the new value.
Example: Lets say email address of User object is getting updated from a#gmail.com to b#gmail.com, then we want to insert "***B#gmail.com-12:23:47" in new_value column of audit_log_event table.
I thought by updating the value of newMap[key] in onChange() method, we can do this, but that doesn't seem to work.
Is there a way to do this?
Tried this:
def onChange = {
oldMap,newMap ->
println "User was changed ..."
oldMap.each({ key, oldVal ->
if(oldVal != newMap[key]) {
println " * $key changed from $oldVal to " + newMap[key]
if(key == "email") {
newMap[key] = "*****Some value udpated****"
println "email is now again changed ..."
println " * $key changed from $oldVal to " + newMap[key]
}
}
})
}
Console output:
User was changed ...
* email changed from a#gmail.com to b#gmail.com
email is now again changed ...
* email changed from a#gmail.com to *****Some value udpated****
However, in DB:
old_value = a#gmail.com
new_value = b#gmail.com

Send an email when a new record is created via admin generator

I had used the symfony admin generator to create an web application for athletes management. One of the last client's requirement was to add a feature to notice the user and send an e-mail to the administrators when an athlete with the same number is inserted on the database. Until now, the column number of the Athlete table had a unique constraint but the client desires that the athlete can by inserted anyway.
To accomplish that, I was trying to extend the the edit / new actions in order to implement the client requirements.
Here is the code:
public function executeEdit(sfWebRequest $request)
{
$user = $this->getUser();
if(! $user->hasCredential('admin'))
{
$clube_id = $user->getAttribute('id');
$atleta_id = $request->getParameter('id');
$atleta = Doctrine::getTable('Atleta')->find($atleta_id);
if($clube_id != $atleta->clube_id)
$this->forward404();
}
if($request->get('post'))
{
// check if the inserted athlete BI already exists; if so, display a message to the user and send an email to the system admins
$atleta_id = $request->getParameter('id');
$atletaBIExiste = Doctrine::getTable('Atleta')->findDuplicateAthleteBI($atleta_id);
if($atletaBIExiste)
{
// display a notice message to the user
$this->getUser()->setFlash('error', 'Athlete already exists');
// send an email to the system administrator
}
}
return parent::executeEdit($request);
}
Here is my problem: when I execute the edit action, I only want to check for a duplicate athlete number when the HTTP is POST but it seems that never is. I had already sent some exceptions to the output to verify which type is HTTP Request and it seems it is always GET.
The problem you will be having is that when you hit save on the Edit page the information isn't posted to the edit action, it is posted to an action called update.
Have a look at the actions.class.php file in the cache and you will see it.

Resources