public void SetUp()
        {
            _shimsContext  = ShimsContext.Create();
            _testable      = new RequestWorkspaceTestable();
            _projectInfo   = new ProjectInfoResult();
            _workspaceInfo = new WorkspaceInfoResult
            {
                ListName      = "test-list",
                WorkspaceName = "test-workspace"
            };

            ShimSPProjectUtility.AllInstances.RequestProjectInfo = (instance) =>
            {
                return(_projectInfo);
            };
            ShimSPProjectUtility.AllInstances.RequestWorkspaceInfoGuidInt32 = (instance, listId, listItemId) =>
            {
                return(_workspaceInfo);
            };

            ShimPage.AllInstances.RequestGet = (instance) => new ShimHttpRequest {
                ItemGetString = (name) =>
                                name == "List" ? Guid.NewGuid().ToString() :
                                name == "id" ? 1.ToString() :
                                null as string
            };

            ShimSPContext.CurrentGet = () => new ShimSPContext
            {
                WebGet = () => new ShimSPWeb
                {
                    CurrentUserGet = () => new ShimSPUser()
                }
            };
        }
Exemple #2
0
        public ProjectInfoResult RequestProjectInfo()
        {
            var result = new ProjectInfoResult();

            var login = SPContext.Current.Web.CurrentUser.LoginName;
            var url   = SPContext.Current.Web.Url;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (var mysite = new SPSite(url))
                {
                    using (var myweb = mysite.OpenWeb())
                    {
                        myweb.Site.CatchAccessDeniedException = false;
                        try
                        {
                            if (!myweb.DoesUserHavePermissions(login, SPBasePermissions.ManageSubwebs))
                            {
                                result.StatusCode = HttpStatusCode.Forbidden;
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteTrace(Area.EPMLiveCore, Categories.EPMLiveCore.LayoutPage, TraceSeverity.VerboseEx, ex.ToString());
                            result.StatusCode = HttpStatusCode.Forbidden;
                            return;
                        }

                        result.ServerRelativeUrl = myweb.ServerRelativeUrl;
                        result.BaseUrl           = myweb.Url + "/";

                        var lockweb = CoreFunctions.getLockedWeb(myweb);
                        if (lockweb != Guid.Empty)
                        {
                            using (SPWeb web = myweb.Site.AllWebs[lockweb])
                            {
                                result.ValidTemplates      = ReadConfigTemplates(web);
                                result.IsNavigationEnabled = ReadConfigNavigationFlag(web);
                                result.IsUnique            = ReadConfigUniqueFlag(web);
                                result.IsWorkspaceExisting = ReadConfigWorkspaceFlag(web);
                            }
                        }

                        result.PopulatedTemplates = PopulateTemplates(myweb, result.ValidTemplates);
                    }
                }
            });

            return(result);
        }
        public void SetUp()
        {
            _shimsContext      = ShimsContext.Create();
            _testable          = new NewAppTestable();
            _requestParameters = new Dictionary <string, string>
            {
                { "hdnSelectedWorkspace", string.Empty },
                { "List", Guid.NewGuid().ToString() },
            };
            _workspaceInfo = new WorkspaceInfoResult
            {
                ListName      = "test-list",
                WorkspaceName = "test-workspace"
            };

            _projectInfo = new ProjectInfoResult();
            ShimSPProjectUtility.AllInstances.RequestProjectInfo = (instance) =>
            {
                return(_projectInfo);
            };
            ShimSPProjectUtility.AllInstances.RequestWorkspaceInfoGuid = (instance, listId) =>
            {
                return(_workspaceInfo);
            };

            _serverRelativeUrl = "http://test.test";
            _redirectUrl       = null;
            _dbUpdateExecuted  = false;
            _listExists        = true;

            ShimPage.AllInstances.RequestGet = (instance) => new ShimHttpRequest
            {
                ItemGetString = (name) => _requestParameters[name]
            };

            ShimPage.AllInstances.ResponseGet = (instance) => new ShimHttpResponse
            {
                RedirectString = (url) => _redirectUrl = url
            };

            ShimCoreFunctions.createSiteStringStringStringStringBooleanBooleanSPWeb =
                (title, url, group, loginName, isUnique, isTopLink, web) =>
            {
                return("0");    // "0" means the entity is created successfully
            };

            ShimSPWebInternals();
        }
