Get a Google App Engine user by their user_id - google-app-engine

In GAE, can you look up a User with the User object's user_id?
In other words, is there something equivalent to:
from google.appengine.api.users import User
user = User.get_by_id(user_id)

I don't think so.
... they certainly wouldn't just give you access to every holder of a google account!
The idea is that you store user ids as properties in your datastore, once they've logged in to your app.
There is a property type called UserProperty
http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html
So, you can query your list of users from your own datastore definition.
hth

This seems to be the only post on the internet regarding this and since I was looking for a solution, I thought I'd post what I found here.
What amir75 said about using the UserProperty is fine for storing the User object itself returned by the google.appengine.users module.
But if you need to lookup a User by the user_id field instead of the default email field, usually something like user = User(email = 'validmail#gmailorgapps.com')
You can use this to query by user_id. user = User(_user_id = 'validuserid') The valid user_id is something that you got earlier from calling user.user_id()
I'm not sure what amir75 is referring to about having access to all google accounts since the User object returned will only have the email address and nickname, and that too only if the user authorizes the application to access that information.
My use case for this is I want people to sign up on the site, but they need an administrator to confirm them for using the site. The form used by the administrator for confirming the users can use email id as the field to identify the checkbox for confirming the user, but given that it might change, the user_id seems to be a safer field to use.

Related

How to write a complex reference to objects in email templates for Salesforce

