//
        // GET: /ManagePermissions/
        public ActionResult Index()
        {
            if (!PermissionService.Authorize(PermissionProvider.ManagePermissions))
            {
                return(AccessDeniedView());
            }

            var roles = _unitOfWork.RoleRepository.Get();

            ViewBag.Roles = roles;
            var permissionRecords       = _unitOfWork.PermissionRecordRepository.Get();
            var query1                  = new PagedList <PermissionRecord>(permissionRecords.ToList(), 0, 100);
            PermissionRecordModel model = new PermissionRecordModel();

            model.RoleId           = roles.FirstOrDefault().Id;
            model.PermissionRecord = new GridModel <PermissionRecordModel>
            {
                Data = query1.Select(g => new PermissionRecordModel()
                {
                    Id         = g.Id,
                    Name       = g.Name,
                    SystemName = g.SystemName,
                    Category   = g.Category,
                    Allow      = g.Roles.Any(x => x.Id == (model.RoleId)),
                    RoleId     = model.RoleId
                }),
                Total = permissionRecords.Count
            };
            return(View(model));
        }
예제 #2
0
        public ActionResult Index(GridCommand command, ErrorLogModel model)
        {
            if (!PermissionService.Authorize(PermissionProvider.ErrorView))
            {
                return(AccessDeniedView());
            }

            int totalRecords = 0;
            var query        = _unitOfWork.ErrorRepository.GetAsQuerable().OrderByDescending(x => x.CreatedOn);
            var errorLog     = query.ApplyGridCommandsWithPaging(command, out totalRecords);

            var errorList = errorLog.Select(error => new ErrorLogModel
            {
                Id           = error.Id,
                IpAddress    = error.IpAddress,
                PageUrl      = error.PageUrl,
                ShortMessage = error.ShortMessage,
                FullMessage  = error.FullMessage,
                CreatedOn    = error.CreatedOn
            }).ToList();

            var gridModel = new GridModel <ErrorLogModel>
            {
                Data  = errorList,
                Total = totalRecords
            };

            return(View(gridModel));
        }
예제 #3
0
        public async Task Authorize_ReturnTrue()
        {
            Permission permission = new Permission()
            {
                SystemName = "permistion"
            };
            var fakeCustomer = new Customer();

            fakeCustomer.Groups.Add("group1");
            _workContextMock.Setup(c => c.CurrentCustomer).Returns(fakeCustomer);
            _cacheMock.Setup(c => c.GetAsync <bool>(It.IsAny <string>(), It.IsAny <Func <Task <bool> > >())).Returns(Task.FromResult(true));
            _groupServiceMock.Setup(c => c.GetAllByIds(It.IsAny <string[]>())).Returns(Task.FromResult <IList <CustomerGroup> >(new List <CustomerGroup>()
            {
                new CustomerGroup()
            }));
            Assert.IsTrue(await _service.Authorize(permission));
        }
예제 #4
0
        public async Task <IFile> GetSourceFileAsync()
        {
            if (_sourceFileResolved)
            {
                return(_sourceFile);
            }

            if (MediaFileId == 0)
            {
                // This is most likely a request for a default placeholder image
                var fallbackImagePath = Path.Combine(MediaUrlGenerator.FallbackImagesRootPath, RawPath).Replace('\\', '/');
                var fi = new FileInfo(CommonHelper.MapPath("~/" + fallbackImagePath, false));
                if (fi.Exists)
                {
                    _sourceFile = new LocalFile(fallbackImagePath, fi, null);
                }
            }
            else
            {
                // Get file from DB
                var mediaFile = await MediaService.GetFileByIdAsync(MediaFileId, MediaLoadFlags.AsNoTracking);

                // File must exist
                if (mediaFile != null)
                {
                    // Serve deleted or hidden files only with sufficient permission
                    if ((mediaFile.Deleted || mediaFile.Hidden) && !PermissionService.Authorize(Permissions.Media.Update, CurrentCustomer))
                    {
                        return(null);
                    }

                    //// File's mime must match requested mime
                    //if (!mediaFile.MimeType.IsCaseInsensitiveEqual(prevMime ?? pathData.MimeType))
                    //	return null;

                    // File path must match requested path and file title
                    // TODO: (mm) (mc) what about MIME and EXT?
                    if (mediaFile.FolderId != PathData.Folder?.Id || !mediaFile.NameWithoutExtension.EqualsNoCase(PathData.FileTitle))
                    {
                        _sourceFileResolved = true;
                        return(null);
                    }
                }

                _sourceFile = mediaFile;
            }

            _sourceFileResolved = true;
            return(_sourceFile);
        }