Exemple #4
0
 private void UpdateSampleDataAndSort(ProjectInfoResult projectInfo)
 {
     foreach (Sample sample in Samples)
     {
         if (sample.Name != projectInfo.Name)
         {
             continue;
         }
         if (!string.IsNullOrEmpty(projectInfo.Description))
         {
             sample.Description = projectInfo.Description;
         }
         sample.IsFeatured = projectInfo.IsFeatured;
         Samples           = Samples.OrderByDescending(s => s.IsFeatured).ToList();
         break;
     }
 }
Exemple #5
0
        public async Task <PartialViewResult> SetProject(int id, int projectId)
        {
            ProjectInfoResult prj = null;

            using (var cn = _data.GetConnection())
            {
                var wi = await _data.FindWorkItemAsync(cn, id);

                wi.ProjectId    = projectId;
                wi.ModifiedBy   = User.Identity.Name;
                wi.DateModified = _data.CurrentUser.LocalTime;
                await cn.UpdateAsync(wi, _data.CurrentUser, r => r.ProjectId, r => r.ModifiedBy, r => r.DateModified);

                prj = await new ProjectInfo()
                {
                    OrgId = _data.CurrentOrg.Id, Id = projectId
                }.ExecuteSingleAsync(cn);
            }

            return(PartialView("/Pages/Dashboard/Items/_ItemInfo.cshtml", prj));
        }
Exemple #6
0
        protected override async Task OnGetInternalAsync(SqlConnection connection)
        {
            CurrentAppId = CurrentOrgUser.CurrentAppId;

            if (Id.HasValue)
            {
                SelectedProject = await Data.FindAsync <Project>(connection, Id.Value);

                SelectedProjectInfo = await new ProjectInfo()
                {
                    Id = Id, OrgId = OrgId
                }.ExecuteSingleAsync(connection);
                ProjectComments = await new Comments()
                {
                    OrgId = OrgId, ObjectType = ObjectType.Project, ObjectIds = new[] { SelectedProject.Id }
                }.ExecuteAsync(connection);
                ImportFromProject = await new ProjectSelect()
                {
                    TeamId = CurrentOrgUser?.CurrentTeamId ?? 0, ExcludeId = Id.Value
                }.ExecuteSelectListAsync(connection);

                if (CurrentOrg.UseFreshdesk())
                {
                    var companies = await _companyCache.QueryAsync(CurrentOrg.Name);

                    FreshdeskCompanySelect = new SelectList(companies.Select(c => new SelectListItem()
                    {
                        Value = c.Id.ToString(), Text = c.Name
                    }), "Value", "Text", SelectedProject.FreshdeskCompanyId);
                }
            }
            else
            {
                // crosstab rows (or card view)
                ProjectInfo = await new ProjectInfo(Sort)
                {
                    OrgId = OrgId, IsActive = IsActive, AppId = CurrentOrgUser.CurrentAppId, Show = Show, IsAppActive = true
                }.ExecuteAsync(connection);
                if (!ProjectInfo.Any())
                {
                    ProjectInfo = new ProjectInfoResult[] { new ProjectInfoResult()
                                                            {
                                                                Name = "Items Without a Project", ApplicationId = CurrentOrgUser.CurrentAppId ?? 0
                                                            } }
                }
                ;

                if (View == ProjectViewOptions.Crosstab)
                {
                    // crosstab columns
                    var milestones = await new Milestones()
                    {
                        OrgId = OrgId
                    }.ExecuteAsync(connection);

                    // crosstab cells
                    var workItems = await new OpenWorkItems()
                    {
                        OrgId = OrgId, AppId = CurrentOrgUser.CurrentAppId
                    }.ExecuteAsync(connection);
                    ProjectWorkItems = workItems.ToLookup(row => new ProjectDashboardCell(row.ProjectId, row.MilestoneDate ?? DateTime.MaxValue));

                    var workItemIds = workItems.Select(wi => wi.Id).ToArray();
                    var labels      = await new LabelsInUse()
                    {
                        OrgId = OrgId, WorkItemIds = workItemIds
                    }.ExecuteAsync(connection);
                    Labels = labels.ToLookup(row => row.WorkItemId);

                    // there's only enough horizontal room for 3 milestones + optional placeholder for work items without a milestone
                    var milestoneList = milestones.Take(3).ToList();
                    // if there's any work item info without a milestone, then we need to append an empty milestone column to the crosstab
                    if (workItems.Any(lbl => !lbl.MilestoneDate.HasValue))
                    {
                        milestoneList.Add(new Milestone()
                        {
                            Name = "Drag to a milestone", Date = DateTime.MaxValue, ShowDate = false
                        });
                    }

                    MilestoneDates = milestoneList.ToLookup(row => row.Date);
                }
            }
        }