I need to create a reference in an email template. for that I need to reffer a standard Contact objecect. For that I have a Custom Object Email Info, that has a lokup to standard Accounts.
So in the email I have to have value of the custom field Email_info__c from the custom object Email_info__c(the object and it's field have the same API names) while entering the Contact.
In the end both Contacts and my custom object have the lookups to Account, but not to each other, and there is no lookup from Acount, for now.
My first guess was to refer to the first child object Email info in the header of the VF template
relatedToType="Email_Info__c"
and then refer to it in the body as
{!RelatedTo.Account_r}
but then I would need a lookup from Accounts to Email Info to be able to refer deeper
{!RelatedTo.Account_r.Email_Info__r.Email_Info__c}
but, I don't think that it'll work that way or that it meets the needed criteria. Can someone share if there is an option at all to get the Email Info to Contacts through Accounts without creating a lookup on Accounts?
The task is to have a middle referred object, not a direct lookup:
It depends a bit how you are going to use this email template. What will the send be triggered from. Account? Contact? Email Info record? Will it be fired from a workflow or user will be instructed to navigate to account record and start composing the message?
If your relatedTo is really Email_Info__c then you don't have to do anything, you have all the data hidden in {!relatedTo.Id}, {!relatedTo.Name}, {!relatedTo.Email_Info__c} (you said the field name is same as object's name)
If your email starts from "Account" and you can guarantee accounts will have 1 email info record on related list - something like this might work:
<messaging:emailTemplate subject="hi stack" recipientType="Contact" relatedToType="Account">
<messaging:plainTextEmailBody >
{!relatedTo.Opportunities[0].Id} {!relatedTo.Opportunities[0].Name} {!relatedTo.Opportunities[0].StageName} {!relatedTo.Opportunities[0].CloseDate}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
from Account (relatedTo) I'm going down to the related list of Opportunities, I'm picking 1st one (at random... but if you have just 1 record it'll be fine) and display whatever I want.
If your relatedTo and recipient both have to be Contact it starts to get bit messier, normal visualforce syntax will not allow you to go "up" (from Contact to Account) and then "down" (from Account to related list of email infos)
You'd need to start with something like https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_with_apex.htm and then figure out how to pass the Id of account to it and run a query for email infos related to this account. https://salesforce.stackexchange.com/questions/245930/pass-id-from-visualforce-email-template-to-controller might be a good start, poke me if you're stuck.

Different views for different users in reactJS

I am having a problem in ReactJS. I want to create a text editor ( with ReactQuill). So, I want different accounts for each user, such that, if one person creates a note and edits it in his account, the other person should not see this.for example this is my current stage - https://wright-text.web.app. After you create your account and login you would see a note called first note because that's the note I created. What should I do so that when you login you see no notes because you have not created a note, but when I login, I should see the note I had already created. How would I do this ??
You need to add a scope to notes endpoint so that user could only GET notes, which they have created.
You need to add query parameters in the API you are fetching. For example, if you are fetching data via a GET request, add in some specific user id that you assign to your user upon validation and then fetch data of a particular user using that id as a query parameter on your API.

Salesforce Email logging on custom object

could really use some serious help on this. Below is the current business case:
We have the standard accounts, contacts, and opportunities objects. We've also created a custom object, and let's call it 'Customers.'
As of now, 'customers' are related to accounts.
Our users have einstein activity capture on, so all the email interactions get logged to the 'Account' level that the contact is related to, which makes sense.
The problem is that I want those emails tracked on the 'Customer' activity feed too, not just the 'Account' or 'Contact' activity feed.
Will creating a junction object between contacts and customers allow this activity to be shown in the 'customer' field? Or is there a simpler way to do this? Thank you in advance as this is a major roadblock I am facing right now.
I haven't worked with Einstein Activity Capture yet. What does it save stuff as? EmailMessage? Task? Either allows adding custom fields so you could add lookup to your Customer__c. With Task it's even simpler, it has that mutant lookup thing, Customer should appear as available option if it has "Allow Activities" ticked in setup.
Assuming that gives you something - next step would be to maybe make a custom quick action with some fields prepopulated, maybe a trigger to go "up" to Account and then to Customer(s)... Because out of the box
https://help.salesforce.com/articleView?id=aac_limitations.htm&type=5
Custom objects aren’t supported. When emails are sent from a custom
object, the email is logged on the activity timeline of the associated
contact.
You can upvote an idea: https://trailblazer.salesforce.com/ideaView?id=0873A000000EAIiQAO

Elegant way to store anonymous users with nick names in django?

I have a simple Post model in my django app:
class Post(models.Model):
category = models.CharField(max_length=10, choices=choices)
message = models.CharField(max_length=500)
user = models.ForeignKey(User, editable=False)
I'd like to implement the feature of having anonymous users create posts with nick names. Unfortunately django doesn't allow you to save an instance of AnonymousUser as a foreignkey to the Post class.
I was thinking of adding a "dummy" user record into the db that represents the anonymous user(id=0, or some negative number if possible) that would be used for all posts without a user. And if it is present a nullable name field would be used to represent the nickname of the anonymous user.
This solution seems a bit hacky to me. Is there any cleaner more effecient solution?
If you can identify new users by some session information, you could just create normal user accounts, pro forma so to speak - with a flag to identify them as volatile (this may lead to some regular maintenance cleanup).
If, during session lifetime, the user actually want to register, you can reuse the user account on your side and the user can keep all his data on his.
As #slacy commented and #Dominique answered; instead of rolling your own take a look at existing projects, e.g. this:
http://www.stereoplex.com/blog/introducing-django-lazysignup
Not tested , but this can help:
https://github.com/danfairs/django-lazysignup
You can add blank=True and null=True to User ForeignKey and set it to None, if user is anonymous. You just need to store the nickname somewhere.
I am new to Django. A friend told me not to use ForeignKey further stating that using CharField is ok. ForeignKey is slower than CharField, as it has some check for user info.

Active Directory get users in role

I get the members of a AD group, but instead of the user name, im getting the display name.
How can i get the user name?
Look for sAMAccountName in the properties you get back.
Well, i think this might be impossible, as the only users related property is the "members".
So as a workaround i used the DirectoryService with the "member" property value to fetch the user again from the AD and get it's sAMAaccoundName.
I'll be happy to hear about another solution to save the call to the AD for each user except the first call.
Thanks

Resources