public InspectionResult Inspect(Core.Services.tmp.EntityOperation operation) { if (operation.IsEntity(EntityConsts.BibliographicListQuery) && _securityService.HasModulePermission(_securityService.CurrentUser, BiblListModule.Id, Permissions.Use)) { if (_securityService.CurrentUser.UserType == UserTypes.Librarian) { return(InspectionResult.Allow); } else if (operation is EntityUpdate) { var update = operation as EntityUpdate; if (update.IsCreate()) { return(InspectionResult.Allow); } else if (update.IsEntity(EntityConsts.BibliographicListQuery)) { var q = new EntityQuery2(User.ENTITY, _securityService.CurrentUser.Id); q.WhereRelated(new RelationQuery(EntityConsts.BibliographicListQuery, Roles.Customer, update.Id.Value)); if (_repository.Read(q) != null) { return(InspectionResult.Allow); } } } } return(InspectionResult.None); }
public void Before(Core.Services.tmp.EntityOperation operation, EntityOperationContext context) { if (operation.IsEntity(EntityConsts.BibliographicQuery)) { if (operation is EntityUpdate) { var update = operation as EntityUpdate; if (update.IsCreate() && _securityService.CurrentUser.UserType == UserTypes.Customer) { update.Attach(User.ENTITY, Roles.Customer, _securityService.CurrentUser.Id); } else if (_securityService.CurrentUser.UserType == UserTypes.Librarian) { bool attach = false; if (update.IsCreate()) { attach = true; } else { var q = new EntityQuery2(User.ENTITY); q.WhereRelated(new RelationQuery(EntityConsts.BibliographicQuery, Roles.ProcessedBy, update.Id.Value)); var user = _repository.Read(q); if (user == null) { attach = true; } else if (user.Id != _securityService.CurrentUser.Id) { update.Detach(User.ENTITY, Roles.ProcessedBy, user.Id); attach = true; } } if (attach) { update.Attach(User.ENTITY, Roles.ProcessedBy, _securityService.CurrentUser.Id); } } } } }