Esempio n. 1
0
        public void SecurityService_EditProject()
        {
            //arrange
            UserProfileInfo u1 = new UserProfileInfo() { Login = "******" };
            UserProfileInfo u2 = new UserProfileInfo() { Login = "******" };
            Project p1 = new Project() { Creator = u1 };

            //act
            bool test1 = this.serviceSecurity.HasRight(SecureActivity.ProjectEdit, u2, p1);
            bool test2 = this.serviceSecurity.HasRight(SecureActivity.ProjectEdit, u1, p1);

            //assert
            Assert.IsFalse(test1,"u2 is not the creator -> does not has the right to edit");
            Assert.IsTrue(test2,"u1 is the creator -> has the right to edit");
        }
Esempio n. 2
0
        public void ProjectService_Create()
        {
            Project p = new Project();
             p.LicenceType = MoG.Licence.CCBY;
             p.Description = "Description";
             p.Likes = 0;
             p.Name = DateTime.Now.ToLongTimeString() + " - TEST";
             p.Tags = "ROCK POP TEST";
             p.VisibilityType = MoG.Visibility.Private;

            var user = serviceUser.GetCurrentUser();

            int i = serviceProject.Create(p, user);
            var activities = serviceProject.GetProjectActivity(i);

            Assert.IsTrue(i > 0);
            Assert.IsTrue(p.Id > 0);
            Assert.IsTrue(activities.Count > 0);
        }
Esempio n. 3
0
 public bool IsOwner(Project project, UserProfileInfo user)
 {
     return project.Creator.Login == user.Login;
 }
Esempio n. 4
0
        public IList<ProjectFile> GetFilteredFiles(Project project, string filterByAuthor, string filterByStatus, string filterByTag)
        {
            var files = project.Files;
            IEnumerable<ProjectFile> result = files.Where(f => f.Deleted == false);
            if (!String.IsNullOrEmpty(filterByAuthor))
            {
                result = result.Where(f => f.Creator.DisplayName == filterByAuthor);
            }
            if (!String.IsNullOrEmpty(filterByStatus))
            {
                FileStatus testStatus = (FileStatus)Enum.Parse(typeof(FileStatus), filterByStatus);
                result = result.Where(f => f.FileStatus == testStatus);
            }
            if (!String.IsNullOrEmpty(filterByTag))
            {
                //FileType testType = (FileType)Enum.Parse(typeof(FileType), filterByType);
                result = result.Where(f => f.Tags.Contains(filterByTag));
            }

            return result.ToList();
        }
Esempio n. 5
0
        public ICollection<string> GetFileTags(Project project)
        {
            List<string> result = new List<string>();
            if (project != null && project.Files != null && project.Files.Count > 0)
            {

                var filetags = project.Files
                    .Where(f => f.Deleted == false)
                    .Select(file => (file.Tags != null ? file.Tags.Split(',') : null));
                if (filetags != null)
                {
                    foreach (var filetag in filetags)
                    {
                        if (filetag != null)
                        {
                            foreach (string tag in filetag)
                            {
                                result.Add(tag);
                            }

                        }
                    }

                }
                return result.Distinct().ToList();
            }
            return new List<String>();
        }
Esempio n. 6
0
 public ICollection<string> GetFileStatuses(Project project)
 {
     if (project != null && project.Files != null && project.Files.Count > 0)
     {
         return project.Files.Select(file => file.FileStatus.ToString()).Distinct().ToList();
     }
     return new List<String>();
 }
Esempio n. 7
0
 public ICollection<string> GetFileAuthors(Project project)
 {
     if (project != null && project.Files != null && project.Files.Count > 0)
     {
         return project.Files.Select(file => file.Creator.DisplayName).Distinct().ToList();
     }
     return new List<String>();
 }
Esempio n. 8
0
 public bool Create(Project p)
 {
     dbContext.Projects.Add(p);
     int result = dbContext.SaveChanges();
     return (result > 0);
 }
Esempio n. 9
0
 private void notifyProjectCreation(Project project)
 {
     var followers = serviceFollow.GetFollowerUsers(project.Creator.Id);
     List<Notification> notifications = new List<Notification>();
     foreach (var follower in followers)
     {
         //TODO : message translation + Url management
         Notification n = new Notification()
         {
             Message = "a new project was created by " + project.Creator.DisplayName,
             UserId = follower.Id,
             PictureUrl = project.Creator.PictureUrl,
             Url = "/Project/Detail/" + project.Id
         };
         notifications.Add(n);
     }
     repoNotification.Create(notifications);
 }
Esempio n. 10
0
        public void LogProjectCreation(Project project)
        {
            Activity act = new Activity();
            act.ProjectId = project.Id;
            act.Who = project.Creator;
            act.When = DateTime.Now;
            act.Type = ActivityType.Create | ActivityType.Project;
            repoActivity.Create(act);

            notifyProjectCreation(project);
        }
Esempio n. 11
0
 public bool IsInvited(Project project, UserProfileInfo user)
 {
     return this.repoInvit.IsInvited(project.Id, user.Id);
 }
Esempio n. 12
0
 public bool IsFollowed(Project project, UserProfileInfo user)
 {
     if (project == null || user == null)
         return false;
     return this.repo.IsFollowed(project.Id, user.Id);
 }
Esempio n. 13
0
        public JsonResult SaveProjectSettings(Project model)
        {
            var project = serviceProject.GetById(model.Id);

            if (!this.serviceSecurity.HasRight(SecureActivity.ProjectEdit, CurrentUser, project))
            {
                return new JsonResult() { Data = false };
            }
            project.Name = model.Name;
            project.Description = model.Description;
            project.VisibilityType = model.VisibilityType;
            project.LicenceType = model.LicenceType;
            Project result = serviceProject.SaveChanges(project);
            return new JsonResult() { Data = true };
        }
Esempio n. 14
0
        public JsonResult JSON(int id)
        {
            var project = serviceProject.GetById(id);

            if (!this.serviceSecurity.HasRight(SecureActivity.ProjectView, CurrentUser, project))
            {
                return JsonHelper.ResultError(null, null, Resources.Resource.COMMON_PermissionDenied, JsonRequestBehavior.AllowGet);
            }

            var projectVM = new Project()
            {
                Id = project.Id,
                Description = project.Description,
                Name = project.Name,
                VisibilityType = project.VisibilityType,
                LicenceType = project.LicenceType
            };
            return new JsonResult() { Data = projectVM, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }
Esempio n. 15
0
 public Project SaveChanges(Project project)
 {
     project.ModifiedOn = DateTime.Now;
     return projectRepo.SaveChanges(project);
 }
Esempio n. 16
0
 public Project SaveChanges(Project project)
 {
     dbContext.Entry(project).State = System.Data.Entity.EntityState.Modified;
     dbContext.SaveChanges();
     return project;
 }
Esempio n. 17
0
        public int Create(Project project, UserProfileInfo userProfile)
        {
            project.CreatedOn = DateTime.Now;
            project.ModifiedOn = DateTime.Now;
            project.Creator = userProfile;
            project.Likes = 0;

            project.ImageUrl = "~/Content/Images/nothingyetbw.png";//http://placehold.it/700*400
            project.ImageUrlThumb1 = "~/Content/Images/nothingyetbw.png";// "http://placehold.it/350x200";

            if (projectRepo.Create(project))
            {
                serviceActivity.LogProjectCreation(project);

                return project.Id;
            }
            return -1;
        }
Esempio n. 18
0
 public int GetLikeCount(Project p)
 {
     return this.GetLikeCount(p.Id);
 }