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(); } }
/// <summary> /// Post the specified request. /// </summary> /// <param name="request">Request.</param> public object Post(CommunityAddUserRequestTep 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); //we use administrator access level to be able to load the community context.AccessLevel = EntityAccessLevel.Administrator; ThematicCommunity domain = ThematicCommunity.FromIdentifier(context, request.Identifier); Role role = Role.FromIdentifier(context, string.IsNullOrEmpty(request.Role) ? domain.DefaultRoleName : request.Role); context.LogInfo(this, string.Format("/community/user POST Identifier='{0}', Username='******', Role='{2}'", request.Identifier, user.Username, role.Identifier)); if (string.IsNullOrEmpty(request.Username)) { //case user auto Join domain.TryJoinCurrentUser(request.Objectives); } else { //case owner add user with role domain.SetUserRole(user, role); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public void SearchCommunitiesForWpsJob() { context.AccessLevel = EntityAccessLevel.Administrator; ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-public-1"); var wpsjob = WpsJob.FromIdentifier(context, "private-job-usr1"); context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); context.StartImpersonation(usr1.Id); try { community.TryJoinCurrentUser(); //share as owner and member of community community.ShareEntity(wpsjob); var communities = new EntityList <ThematicCommunity>(context); var parameters = new NameValueCollection(); parameters.Set("correlatedTo", string.Format("{0}/job/wps/search?uid={1}", context.BaseUrl, "private-job-usr1")); IOpenSearchResultCollection osr = ose.Query(communities, parameters); Assert.AreEqual(1, osr.TotalResults); //unshare the job wpsjob.RevokePermissionsFromAll(true, false); wpsjob.DomainId = wpsjob.Owner.DomainId; wpsjob.Store(); Assert.False(wpsjob.IsSharedToCommunity()); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }
public void SearchAllCommunities() { var ose = MasterCatalogue.OpenSearchEngine; var parameters = new NameValueCollection(); context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); var usr2 = User.FromUsername(context, "testusr2"); var usr3 = User.FromUsername(context, "testusr3"); try { context.StartImpersonation(usr1.Id); var communities = new CommunityCollection(context); communities.Identifier = "community"; communities.OpenSearchEngine = ose; //communities.UserId = usr1.Id; var osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); parameters.Set("q", "public"); osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); parameters.Set("q", "public*"); osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); parameters.Set("q", "*"); osr = ose.Query(communities, parameters); Assert.AreEqual(NBCOMMUNITY_PUBLIC, osr.TotalResults); parameters.Remove("q"); parameters.Set("status", "joined"); communities.UserStatus = ThematicCommunity.USERSTATUS_JOINED; osr = ose.Query(communities, parameters); Assert.AreEqual(0, osr.TotalResults); context.EndImpersonation(); context.StartImpersonation(usr2.Id); communities.UserId = usr2.Id; osr = ose.Query(communities, parameters); Assert.AreEqual(4, osr.TotalResults); context.EndImpersonation(); context.StartImpersonation(usr3.Id); ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-public-1"); community.TryJoinCurrentUser(); var roles = Role.GetUserRolesForDomain(context, usr3.Id, community.Id); //user part of community Assert.AreEqual(1, roles.Length); Assert.AreEqual(RoleTep.MEMBER, roles[0].Name); communities.UserId = usr3.Id; osr = ose.Query(communities, parameters); Assert.AreEqual(1, osr.TotalResults); context.EndImpersonation(); communities.UserId = usr3.Id; osr = ose.Query(communities, parameters); Assert.AreEqual(1, osr.TotalResults); } catch (Exception e) { context.EndImpersonation(); Assert.Fail(e.Message); } }
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(); } }
public void ShareWpsJobToCommunity() { context.AccessLevel = EntityAccessLevel.Administrator; ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-public-1"); var wpsjob = WpsJob.FromIdentifier(context, "private-job-usr1"); var wpsjob2 = WpsJob.FromIdentifier(context, "private-job-usr2"); context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); context.StartImpersonation(usr1.Id); try { //share as non owner try { community.ShareEntity(wpsjob2); Assert.Fail("Cannot share as non owner"); } catch (Exception) { } //share as owner and not member of community try { community.ShareEntity(wpsjob2); Assert.Fail("Cannot share as non member"); } catch (Exception) { } community.TryJoinCurrentUser(); //share as owner and member of community community.ShareEntity(wpsjob); Assert.True(wpsjob.IsSharedToCommunity()); EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context); var parameters = new NameValueCollection(); parameters.Set("q", "private-job-usr1"); IOpenSearchResultCollection osr = ose.Query(wpsjobs, parameters); Assert.AreEqual(1, osr.TotalResults); bool hasSharedLink = false; foreach (var item in osr.Items) { if (item.Identifier == "private-job-usr1") { foreach (var link in item.Links) { if (link.RelationshipType == "results") { hasSharedLink = true; } } } } Assert.True(hasSharedLink); //unshare the job wpsjob.RevokePermissionsFromAll(true, false); wpsjob.DomainId = wpsjob.Owner.DomainId; wpsjob.Store(); Assert.False(wpsjob.IsSharedToCommunity()); wpsjobs = new EntityList <WpsJob>(context); parameters = new NameValueCollection(); parameters.Set("q", "private-job-usr1"); osr = ose.Query(wpsjobs, parameters); Assert.AreEqual(1, osr.TotalResults); hasSharedLink = false; foreach (var item in osr.Items) { if (item.Identifier == "private-job-usr1") { foreach (var link in item.Links) { if (link.RelationshipType == "results") { hasSharedLink = true; } } } } Assert.False(hasSharedLink); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }