public object Delete(CommunityRemoveUserRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); if (string.IsNullOrEmpty(request.Identifier)) { throw new Exception("Invalid request - missing community identifier"); } User user = string.IsNullOrEmpty(request.Username) ? User.FromId(context, context.UserId) : User.FromUsername(context, request.Username); context.LogInfo(this, string.Format("/community/user DELETE Identifier='{0}', Username='******', Reason='{2}'", request.Identifier, request.Username, request.Reason)); ThematicCommunity domain = ThematicCommunity.FromIdentifier(context, request.Identifier); domain.RemoveUser(user, request.Reason); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public void JoinPublicCommunity() { context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); var usr2 = User.FromUsername(context, "testusr2"); context.StartImpersonation(usr1.Id); try { ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-public-1"); var roles = Role.GetUserRolesForDomain(context, usr1.Id, community.Id); //user not part of community Assert.AreEqual(0, roles.Length); community.TryJoinCurrentUser(); roles = Role.GetUserRolesForDomain(context, usr1.Id, community.Id); //user part of community Assert.AreEqual(1, roles.Length); Assert.AreEqual(RoleTep.MEMBER, roles [0].Name); //check user cannot joins twice community.TryJoinCurrentUser(); roles = Role.GetUserRolesForDomain(context, usr1.Id, community.Id); Assert.AreEqual(1, roles.Length); context.EndImpersonation(); context.StartImpersonation(usr2.Id); var role = Role.FromIdentifier(context, RoleTep.STARTER); community.SetUserRole(usr1, role); roles = Role.GetUserRolesForDomain(context, usr1.Id, community.Id); //user part of community Assert.AreEqual(1, roles.Length); Assert.AreEqual(RoleTep.STARTER, roles [0].Name); community.RemoveUser(usr1); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }
public void JoinPrivateCommunity() { context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); var usr2 = User.FromUsername(context, "testusr2"); var ose = MasterCatalogue.OpenSearchEngine; var parameters = new NameValueCollection(); try { context.StartImpersonation(usr1.Id); ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-private-1"); Role role = Role.FromIdentifier(context, RoleTep.MEMBER); //check how many communities user can see var communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; IOpenSearchResultCollection osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); context.EndImpersonation(); context.StartImpersonation(usr2.Id); //add user in community community.SetUserAsTemporaryMember(usr1); Assert.True(community.IsUserPending(usr1.Id)); context.EndImpersonation(); context.StartImpersonation(usr1.Id); //check how many communities user can see communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC + 1, osr.TotalResults); //check visibility is private + pending var items = osr.Items; bool isprivate = false, isVisibilityPending = false, ispublic = false; foreach (var item in items) { if (item.Title.Text == "community-private-1") { foreach (var cat in item.Categories) { if (cat.Name == "visibility") { if (cat.Label == "hidden") { isprivate = true; } else if (cat.Label == "public") { ispublic = true; } } else if (cat.Name == "status" && cat.Label == "pending") { isVisibilityPending = true; } } } } Assert.True(isprivate); Assert.True(isVisibilityPending); Assert.False(ispublic); //usr1 validates community.TryJoinCurrentUser(); Assert.True(community.IsUserPending(usr1.Id)); //check how many communities user can see communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC + 1, osr.TotalResults); //remove from community community.RemoveUser(usr1); //check how many communities user can see communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }