public void AppendGroupMemberships(List <Guid> itemGroupIds) { if (itemGroupIds == null) { return; } bool allowOneGroupMembership = ConfigurationMapper.Instance.ItemsAllowOneGroupMembership; List <Guid> itemGroupIdsToInsert = allowOneGroupMembership ? new List <Guid> () : new List <Guid> (itemGroupIds); if (allowOneGroupMembership && itemGroupIds.Count > 0) { itemGroupIdsToInsert.Add(itemGroupIds.First()); if (!this.GroupMemberships.Any(gm => gm.ItemGroupId == itemGroupIdsToInsert.First())) { this.GroupMemberships.Children.Clear(); } } foreach (Guid itemGroupId in itemGroupIds) { if (!this.GroupMemberships.Any(gm => gm.ItemGroupId == itemGroupId)) { var groupMembership = GroupMemberships.CreateNew(); groupMembership.ItemGroupId = itemGroupId; } } }
public override object Deserialize(JsonValue json, JsonMapper mapper) { GroupMemberships groupMemberships = (GroupMemberships)base.Deserialize(json, mapper); groupMemberships.Memberships = DeserializeMemberships(json.GetValue("values")); return(groupMemberships); }
public int CompareTo(object obj) { var user = obj as IUserDto; if (user == null) { return(0); } Assert.AreEqual(UserGuid, user.UserGuid, "User Guid Does NOT Match."); Assert.AreEqual(PasswordHash, user.PasswordHash, "User Password Hash Does NOT Match."); Assert.AreEqual(FirstName, user.FirstName, "User First Name Does NOT Match."); Assert.AreEqual(LastName, user.LastName, "User Last Name Does NOT Match."); Assert.AreEqual(JobTitle, user.JobTitle, "User Job Title Does NOT Match."); Assert.AreEqual(ContactNumber, user.ContactNumber, "User Contact Number Does NOT Match."); Assert.AreEqual(Email, user.Email, "User Email Does NOT Match."); Assert.AreEqual(EmailConfirmed, user.EmailConfirmed, "User Email Confirmed Does NOT Match."); Assert.AreEqual(PhoneNumber, user.PhoneNumber, "User Phone Number Does NOT Match."); Assert.AreEqual(PhoneNumberConfirmed, user.PhoneNumberConfirmed, "User Phone Number Confirmed Does NOT Match."); Assert.AreEqual(TwoFactorEnabled, user.TwoFactorEnabled, "User Two Factor Enabled Does NOT Match."); Assert.AreEqual(AccountLocked, user.AccountLocked, "User Account Locked Does NOT Match."); Assert.AreEqual(AccessFailedCount, user.AccessFailedCount, "User Access Failed Count Does NOT Match."); Assert.AreEqual(ShopBillingNotification, user.ShopBillingNotification, "User Shop Billing Notification Does NOT Match."); Assert.AreEqual(ShopReportNotification, user.ShopReportNotification, "User Shop Report Notification Does NOT Match."); Assert.AreEqual(TimeZoneInfoId, user.TimeZoneInfoId, "User Time Zone Info Id Does NOT Match."); Assert.IsTrue(user.AccountMemberships?.All(r => AccountMemberships?.Contains(r) ?? false) ?? true, "User Account Memberships Do NOT Match."); Assert.IsTrue(user.ShopMemberships?.All(r => ShopMemberships?.Contains(r) ?? false) ?? true, "User Shop Memberships Do NOT Match."); Assert.IsTrue(user.GroupMemberships?.All(r => GroupMemberships?.Contains(r) ?? false) ?? true, "User Group Memberships Do NOT Match."); return(1); }
private void AddByGroup(List <Permission> permissions, GraphHttpClient graphClient, Dictionary <int, string> permission, string repositoryName, KeyValuePair <Microsoft.VisualStudio.Services.Identity.IdentityDescriptor, AccessControlEntry> kvp, GraphGroup group) { GroupMemberships expandedMembers = ExpandVSTSGroup(graphClient, group); foreach (var user in expandedMembers.Users) { CreatePermissionList(permissions, permission, repositoryName, kvp, user, group); } }
private static GroupMemberships ExpandVSTSGroup(GraphHttpClient graphClient, GraphGroup group) { groupCache.TryGetValue(group, out GroupMemberships groupMemberships); if (groupMemberships != null) { return(groupMemberships); } groupMemberships = new GroupMemberships(); // Convert all memberships into GraphSubjectLookupKeys List <GraphSubjectLookupKey> lookupKeys = new List <GraphSubjectLookupKey>(); List <GraphMembership> memberships = graphClient.ListMembershipsAsync(group.Descriptor, GraphTraversalDirection.Down).Result; foreach (var membership in memberships) { lookupKeys.Add(new GraphSubjectLookupKey(membership.MemberDescriptor)); } IReadOnlyDictionary <SubjectDescriptor, GraphSubject> subjectLookups = graphClient.LookupSubjectsAsync(new GraphSubjectLookup(lookupKeys)).Result; foreach (GraphSubject subject in subjectLookups.Values) { if (subject.OriginId.Equals(group.OriginId)) { break; //Father paradox } switch (subject.Descriptor.SubjectType) { //member is an AAD user case "aad": groupMemberships.AddUser((GraphUser)subject); break; //member is an MSA user case "asd2": groupMemberships.AddUser((GraphUser)subject); break; //member is a nested AAD group case "aadgp": groupMemberships.AddAADGroup((GraphGroup)subject); break; //member is a nested VSTS group case "vssgp": GroupMemberships subGroupMemberships = ExpandVSTSGroup(graphClient, (GraphGroup)subject); groupMemberships.Add(subGroupMemberships); break; default: throw new Exception("Unknown SubjectType: " + subject.Descriptor.SubjectType); } } groupCache.Add(group, groupMemberships); return(groupMemberships); }
/// <summary> /// Returns true if UserViewModel instances are equal /// </summary> /// <param name="other">Instance of UserViewModel to be compared</param> /// <returns>Boolean</returns> public bool Equals(UserViewModel other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id.Equals(other.Id) ) && ( Active == other.Active || Active.Equals(other.Active) ) && ( GivenName == other.GivenName || GivenName != null && GivenName.Equals(other.GivenName) ) && ( Surname == other.Surname || Surname != null && Surname.Equals(other.Surname) ) && ( Email == other.Email || Email != null && Email.Equals(other.Email) ) && ( SmUserId == other.SmUserId || SmUserId != null && SmUserId.Equals(other.SmUserId) ) && ( UserRoles == other.UserRoles || UserRoles != null && UserRoles.SequenceEqual(other.UserRoles) ) && ( GroupMemberships == other.GroupMemberships || GroupMemberships != null && GroupMemberships.SequenceEqual(other.GroupMemberships) ) && ( District == other.District || District != null && District.Equals(other.District) )); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { int hash = 41; // Suitable nullity checks hash = hash * 59 + Id.GetHashCode(); hash = hash * 59 + Active.GetHashCode(); if (GivenName != null) { hash = hash * 59 + GivenName.GetHashCode(); } if (Surname != null) { hash = hash * 59 + Surname.GetHashCode(); } if (Email != null) { hash = hash * 59 + Email.GetHashCode(); } if (SmUserId != null) { hash = hash * 59 + SmUserId.GetHashCode(); } if (UserRoles != null) { hash = hash * 59 + UserRoles.GetHashCode(); } if (GroupMemberships != null) { hash = hash * 59 + GroupMemberships.GetHashCode(); } if (District != null) { hash = hash * 59 + District.GetHashCode(); } return(hash); } }
public void GetGroupMemberships() { mockServer.ExpectNewRequest() .AndExpectUri("https://api.linkedin.com/v1/people/~/group-memberships:(group:(id,name),membership-state,show-group-logo-in-profile,allow-messages-from-members,email-digest-frequency,email-announcements-from-managers,email-for-every-new-post)?format=json") .AndExpectMethod(HttpMethod.GET) .AndRespondWith(JsonResource("GroupMemberships"), responseHeaders); GroupMemberships memberships = linkedIn.GroupOperations.GetGroupMembershipsAsync().Result; Assert.AreEqual(10, memberships.Count); Assert.AreEqual(0, memberships.Start); Assert.AreEqual(30, memberships.Total); Assert.AreEqual(10, memberships.Memberships.Count); var s = memberships.Memberships[0]; Assert.AreEqual(true, s.AllowMessagesFromMembers); Assert.AreEqual(false, s.EmailAnnouncementsFromManagers); Assert.AreEqual(EmailDigestFrequency.None, s.EmailDigestFrequency); Assert.AreEqual(MembershipState.Member, s.MembershipState); Assert.AreEqual(true, s.ShowGroupLogoInProfile); Assert.AreEqual(69286, s.Group.ID); Assert.AreEqual("Software Architect Network", s.Group.Name); }
protected override void Execute(CodeActivityContext context) { PrincipalContext principalContext; if (IsLocalAccount.Get(context)) { principalContext = new PrincipalContext(ContextType.Machine); } else { principalContext = new PrincipalContext(ContextType.Domain, Domain.Get(context), DomainContainer.Get(context)); } UserPrincipal principal = UserPrincipal.FindByIdentity(principalContext, Username.Get(context)); if (principal == null) { principal = new UserPrincipal(principalContext, Username.Get(context), Password.Get(context), true); principal.DisplayName = Firstname.Get(context) + " " + Lastname.Get(context); principal.PasswordNeverExpires = true; principal.Save(); IList <string> groups = GroupMemberships.Get(context) ?? new List <string>(); foreach (var group in groups) { GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, group); if (!groupPrincipal.Members.Contains(principal)) { groupPrincipal.Members.Add(principal); } groupPrincipal.Save(); } } else if (UpdateExistingUser.Get(context)) { principal.SetPassword(Password.Get(context)); principal.DisplayName = Firstname.Get(context) + " " + Lastname.Get(context); principal.PasswordNeverExpires = true; principal.Save(); IList <string> groups = GroupMemberships.Get(context) ?? new List <string>(); foreach (var group in groups) { GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, group); if (!groupPrincipal.Members.Contains(principal)) { groupPrincipal.Members.Add(principal); } groupPrincipal.Save(); } GroupPrincipal allGroups = new GroupPrincipal(principalContext); allGroups.Name = "*"; PrincipalSearcher searcher = new PrincipalSearcher(allGroups); var allGroupList = searcher.FindAll(); foreach (GroupPrincipal group in allGroupList) { if (!groups.Contains(group.Name) && group.Members.Contains(principal)) { group.Members.Remove(principal); group.Save(); } } } }
/// <summary> /// Returns true if User instances are equal /// </summary> /// <param name="other">Instance of User to be compared</param> /// <returns>Boolean</returns> public bool Equals(User other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id.Equals(other.Id) ) && ( GivenName == other.GivenName || GivenName != null && GivenName.Equals(other.GivenName) ) && ( Surname == other.Surname || Surname != null && Surname.Equals(other.Surname) ) && ( Active == other.Active || Active.Equals(other.Active) ) && ( Initials == other.Initials || Initials != null && Initials.Equals(other.Initials) ) && ( Email == other.Email || Email != null && Email.Equals(other.Email) ) && ( SmUserId == other.SmUserId || SmUserId != null && SmUserId.Equals(other.SmUserId) ) && ( Guid == other.Guid || Guid != null && Guid.Equals(other.Guid) ) && ( SmAuthorizationDirectory == other.SmAuthorizationDirectory || SmAuthorizationDirectory != null && SmAuthorizationDirectory.Equals(other.SmAuthorizationDirectory) ) && ( UserRoles == other.UserRoles || UserRoles != null && UserRoles.SequenceEqual(other.UserRoles) ) && ( GroupMemberships == other.GroupMemberships || GroupMemberships != null && GroupMemberships.SequenceEqual(other.GroupMemberships) ) && ( District == other.District || District != null && District.Equals(other.District) )); }