public async Task <FolderResponseModel> Get(string id) { var folder = await _cipherRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value); if (folder == null || folder.Type != Core.Enums.CipherType.Folder) { throw new NotFoundException(); } return(new FolderResponseModel(folder)); }
public async Task <CipherResponseModel> Get(string id) { var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value); if (cipher == null) { throw new NotFoundException(); } return(new CipherResponseModel(cipher)); }
public async Task <CipherResponseModel> Get(string id) { var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User))); if (cipher == null) { throw new NotFoundException(); } return(new CipherResponseModel(cipher)); }
public async Task <LoginResponseModel> Get(string id) { var userId = _userService.GetProperUserId(User).Value; var login = await _cipherRepository.GetByIdAsync(new Guid(id), userId); if (login == null || login.Type != Core.Enums.CipherType.Login) { throw new NotFoundException(); } var response = new LoginResponseModel(login); return(response); }
public async Task <LoginResponseModel> GetAdmin(string id) { var login = await _cipherRepository.GetByIdAsync(new Guid(id)); if (login == null || !login.OrganizationId.HasValue || !_currentContext.OrganizationAdmin(login.OrganizationId.Value)) { throw new NotFoundException(); } var response = new LoginResponseModel(login); return(response); }
public async Task <Cipher> GetByIdAsync(string id) { var data = await _cipherRepository.GetByIdAsync(id); if (data == null || data.UserId != _authService.UserId) { return(null); } var attachments = await _attachmentRepository.GetAllByCipherIdAsync(id); var cipher = new Cipher(data, attachments); return(cipher); }
public async Task <SiteResponseModel> Get(string id, string[] expand = null) { var site = await _cipherRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User))); if (site == null || site.Type != Core.Enums.CipherType.Site) { throw new NotFoundException(); } var response = new SiteResponseModel(site); await ExpandAsync(site, response, expand, null); return(response); }
public async Task <IActionResult> List([FromQuery] EventFilterRequestModel request) { var dateRange = request.ToDateRange(); var result = new PagedResult <IEvent>(); if (request.ActingUserId.HasValue) { result = await _eventRepository.GetManyByOrganizationActingUserAsync( _currentContext.OrganizationId.Value, request.ActingUserId.Value, dateRange.Item1, dateRange.Item2, new PageOptions { ContinuationToken = request.ContinuationToken }); } else if (request.ItemId.HasValue) { var cipher = await _cipherRepository.GetByIdAsync(request.ItemId.Value); if (cipher != null && cipher.OrganizationId == _currentContext.OrganizationId.Value) { result = await _eventRepository.GetManyByCipherAsync( cipher, dateRange.Item1, dateRange.Item2, new PageOptions { ContinuationToken = request.ContinuationToken }); } } else { result = await _eventRepository.GetManyByOrganizationAsync( _currentContext.OrganizationId.Value, dateRange.Item1, dateRange.Item2, new PageOptions { ContinuationToken = request.ContinuationToken }); } var eventResponses = result.Data.Select(e => new EventResponseModel(e)); var response = new ListResponseModel <EventResponseModel>(eventResponses, result.ContinuationToken); return(new JsonResult(response)); }
public async Task <ListResponseModel <EventResponseModel> > GetCipher(string id, [FromQuery] DateTime?start = null, [FromQuery] DateTime?end = null, [FromQuery] string continuationToken = null) { var cipher = await _cipherRepository.GetByIdAsync(new Guid(id)); if (cipher == null) { throw new NotFoundException(); } var canView = false; if (cipher.OrganizationId.HasValue) { canView = await _currentContext.AccessEventLogs(cipher.OrganizationId.Value); } else if (cipher.UserId.HasValue) { var userId = _userService.GetProperUserId(User).Value; canView = userId == cipher.UserId.Value; } if (!canView) { throw new NotFoundException(); } var dateRange = GetDateRange(start, end); var result = await _eventRepository.GetManyByCipherAsync(cipher, dateRange.Item1, dateRange.Item2, new PageOptions { ContinuationToken = continuationToken }); var responses = result.Data.Select(e => new EventResponseModel(e)); return(new ListResponseModel <EventResponseModel>(responses, result.ContinuationToken)); }
public async Task <IActionResult> Post([FromBody] EventModel model) { switch (model.Type) { // User events case EventType.User_LoggedIn: await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type); break; // Cipher events case EventType.Cipher_Created: if (!model.CipherId.HasValue) { return(new BadRequestResult()); } var cipher = await _cipherRepository.GetByIdAsync(model.CipherId.Value, _currentContext.UserId.Value); if (cipher == null) { return(new BadRequestResult()); } await _eventService.LogCipherEventAsync(cipher, model.Type); break; default: return(new BadRequestResult()); } return(new OkResult()); }
public async Task <LoginResponseModel> Put(string id, [FromBody] LoginRequestModel model) { var userId = _userService.GetProperUserId(User).Value; var login = await _cipherRepository.GetByIdAsync(new Guid(id), userId); if (login == null || login.Type != Core.Enums.CipherType.Login) { throw new NotFoundException(); } await _cipherService.SaveAsync(model.ToCipherDetails(login), userId); var response = new LoginResponseModel(login); return(response); }
public async Task PostCipher(Guid id, [FromBody] EventModel model) { var cipher = await _cipherRepository.GetByIdAsync(id, _currentContext.UserId.Value); if (cipher != null) { await _eventService.LogCipherEventAsync(cipher, model.Type); } }
public async Task <AttachmentResponseData> GetAttachmentDownloadAsync(Guid id, Guid cipherId, string attachmentId, User requestingUser) { var emergencyAccess = await _emergencyAccessRepository.GetByIdAsync(id); if (!IsValidRequest(emergencyAccess, requestingUser, EmergencyAccessType.View)) { throw new BadRequestException("Emergency Access not valid."); } var cipher = await _cipherRepository.GetByIdAsync(cipherId, emergencyAccess.GrantorId); return(await _cipherService.GetAttachmentDownloadDataAsync(cipher, attachmentId)); }
private async Task <bool> LogEventAsync(EventModel model) { switch (model.Type) { // User events case EventType.User_ClientExportedVault: await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type, model.Date); break; // Cipher events case EventType.Cipher_ClientAutofilled: case EventType.Cipher_ClientCopiedHiddenField: case EventType.Cipher_ClientCopiedPassword: case EventType.Cipher_ClientCopiedCardCode: case EventType.Cipher_ClientToggledCardCodeVisible: case EventType.Cipher_ClientToggledHiddenFieldVisible: case EventType.Cipher_ClientToggledPasswordVisible: case EventType.Cipher_ClientViewed: if (!model.CipherId.HasValue) { return(false); } var cipher = await _cipherRepository.GetByIdAsync(model.CipherId.Value, _currentContext.UserId.Value); if (cipher == null) { return(false); } await _eventService.LogCipherEventAsync(cipher, model.Type, model.Date); break; default: return(false); } return(true); }
public async Task <IActionResult> Post([FromBody] EventModel model) { switch (model.Type) { // User events case EventType.User_ExportedVault: await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type); break; // Cipher events case EventType.Cipher_ClientAutofilled: case EventType.Cipher_ClientCopedHiddenField: case EventType.Cipher_ClientCopiedPassword: case EventType.Cipher_ClientToggledHiddenFieldVisible: case EventType.Cipher_ClientToggledPasswordVisible: case EventType.Cipher_ClientViewed: if (!model.CipherId.HasValue) { return(new BadRequestResult()); } var cipher = await _cipherRepository.GetByIdAsync(model.CipherId.Value, _currentContext.UserId.Value); if (cipher == null) { return(new BadRequestResult()); } await _eventService.LogCipherEventAsync(cipher, model.Type); break; default: return(new BadRequestResult()); } return(new OkResult()); }
public async Task <IActionResult> Post([FromBody] IEnumerable <EventModel> model) { if (model == null || !model.Any()) { return(new BadRequestResult()); } var cipherEvents = new List <Tuple <Cipher, EventType, DateTime?> >(); var ciphersCache = new Dictionary <Guid, Cipher>(); foreach (var eventModel in model) { switch (eventModel.Type) { // User events case EventType.User_ClientExportedVault: await _eventService.LogUserEventAsync(_currentContext.UserId.Value, eventModel.Type, eventModel.Date); break; // Cipher events case EventType.Cipher_ClientAutofilled: case EventType.Cipher_ClientCopiedHiddenField: case EventType.Cipher_ClientCopiedPassword: case EventType.Cipher_ClientCopiedCardCode: case EventType.Cipher_ClientToggledCardCodeVisible: case EventType.Cipher_ClientToggledHiddenFieldVisible: case EventType.Cipher_ClientToggledPasswordVisible: case EventType.Cipher_ClientViewed: if (!eventModel.CipherId.HasValue) { continue; } Cipher cipher = null; if (ciphersCache.ContainsKey(eventModel.CipherId.Value)) { cipher = ciphersCache[eventModel.CipherId.Value]; } else { cipher = await _cipherRepository.GetByIdAsync(eventModel.CipherId.Value, _currentContext.UserId.Value); } if (cipher == null) { continue; } if (!ciphersCache.ContainsKey(eventModel.CipherId.Value)) { ciphersCache.Add(eventModel.CipherId.Value, cipher); } cipherEvents.Add(new Tuple <Cipher, EventType, DateTime?>(cipher, eventModel.Type, eventModel.Date)); break; default: continue; } } if (cipherEvents.Any()) { foreach (var eventsBatch in cipherEvents.Batch(50)) { await _eventService.LogCipherEventsAsync(eventsBatch); } } return(new OkResult()); }