GraphServiceClient get group from name - azure-ad-graph-api

I am trying to find all members of a given group, and I only have the group name (and not the id). Is there anyway to get a group from name with the GraphServiceClient? Onlything I found requires id:
var users = await graphClient.Groups[group.Id].Members.Request().GetAsync();

You can the filter the groups using query parameter and search the Group by using DisplayName. For example - you can search the groups whose displayName starts with 'test' like below:
var result = await client.Groups.Request().Filter("startswith(displayName,'Test')").Select("displayName,description,id").GetAsync();

Related

How to show list in flutter whose id matches

I have two list of data stored in
1. final profiles = context.watch<ProfilesBloc>().state.profiles;
2. final users= context.watch<UsersBloc>().state.users;
I want to build the list with the only whose profile.id matches the user.id
I tried by if (user.id == profiles.id) but it's not working
any help?
var newUser = users.where((user) => user.id.toLowerCase().contains(profiles.id.toLowerCase()).toList();
you can basically use this method to check a condition to create a new list. Feel free to alter the codes as per your requirements.

Strapi - How to GET data sorted based on relation property?

I have an Articles table and it has a relation with the Authors table. Each author has a name property. I want to make a GET request for the articles and receive the articles sorted based on their author's name.
When I use _sort=author in the url parameters, I get the articles sorted based on the author object's ID.
When I use _sort=author.name in the url parameters, I get the articles in a seemingly random order but definitely not based on author.name.
How can I get the data sorted based on author.name?
I use mongoDB as my database.
That is the default behavior of _sort. However, you can simply accomplish this by overriding the find method in api/article/services/article.js to sort by Author's name like so:
module.exports = {
async find(params, populate) {
let result = await strapi.query('article').find(params, populate);
if (params._sort == 'author')
return result.sort((a, b) => (a.author.name > b.author.name) ? 1 : -1);
return result;
},
}
Check the documentation for customizing services to get more info: https://strapi.io/documentation/v3.x/concepts/services.html#concept

using email addresses as keys in firestore

I want to create "invitations" based on email addresses so that when a user with that email would arrive to the system his invitations would already be waiting for him.
so I wanted to create an invitations collection with key based on groupId + '_' + invited_user_email but if the user is test#test.com this the .com is interpreted as a subkey :(
I tried groupId + '_' + invited_user_email.replace(/[.]/g,'\\.') but it did not help either.
What am I missing? Is there no way to include a '.' in a firestore document's ID ?
EDIT:
per Doug Stevenson's request here is the code I use now:
var invitedUserEmailAsKey=invitedUserEmail.replace(/[.]/g,'\\.')
var batch = db.batch();
var groupRef = db.collection("groups").doc(groupId);
var invitationRef = db.collection("invitations").doc( groupRef.id + '_' + invitedUserEmailAsKey);
var groupUpdates = {};
groupUpdates['invited.' + invitedUserEmailAsKey + '.user_name'] = invitedUserName;
groupUpdates['merge'] = true;
batch.update(groupRef, groupUpdates);
The problems are with the updated document on the groups collection.
It ends up looking like this:
instead of having someone#gmail.com as a key
Using update() with "dot" in a key is interpreted as a nested field as documented here.
Notice that you're updating a document fields (groupRef) and not really doing anything with the "invitations" collection. I don't think that creating a new field on the group doc for every invitation is what you really mean to do.
As Dror mentioned, adding users with update() and a dot in the key won't work.
I use the set method with merge true:
addUserToGroup(id,email,type){
this.log("id",id,"email",email,"type",type);
let obj = {};
obj[email] = type;
this.angularFireStore.collection("Users").doc(id).set(obj, { merge: true }).then(() => {
this.log("addedUser",email);
}).catch((error) => {
this.log("failed to add user",error)
})
}
From the documentation: https://firebase.google.com/docs/firestore/manage-data/add-data#web-v8_1
"To create or overwrite a single document, use the set() method"
"If you're not sure whether the document exists, pass the option to merge the new data with any existing document to avoid overwriting entire documents."

sharepoint 2010 get value of choice field through api call

I have a sharepoint list ImageList, i have a column which stores its type
The column name is ImageType
the choices are "profile pic","thumbnail" etc
i want to fetch these choice values for this field
i tried accessing it using
http://myintranet:2010/sites/ImagesGallery/_vti_bin/listdata.svc/ImageList?$expand=ImageType
but it is not containing the choice values in it!
How can i get them?
The query:
http://myintranet:2010/sites/ImagesGallery/_vti_bin/listdata.svc/ImageList?$expand=ImageType
returns list items values for List resource only.
In order to retrieve field resource itself, the different endpoint have to be specified, in particular:
http://myintranet:2010/sites/ImagesGallery/_vti_bin/listdata.svc/ImageListImageType
It is assumed that list name is ImageList and field name is
ImageType
Example
$.getJSON(endpointUrl)
.done(function(data)
{
//print field choice options
data.d.results.forEach(function(item){
console.log(item.Value);
});
})
.fail(function(error){
console.log(JSON.stringify(error));
});

Is there a way to update a database field based on a list?

Using JPA, I have a list of entries from my database :
User(id, firstname, lastname, email)
That I get by doing:
List<User> users = User.find("lastname = ?", "smith");
And I'd like to update all in one request, by doing something like this :
"UPDATE USER SET email = null IN :list"
and then set the parameter "list" to users
Is it possible? if so, how?
Thanks for your help :)
Well, you could embed the query that you used to obtain list in the where clause of the update.
UPDATE User a SET a.email = null
WHERE user IN (SELECT b FROM User b WHERE lastName = :?)
By doing this you'd be doing the query to search the list and the update in single update query.
How do you like that? Do you think this could work?
-EDIT-
Since you want to use the original list of items instead of a list just retrieved from the database, you can still ensure you build the original list like this
UPDATE User a SET a.email = null
WHERE user IN (SELECT b FROM User b WHERE lastName IN(:originalList))
Then when you invoke it, you can do something like this:
Collection<String> originalList = Arrays.asList("Kenobi", "Skywalker", "Windu");
query.setParameter("originalList", originalList);
By this, you can still ensure the query will only contain items in your original list and not any possible new item from the database, provided that that last name is a candidate key in the database, otherwise I would recommend that you use the ID for the subquery instend of the last name.
if you have jpa+hibernate you can use entityManager.createQuery() for creating hql query
like that:
String hql = "UPDATE Supplier SET name = :newName WHERE name IN :name";
entityManager.createQuery(hql);