Unable to Check Permission of a SharePoint Group - sharepoint

I tried to use examples from the net to check if a group has a specific permission in my SP site.
Below is my code snippet:
if (roleAssignment.Member is SPGroup)
{
//displays as 1
Console.WriteLine(roleAssignment.RoleDefinitionBindings.Count)
if (roleAssignment.RoleDefinitionBindings.Contains(SPContext.Current.Web.RoleDefinitions["Full Control"]))
{
//code not reached
}
}
I met the following error:
System.NullReferenceException: Object reference not set to an instance of an object.
My roleAssignment object exists, and passes the spgroup check.
May I know how can I troubleshoot this error?
Thank you.

You could try this to check if the roleassignment is a group:
if (roleAssignment.Member.PrincipalType == Microsoft.SharePoint.Client.Utilities.PrincipalType.SharePointGroup)

Related

Azure conditional access object ID translation

Trying to create a simple conditional access policy report,
$Policies = Get-AzureADMSConditionalAccessPolicy
$Policies[1].Conditions.Users.IncludeGroups
These group object ID's can be resolved using:
Get-AzureADObjectByObjectId -ObjectIds xxxx-xxxxx
But how to resolve, for example, locations?
$Policies[1].Conditions.Locations.ExcludeLocations
Could not find the location ID's using Get-AzureADObjectByObjectId.
Any ideas appreciated ...
For the location id's you need to query the namedLocations API rather than the directory itself. For this, use Get-AzureADMSNamedLocationPolicy:
$Policies[1].Conditions.Locations.ExcludeLocations |ForEach-Object {
Get-AzureADMSNamedLocationPolicy -PolicyId $_
}

Discord.js - Command to Remove All Users Containing Role

I know that you can remove certain roles from users, and remove all roles from a user, but I was thinking of doing the reverse. I looked at this guide, which provides a way to retrieve all of the people who have a specific role. It seems like you could manipulate the collection/map to go through each member and remove the role. However, I cannot seem to achieve this.
I've hard-coded the one specific role that I am targeting as well as the message that should trigger the command.
Current code that I've been trying out (only seems to be working if there's just one person assigned the role):
if (msg.startsWith('!new round')) {
//check for everyone and remove the role
//roleID is just the roleID number string; I've stated it outside the if loop, for other command use cases as well
let membersWithRole = message.guild.roles.cache.get(roleID).members;
console.log(membersWithRole);
for (let member of membersWithRole) {
let mem = member[1]
mem.roles.remove(role).catch(console.error);
message.reply("Everyone with the jail role is now back in the game!");
}
}
Bottom line: Given a collection of the list of "guild" members that have the specified role (provided in the guide), could I iterate through a list* in order to remove the role from each member?
*I haven't found said list containing the members, but it's probably the objects themselves, so the whole collection
you need to learn documentation of discord.js
and yes you can do it by looping through all members.
if(msg.startsWith('!new round')){
console.log('command used by '+msg.author);
let role =msg.guild.roles.cache.get(roleId);
role.members.each(member=>{
member.roles.remove(role);
});
console.log('removed role from all members');
}
and also if you want to remove role from all members, so why you are not just deleting the role?
delete role:
msg.guild.roles.cache.get(roleId).delete();

Multiple objects with the same name were found

I'm working on an App for Office that inserts text/images into specific parts of the current Word document, as far as I've investigated, the only way to achieve this is by using ContentControls and creating a binding with:
Office.context.document.bindings.addFromNamedItemAsync();
Now, the problem is that when I have Content Controls inside both, the document body and the header/footer, I'm getting the following error:
Code: 3007
Name: Binding Creation Error
Message: Multiple objects with the same name were found.
According to Microsoft's website!, this is due to 2 or more CCs with the same name; but this is not the case since every CC that I created has an unique name, and when I move all of them to either the header/footer or the body, it works, the error just happens when they are located in different sections of the document.
This is the code I'm using:
Office.context.document.bindings.addFromNamedItemAsync("HeaderLogoCC","text",
{ id: 'logoBinding' }, function (result)
{
if (result.status == "failed")
{
result.error.message == "The named item does not exist."
}
(I know my English is not the best, I apologize in advance for any mistake and I can try to make it more clear, if necessary).
Any help would be really appreciated,
Thanks!

Spring LDAP - Remove user from group

I want to know what's the best way to remove a user from a group (without removing the user itself) using Spring LDAP 1.3.1. (The Spring LDAP version is important here because I can't upgrade right now and I'm NOT using the ODM).
I've tried this, but it doesn't work. The memberOf attribute is removed for the user, but the user entry remains in the group.
public void disable(User user) {
Name dn = buildDn(user.getUsername());
Attribute attr = new BasicAttribute("memberOf");
ModificationItem item = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr);
ldapTemplate.modifyAttributes(dn, new ModificationItem[] { item });
}
Any help would be very appreciated.
If you want to remove user from group you have to also delete him from members attribute of this group.

How do you get the value for an attribute when it's not your primary entity

I am trying to write a plugin that will trigger when an account is created. If there is a originating lead I want to fetch the company name in the lead and put it in the account name field. What I'm not sure how to do is to obtain the information out of the lead entity.
I have the following code (I'll keep updating this)...
Entity member = service.Retrieve("lead",
((EntityReference)account["originatingleadid"]).Id, new ColumnSet(true));
if (member.Attributes.Contains("companyname"))
{
companyName = member.Attributes["companyname"].ToString();
}
if (context.PostEntityImages.Contains("AccountPostImage") &&
context.PostEntityImages["AccountPostImage"] is Entity)
{
accountPostImage = (Entity)context.PostEntityImages["AccountPostImage"];
companyName = "This is a test";
if (companyName != String.Empty)
{
accountPostImage.Attributes["name"] = companyName;
service.Update(account);
}
}
I'm not going to spoil the fun for you just yet but the general idea is to:
Catch the message of Create.
Extract the guid from your Entity (that's your created account).
Obtain the guid from its EntityReference (that's your lead).
Read the appropriate field from it.
Update the name field in your account.
Store the information.
Which of the steps is giving you issues? :)
As always, I recommend using query expressions before fetchXML. YMMV
Is lead connected to the account? Just use the IOrganizationService.Retrieve Method
To retrieve the correct lead (assuming you have the lead id from the account entity)..
Create the organizationService in the execute method of your plugin.
http://msdn.microsoft.com/en-us/library/gg334504.aspx
Also here is a nice example to write the plugin:
http://mscrmkb.blogspot.co.il/2010/11/develop-your-first-plugin-in-crm-2011.html?m=1

Resources