I want to add members to Google group using AdminDirectory.Members.insert.
This is my code:
function addGroupMember() {
var member = {
name: {
givenName: 'Jhon',
familyName: 'Doe'
},
email: 'mail#example.com',
role: 'MEMBER'
};
var newMember=AdminDirectory.Members.insert(member, 'group_email#example.com');
}
The members is created into Group Members of Google Workspace, but without name, as you can see below:
There is one way to change Member by John Doe?
NOTE: The email domain is external, is not the same of the organization.
You may want to take a deeper look at the documentation.
From the Member overview:
A Google Groups member can be a user or another group.
Also you can see that the Member resource has no attribute name so it's indeed impossible to assign it a name before creating the User resource.
What you can do right now is creating an User through the users.insert request. After that store the id of said user and insert it into a group with members.insert.
And of course if you have already created a bunch of users without specifying the names you can update them.
Related
I am calling google admin directory api to get user through email and then storing the organizations return in org.
var user = AdminDirectory.Users.get(bmail);
org = user.organizations;
Output
[ { customType: '',
title: 'PM',
department: 'BIT',
primary: true,
description: 'Permanent' } ]
How can i get only department in org? I've tried to use get.child(element) to get the department however not successful.
How can i get only manager's email? I've read the Rest Resource Users but there is no information related to manager's email.
Any reference or help will be much appreciated.
Thank you
You already have the User object, so if you want to read the department property you only have to navigate its tree. See the example below:
function myFunction() {
var user = AdminDirectory.Users.get(bmail);
org = user['organizations'][0]['department'];
}
Now to answer your second question you could use the relations field to keep track of the user's managers. Feel free to drop a comment if you need further clarifications.
Using Prisma 3.7.0.
I'm following this example in the docs
model Person {
id Int #id #default(autoincrement())
name String?
followers Follows[] #relation("follower")
following Follows[] #relation("following")
}
model Follows {
follower Person #relation("follower", fields: [followerId], references: [id])
followerId Int
following Person #relation("following", fields: [followingId], references: [id])
followingId Int
##id([followerId, followingId])
}
Then I try creating a User along with the people they're following, with the below code.
const person = await prisma.person.create({
data: {
following: {
create: [
{ following: { connect: { id: 1 } } }
]
}
}
});
I'm getting the following (see what I did there :)) error.
/usr/src/app/node_modules/#prisma/client/runtime/index.js:34755
const error2 = new PrismaClientValidationError(renderErrorStr(validationCallsite));
^
PrismaClientValidationError: Unknown arg `following` in data.following.create.0.following for type FollowsCreateWithoutFollowingInput. Did you mean `follower`?
Argument follower for data.following.create.0.follower is missing.
at Object.validate (/usr/src/app/node_modules/#prisma/client/runtime/index.js:34755:20)
at PrismaClient._executeRequest (/usr/src/app/node_modules/#prisma/client/runtime/index.js:39749:17)
at consumer (/usr/src/app/node_modules/#prisma/client/runtime/index.js:39690:23)
at /usr/src/app/node_modules/#prisma/client/runtime/index.js:39694:49
at AsyncResource.runInAsyncScope (node:async_hooks:199:9)
at PrismaClient._request (/usr/src/app/node_modules/#prisma/client/runtime/index.js:39694:27)
at request (/usr/src/app/node_modules/#prisma/client/runtime/index.js:39799:77)
at _callback (/usr/src/app/node_modules/#prisma/client/runtime/index.js:40007:14)
at PrismaPromise.then (/usr/src/app/node_modules/#prisma/client/runtime/index.js:40014:23) {
clientVersion: '3.7.0'
}
I believe the reason I'm getting this error is because the following[] relation creates an input as mentioned in the error message FollowsCreateWithoutFollowingInput, meaning it's expecting a follower relation and not a following, as the following will be the Person I'm currently creating, and I just need to tell it who is the follower Person.
However this doesn't make sense to me. When I'm creating a Person along with its people they're following, I understand that to be an array of Persons who the person I'm currently creating is following. If so, then a Follows record in the following array contains the current Person (the one I'm creating) as the follower relation and some other Person as the following relation. And the relation I should be inputting is the following and not the follower. Therefore the input type that prisma should generate should be FollowsCreateWithoutFollowerInput instead of FollowsCreateWithoutFollowingInput.
What am I missing, in my understanding?
I looked at the below resources during my research on this.
count self relation on Prisma error: table name specified more than once. This is discussing a different issue, using the same example.
https://github.com/prisma/prisma/discussions/3960. This discusses how to create the same type of relation, where the join table references the same table for both ids. But it doesn't explain how to create records once the relationships are defined.
One-to-many self-relation in prisma schema. This shows how to create a record, but its not using the join tables relation during create it's using a property. Also it's not exactly the same case as the join table seems to be the same table.
`const person = await prisma.person.create({
data: {
following: {
connect: { id: 1 }
}
}
});
It's the "create" in the body of the function that's doing it. The second nested following would also cause a problem if you just fix that though.
Think of it like you aren't creating the follower. The follower already needs to be there. You are just creating a record of the connection between the person and the follower. So prisma.person.create some data that this person has a follower and that follower is connected to the user with id whatever.
Is there a way to get user details (profile attributes etc) if I have IdentityPool or UserPool ID (sub) of a user with AWS SDK?
The use case is that I'm saving some information submitted by a user in a DB with a key equal to user ID (sub). So, when I'm reading it from the DB, I want to restore back some user info from my pool for my app UI.
I found a similar question (Getting cognito user pool username from cognito identity pool identityId), but it seems, the answer given is focused around serverless deployment, and still has some gaps.
Thanks in advance
Since you have the user's sub, you can use AdminGetUser. It returns the UserAttributes in the pool.
I think I found a solution, it was on the surface actually.
Having user pool id one can use ListUsers call with filter sub = \"${userId}\". The client to be used is CognitoIdentityProviderClient, if JS is used.
const client = new CognitoIdentityProviderClient({
region: REGION,
credentials: fromCognitoIdentityPool({
client: new CognitoIdentityClient({ region: REGION }),
logins: {
[PROVIDER_ID]: token
},
identityPoolId: ID_POOL_ID
})
});
const filter = `sub = \"${userPoolId}\"`;
const resp = await client.send(new ListUsersCommand({
UserPoolId: USER_POOL_ID,
Filter: filter,
Limit: 1
}));
Of course AdminGetUser can be used as well, as Ulas Keles mentioned above, if it's applicable
I'm working with two tables in particular. Users and Friends. Users has a bunch of information that defines the User whereas Friends has two columns aside from id: user_id and friend_id where both of them are a reference to the User table.
I'm trying to find all of the users friends in as little calls to the db as possible and I currently have 2. One to retrieve the id of a user first from a request, then another to Friends where I compare the IDs from the first call and then a third call that passes the array of friends and find all of them in the Users table. This already feels like overkill and I think that with associations, there has to be a better way.
Modification of the tables unfortunately is not an option.
One thing that I saw from "http://docs.sequelizejs.com/manual/querying.html#relations---associations"
I tried but got an interesting error.. when trying to repurpose the code snippet in the link under Relations/Associations, I get "user is associated to friends multiple times. To identify the correct association, you must use the 'as' keyword to specify the alias of the association you want to include."
const userRecord = await User.findOne({
where: { id }
})
const friendsIDs = await Friends.findAll({
attributes: ["friend_id"],
where: {
user_id: userRecord.id
}
}).then(results => results.map(result => result.friend_id));
const Sequelize = require("sequelize");
const Op = Sequelize.Op;
return await User.findAll({
where: {
id: { [Op.in]: friendsIDs }
},
});
Above for my use case works. I'm just wondering if there are ways to cut down the number of calls to the db.
Turns out Sequelize handles this for you if you have the proper associations in place so yes, it was a one liner user.getFriends() for me.
I need row-level permissions in sails. I already looked at this and at other threads, but everybody says to just use policies.
But what I need isn't just limiting the ability to do e.g. find/update all elements of a table but to have permissions per database row that consider associations for permissions.
It would be great if the permissions support blueprints like the ember data adapter, nested create/update/find (with populate) and sockets.
So for example:
GET /:model/:id
should return and populate with such entries where certain associated conditions are met.
So for example, we have 4 models:
User (columns: id, name, email, pwd_hash, ...)
Project (columns: id, client, name, ...)
UserAssignment (columns: id, user, project, user_perms, ...)
Client (columns: id, name, ...)
User and Project are linked through UserAssignment - an advanced MM-Table. (Users may have special user_perms to different projects, such as read,write,manage). And a Project always has one Client.
Here's the corresponding sails models:
// User.js
attributes: {
name: 'string'
}
// Project.js
attributes: {
name: 'string',
client: {
model: 'client'
},
userAssignments: {
collection: 'userAssignment',
via: 'project'
}
}
// UserAssignment.js
attributes: {
userPerms: 'integer',
user: {
model:'user'
},
project: {
model:'project'
}
}
// Client.js
attributes: {
name: 'string',
projects: {
collection: 'project',
via: 'client'
}
}
So lets say the User with the ID=1 wants to access a list of Clients he is allowed to see, he calls
GET /clients/
Speaking in SQL:
SELECT client.*
FROM client
INNER JOIN project ON project.client = client.id
INNER JOIN user_assignment ON project.id = user_assignment.project
WHERE user_assignment.user = 1 and user_perms > 4
GROUP BY client.id;
And then also if we have certain Project managers, they can update associated UserAssignments etc.
Basically I thought the permissions could be based on role associations.
I tried several ways to implement this functionality. I tried _permission_read, _permission_write columns for all rows and other stuff like using populates for this but nothing seems to work right.
The above example is just a excerpt of many different kinds of models which I can filter based on SQL couldn't do nicely with Sails/Waterline.
Do I need custom SQL queries for this?
Is it possible to do this neatly with Sails?
Do I misunderstand policies and is there a way to implement such requirements with them?
Or shall I use SQL views instead of tables?
Thanks in advance!