Beispiel #1
0
 public ActionResult DeleteInvitation(EditInvitationsViewModel model, long? id)
 {
     var inv = _fileManager.FindInvitation(id.Value);
     if (inv == null)
         return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);
     DeleteInvitation(inv);
     return RedirectToAction("Index", new { fullName = model.FullName });
 }
Beispiel #2
0
        public ActionResult NewInvitation(EditInvitationsViewModel model)
        {
            List<User> uninvited = new List<User>(uninvitedUsers(model.FullName));
            if (ModelState.IsValid)
            {
                Folder userRootFolder = _fileManager.GetUserRootFolder(User.Identity.GetUserId());
                User currentUser = _userManager.FindUser(User.Identity.GetUserId());
                string fullDisplayName;
                Folder f = (Folder)_fileManager.FindFile(model.FullName, userRootFolder, out fullDisplayName);

                if (DetermineDisallowedReason(f) != InvitationDisallowedReason.None)
                    return new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden);

                foreach (var item in model.UsersToInvite)
                {
                    if (item.IsSelected)
                    {
                        FooBox.User u = _userManager.FindUser(item.Id);
                        var invitation = new Invitation
                        {
                            Target = f,
                            TargetId = f.Id,
                            User = u,
                            UserId = u.Id,
                            TimeStamp = DateTime.UtcNow
                        };
                        _userManager.Context.Invitations.Add(invitation);
                        _userManager.Context.SaveChanges();
                    }
                }
                foreach (var item in model.GroupsToInvite)
                {
                    if (item.IsSelected)
                    {
                        FooBox.Group g = _userManager.FindGroup(item.Id);
                        foreach (User u in g.Users)
                        {
                            if (u == _userManager.GetDefaultUser() ||
                                u.State == ObjectState.Deleted ||
                                u == currentUser) continue;
                            if (uninvited.Contains(u))
                            {
                                uninvited.Remove(u);
                                var invitation = new Invitation
                                {
                                    Target = f,
                                    TargetId = f.Id,
                                    User = u,
                                    UserId = u.Id,
                                    TimeStamp = DateTime.UtcNow
                                };
                                _userManager.Context.Invitations.Add(invitation);
                                _userManager.Context.SaveChanges();
                            }
                        }
                    }
                }
                return RedirectToAction("Index", new { fullName = model.FullName });
            }
            return View(model);
        }
Beispiel #3
0
        public ActionResult Index(string fullName)
        {
            if (fullName == null)
                return RedirectToAction("Browse", "File", null);

            Folder userRootFolder = _fileManager.GetUserRootFolder(User.Identity.GetUserId());
            User currentUser = _userManager.FindUser(User.Identity.GetUserId());
            string fullDisplayName;
            File file = _fileManager.FindFile(fullName, userRootFolder, out fullDisplayName);

            if (file == null || file is Document)
            {
                return HttpNotFound();
            }

            Folder folder = (Folder)file;

            if (DetermineDisallowedReason(folder) != InvitationDisallowedReason.None)
                return new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden);

            var mod = new EditInvitationsViewModel();

            mod.FullName = fullName;
            mod.FromPath = _fileManager.GetFullDisplayName(file.ParentFolder, userRootFolder);

            var invitations = _fileManager.Context.Invitations.ToList();
            foreach (Invitation i in invitations)
            {
                if (i.TargetId == folder.Id)
                {
                    var ivm = new InvitationVM
                    {
                        Id = i.Id,
                        UserName = i.User.Name,
                        Timestamp = i.TimeStamp,
                        Accepted = i.AcceptedFolders.Any()
                    };
                    mod.FolderInvitations.Add(ivm);
                }
            }

            var uninvited = uninvitedUsers(fullName);
            foreach (User u in uninvited)
            {
                if (u == _userManager.GetDefaultUser() ||
                    u.State == ObjectState.Deleted ||
                    u == currentUser) continue;
                var e = new EntitySelectedViewModel
                {
                    Id = u.Id,
                    IsSelected = false,
                    Name = u.Name
                };
                mod.UsersToInvite.Add(e);
            }

            foreach (Group g in _userManager.Context.Groups)
            {
                if (g.State == ObjectState.Deleted) continue;
                var e = new EntitySelectedViewModel
                {
                    Id = g.Id,
                    IsSelected = false,
                    Name = g.Name
                };
                mod.GroupsToInvite.Add(e);
            }

            ViewBag.Subheading = folder.DisplayName;
            return View(mod);
        }