Пример #1
0
        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();
            }
        }
Пример #2
0
        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();
            }
        }