Modifying the Employee Information field in Suite Admin SDK Python - python

Is there a way to modify these fields through the Admin SDK without manually doing it through the admin console? Specifically under the employee information, the job title, type of employee, manager's email and department.
I've looked at https://developers.google.com/admin-sdk/directory/reference/rest/v1/users and https://googleapis.github.io/google-api-python-client/docs/dyn/admin_directory_v1.users.html#insert but I don't see any parameter that you can specify these fields in.
Any help would be appreciated, thank you!

The fields are kind of scattered around but we can figure it out by filling them manually on a test user and running a users.get on them.
So for an employee that looks like this:
The API result is the following (after removing the irrelevant fields):
{
"externalIds": [
{
"value": "ID-123",
"type": "organization"
}
],
"relations": [
{
"value": "example#domain.com",
"type": "manager"
}
],
"organizations": [
{
"title": "My Job Title",
"primary": true,
"customType": "",
"department": "My Department",
"description": "My Employee Type",
"costCenter": "My Cost Center"
}
],
"locations": [
{
"buildingId": "My Building ID",
"floorName": "My Floor Name",
"floorSection": "My Floor Section"
}
]
}
So from this we can deduce that Job Title corresponds to organizations.title, Type of employee corresponds to organizations.description, Manager's email corresponds to relations.value that also has a relations.type = manager and Department corresponds to organizations.department.
Do note that as explained in the documentation that you were looking at, these fields can hold multiple values, so the user can have multiple organizations, but the one that shows in the Admin console is the one marked as primary, they can have multiple relations other than manager such as assistant, spouse, etc. They can have multiple locations and so on.
Generally what will be displayed in the Admin console are the primary fields. Any secondary values may not show up but you can still retrieve them via the API. Most likely they're meant for custom applications that can take advantage of reading these multiple fields, while the console only shows the most relevant fields (as decided by Google).

Related

Tweepy get_bookmarks() - User Fields Not Working Despite Proper Arguments

I am using the tweepy library to retrieve user bookmarks, but I am unable to retrieve the profile picture URL despite passing the correct user_field.
According to the tweepy documentation, the only available expansion for this endpoint is "expansions=owner_id". I am not sure what this means or how to retrieve the profile picture URL.
Can someone help me understand this and provide a solution?
bookmarks = client.get_bookmarks(expansions=["author_id"],
user_fields=["profile_image_url"])
The response object is as follows:
{
"data": [
{
"id": 1621356248334483456,
"text": "The majesty of nature is on full display at Yosemite National Park. Visit now to experience it for yourself: https://natureloversparadise.com"
},
{
"id": 1620813010569945091,
"text": "Discover the beauty of the Great Barrier Reef with a snorkeling adventure. Book now at https://greatbarrierreefadventures.com"
}
],
"includes": {
"users": [
{
"id": 123456789,
"username": "naturelover",
"name": "Nature Enthusiast"
},
{
"id": 987654321,
"username": "oceanadventurer",
"name": "Ocean Adventurer"
}
]
}
}
As you can see, the includes section only contains basic information about the authors of the tweets (id , username , and name ), and no information about profile pictures.
Thank you for your help.
I have successfully made the necessary scope access and authentication. However, I think the get_bookmark() method might only return basic author information like author_id user fields and need confirmation before using user_id to call user information from different method.

What is best way to deserialize JSON into multiple models in django rest framework

I am quite new to django rest framework and I would like to discuss what is the best way to implement an API endpoints I am aiming to have.
I have following JSON example:
[
{
'top_lvl_key1': {
id: 1
'some_key1': "value"
'some_key2' : "value"
}
},
{
'top_lvl_key2': {
id: 1
'some_key1': "value"
'some_key2' : "value"
}
},
{
'top_lvl_key1': {
id: 2
'some_key1': "value"
'some_key3' : "value"
}
},
{
'top_lvl_key3': {
id: 1
'some_key1': "value"
'some_key2' : "value"
}
}
]
and I want to have 3 endpoints
[POST] /insert inserting and parsing the entire JSON to store it into models
[GET] /detail/<top_lvl_key>/ Display all record for specfici top_lvl_key
[GET] /detail//<top_lvl_key>/id/ Display a record for specific top_lvl_key and specific id (only 1 record)
As you can see, I need to store each type of top_lvl_key to different model so I can retrieve for GET requests. However I am not sure how should I got about serializing the JSON, since the dictionaries of the top_lvl_keys can differ. For example top_lvl_key_1 can sometimes have some_key_1 and some_key_2, but sometimes some_key_1 and some_key_2. So far I have been implementing the models with blank=True, null=True, but I am not sure this is best solution as there a lot of attributes which can be NULL now. Is there a better way to go about this?
Thanks a lot in advance

Dynamic forms for end users in django

I'm creating a django project where any user can create forms with any number of fields. For example user A could create the follow form:
Name of field: Field_1 - Type: Text
Name of field: Field_2 - Type: Date
Name of field: Field_3 - Type: File
And user B could create:
Name of field: name - Type: Text
Name of field: phone - Type: Text
Look that the user need to say to the program the name of the field and type. Since is a dynamic way to create any number of forms and any number of field for each forms. What would be the most efficient way to create the database model?
Take into account that the program does not know the name of the field until the user send it. So in the views, I can't process it with exact name of fields.
If you create two tables in your database you can handle this pretty easily. Have one table that stores the serialized form as JSON, and another table that holds the form data (and links to the form definition).
How you serialize it is up to you but it would look something like this:
Serialized form
{
"fields": [
{
"name": "field_name"
"type": "text"
"attrs": []
}
]
}
Serialized data (ForeignKey's to above form)
{
"data": {
"field_name": "value"
}
}
The advantage to doing this is you aren't creating models on the fly, and your database stays a lot cleaner because you won't have tons of tables lying around.

Setting posting and receving attributes when adding member to a group

After adding a member to a group:
groupMember = {
"email": sender,
"role": "MEMBER",
}
directory_service.members().insert(groupKey=groupName,body=groupMember).execute()
I would like to set the following attributes for that same member:
- Email delivery (we want to set it to no mail)
- Posting permission (we want to set it to "Override: member is allowed to post")
I can't find python (or other languages) API for setting group member attributes other than these member resource attributes:
{
"kind": "admin#directory#member",
"etag": etag,
"id": string,
"email": string,
"role": string,
"type": string
}
Is there an API (python or other languages) to set "Email delivery" and "Posting permission" attributes for a specific group member?
Thank you for your help!
There is no API to set group member email preferences.

Django REST framework inconsistent data

When I request my user data from localhost:8000/users, I get users that look like this:
{
"username": "iv4ha05k",
"email": "xxxx#xxx.com",
"profile": {
"image": "http://localhost:8000/media/images-4.jpg"
},
"pk": 303
},
But, if I request user data from the django manage shell, the data will look like this:
{
"username": "iv4ha05k",
"email": "xxxx#xxx.com",
"profile": {
"image": "/media/images-4.jpg"
},
"pk": 303
},
Notice how the image url becomes truncated. I am querying the same exact database in the same exact state, and it has nothing to do with migrations or anything of the like. I discovered this issue when trying to write custom API views. When I would query the User viewset, it would return data with the full image address. But, when I try to write a custom API view that queries the user database, it will return it with the truncated address. I am using django's FileSystemStorage, if that helps anyone.. Thanks.

Categories