示例#1
0
        public async Task <ActionResult> Items(WebUser user, string id, string returnUrl)
        {
            var accessRight = await _accessManager.GetUserAccess(id, user.Id);

            if ((await _vaultManager.GetVaultAdmin(id)).Id == user.Id)
            {
                var vaultItems = await _vaultManager.GetAllItems(id);

                var editmodel = CreateVaultItemListModel(id, vaultItems, accessRight, returnUrl);
                return(View(editmodel));
            }

            if (accessRight == null)
            {
                TempData["message"] = "You don't have enough rights to access this vault";
                var message = $"User {user.UserName} tried to get access to the vault";
                await _vaultItemHelper.Log(id, "Deny", message);
                await ReportToAdmin(id, message);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                if (!await _accessManager.TimeAccessAsync(id))
                {
                    TempData["message"] = "At this this time the vault you want to get access is closed";
                    var message = $"User {user.UserName} tried to get access to the vault when it was closed";
                    await _vaultItemHelper.Log(id, "Deny", message);
                    await ReportToAdmin(id, message);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    if (accessRight == "Create")
                    {
                        var items = await _vaultManager.GetAllItems(id);

                        var editItem = CreateVaultItemListModel(id, items, accessRight, returnUrl);
                        await _vaultItemHelper.Log(id, "Full Access", $"User {user.UserName} entered the vault");

                        return(View(editItem));
                    }
                    else
                    {
                        var items = await _vaultManager.GetAllItems(id);

                        var editItem = CreateVaultItemListModel(id, items, accessRight, returnUrl);
                        await _vaultItemHelper.Log(id, "Read Access", $"User {user.UserName} entered the vault");

                        return(View(editItem));
                    }
                }
            }
        }