mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
share api
This commit is contained in:
35
src/Api/Models/Request/ShareRequestModel.cs
Normal file
35
src/Api/Models/Request/ShareRequestModel.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Domains;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ShareRequestModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(36)]
|
||||
public string UserId { get; set; }
|
||||
[Required]
|
||||
[StringLength(36)]
|
||||
public string CipherId { get; set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
public Share ToShare(Guid sharerUserId)
|
||||
{
|
||||
return ToShare(new Share
|
||||
{
|
||||
SharerUserId = sharerUserId
|
||||
});
|
||||
}
|
||||
|
||||
public Share ToShare(Share existingShare)
|
||||
{
|
||||
existingShare.UserId = new Guid(UserId);
|
||||
existingShare.CipherId = new Guid(CipherId);
|
||||
existingShare.Key = Key;
|
||||
|
||||
return existingShare;
|
||||
}
|
||||
}
|
||||
}
|
36
src/Api/Models/Response/ShareResponseModel.cs
Normal file
36
src/Api/Models/Response/ShareResponseModel.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ShareResponseModel : ResponseModel
|
||||
{
|
||||
public ShareResponseModel(Share share)
|
||||
: base("share")
|
||||
{
|
||||
if(share == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(share));
|
||||
}
|
||||
|
||||
Id = share.Id.ToString();
|
||||
UserId = share.UserId.ToString();
|
||||
SharerUserId = share.SharerUserId.ToString();
|
||||
CipherId = share.CipherId.ToString();
|
||||
Key = Key;
|
||||
Permissions = share.Permissions == null ? null :
|
||||
JsonConvert.DeserializeObject<IEnumerable<Core.Enums.SharePermissionType>>(share.Permissions);
|
||||
Status = share.Status;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string SharerUserId { get; set; }
|
||||
public string CipherId { get; set; }
|
||||
public string Key { get; set; }
|
||||
public IEnumerable<Core.Enums.SharePermissionType> Permissions { get; set; }
|
||||
public Core.Enums.ShareStatusType? Status { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user