예제 #5
0
        public ActionResult Index(GridCommand command, UserModel model)
        {
            if (!PermissionService.Authorize(PermissionProvider.ManageUsers))
            {
                return(AccessDeniedView());
            }

            int totalRecords = 0;
            var query        = _unitOfWork.UserRepository.GetAsQuerable(x => !x.Deleted).OrderByDescending(x => x.CreatedOn);

            var users = query.ApplyGridCommandsWithPaging(command, out totalRecords);

            var modelList = new List <UserModel>();

            foreach (var user in users)
            {
                var newUser = new UserModel
                {
                    Id        = user.Id,
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    UserName  = user.Username,
                    Email     = user.Email,
                    Role      = user.Role.Name,
                    Active    = user.Active
                };
                var temp = _unitOfWork.UserRepository.GetById(user.CreatedByUserId);
                if (temp != null)
                {
                    newUser.CreatedBy = temp.FirstName + " " + temp.LastName;
                }
                newUser.CreatedOn = user.CreatedOn.ToString("MM/dd/yyyy");
                modelList.Add(newUser);
            }

            var gridModel = new GridModel <UserModel>
            {
                Data  = modelList,
                Total = totalRecords
            };

            return(View(gridModel));
        }
        public ActionResult Index(GridCommand command, PermissionRecordModel model)
        {
            if (!PermissionService.Authorize(PermissionProvider.ManagePermissions))
            {
                return(AccessDeniedView());
            }

            try
            {
                var roles = _unitOfWork.RoleRepository.Get();
                ViewBag.Roles = roles;
                var permissionRecords = _unitOfWork.PermissionRecordRepository.Get();
                List <PermissionRecordModel> listPermissions = new List <PermissionRecordModel>();
                foreach (var item in permissionRecords)
                {
                    PermissionRecordModel newItem = new PermissionRecordModel();
                    newItem.Id         = item.Id;
                    newItem.Name       = item.Name;
                    newItem.SystemName = item.SystemName;
                    newItem.Category   = item.Category;
                    newItem.Allow      = item.Roles.Any(x => x.Id == (model.RoleId));
                    newItem.RoleId     = model.RoleId;
                    listPermissions.Add(newItem);
                }

                return(View(new GridModel <PermissionRecordModel>()
                {
                    Data = listPermissions, Total = permissionRecords.Count
                }));
            }
            catch (Exception exception)
            {
                Logger.LogException(exception);
                return(new JsonResult()
                {
                    Data = new PermissionRecordModel().PermissionRecord
                });
            }
        }
        public ActionResult Index(GridCommand command, UserModel model)
        {
            if (!PermissionService.Authorize(PermissionProvider.ManageRoles))
            {
                return(AccessDeniedView());
            }

            int totalRecords = 0;
            var query        = _unitOfWork.RoleRepository.GetAsQuerable(x => !x.Deleted).OrderByDescending(x => x.CreatedOn);
            var roles        = query.ApplyGridCommandsWithPaging(command, out totalRecords);

            List <RoleModel> modelList = new List <RoleModel>();

            foreach (var role in roles)
            {
                RoleModel newRole = new RoleModel();
                newRole.Id          = role.Id;
                newRole.Name        = role.Name;
                newRole.Description = role.Description;
                newRole.Active      = role.Active;
                newRole.CreatedOn   = role.CreatedOn.ToString("MM/dd/yyyy");

                var temp = _unitOfWork.UserRepository.GetById(role.CreatedByUserId);
                if (temp != null)
                {
                    newRole.CreatedBy = temp.FirstName + " " + temp.LastName;
                }

                modelList.Add(newRole);
            }

            var gridModel = new GridModel <RoleModel>
            {
                Data  = modelList,
                Total = totalRecords
            };

            return(View(gridModel));
        }
예제 #8
0
        public ActionResult Index(GridCommand command, UserModel model)
        {
            if (!PermissionService.Authorize(PermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            int totalRecords = 0;
            var query        = _unitOfWork.SettingRepository.GetAsQuerable(x => !x.Deleted).OrderByDescending(x => x.CreatedOn);
            var settings     = query.ApplyGridCommandsWithPaging(command, out totalRecords);

            var listModel = new List <SettingModel>();

            foreach (var topic in settings)
            {
                var setting = new SettingModel
                {
                    Id          = topic.Id,
                    SettingName = topic.SettingName,
                    Value       = topic.Value,
                    Description = topic.Description
                };
                var user1 = _unitOfWork.UserRepository.GetById(topic.CreatedByUserId);
                if (user1 != null)
                {
                    setting.CreatedBy = user1.FirstName;
                }
                listModel.Add(setting);
            }

            var gridModel = new GridModel <SettingModel>
            {
                Data  = listModel,
                Total = totalRecords
            };

            return(View(gridModel));
        }
예제 #9
0
 public bool HasPermission(String permissionName)
 {
     return(PermissionService.Authorize(permissionName));
 }
예제 #10
0
 public bool HasPermission(PermissionRecord permissionRecord)
 {
     return(PermissionService.Authorize(permissionRecord));
 }