Quota: string representation of quota
This commit is contained in:
parent
ff8cfa3737
commit
933a4129fa
@ -145,7 +145,7 @@ public class LdapObjectExtension
|
||||
var emails = GetContacts(ldapUser, Mapping.AdditionalMail, settings);
|
||||
var skype = GetContacts(ldapUser, Mapping.Skype, settings);
|
||||
|
||||
var quota = settings.LdapMapping.ContainsKey(Mapping.UserQuotaLimit) ? GetAttribute(ldapUser, settings.LdapMapping[Mapping.UserQuotaLimit]) : "1000";
|
||||
var quota = settings.LdapMapping.ContainsKey(Mapping.UserQuotaLimit) ? GetAttribute(ldapUser, settings.LdapMapping[Mapping.UserQuotaLimit]) : "10Mb";
|
||||
|
||||
if (string.IsNullOrEmpty(userName))
|
||||
{
|
||||
@ -170,7 +170,7 @@ public class LdapObjectExtension
|
||||
Location = !string.IsNullOrEmpty(location) ? location : string.Empty,
|
||||
WorkFromDate = _tenantUtil.DateTimeNow(),
|
||||
ContactsList = contacts,
|
||||
QuotaLimit = Int32.Parse(quota)
|
||||
QuotaLimit = quota
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(firstName))
|
||||
|
@ -41,4 +41,40 @@ public static class ByteConverter
|
||||
|
||||
return bytes < MB ? bytes * MB : bytes;
|
||||
}
|
||||
|
||||
public static long ConvertSizeToBytes(string size)
|
||||
{
|
||||
long bytes = 0;
|
||||
var regex = new Regex(@"\d+|\w+");
|
||||
var matches = regex.Matches(size);
|
||||
if (matches.Count > 0)
|
||||
{
|
||||
var num = int.Parse(matches[0].Value);
|
||||
var unit = matches[1].Value.ToLower();
|
||||
switch (unit)
|
||||
{
|
||||
case "bytes":
|
||||
bytes = num;
|
||||
break;
|
||||
case "kb":
|
||||
bytes = num * 1024;
|
||||
break;
|
||||
case "mb":
|
||||
bytes = Convert.ToInt64(num * Math.Pow(1024, 2));
|
||||
break;
|
||||
case "gb":
|
||||
bytes = Convert.ToInt64(num * Math.Pow(1024, 3));
|
||||
break;
|
||||
case "tb":
|
||||
bytes = Convert.ToInt64(num * Math.Pow(1024, 4));
|
||||
break;
|
||||
case "pb":
|
||||
bytes = Convert.ToInt64(num * Math.Pow(1024, 5));
|
||||
break;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public sealed class UserInfo : IDirectRecipient, ICloneable, IMapFrom<User>
|
||||
public string SsoNameId { get; set; } // SSO SAML user identificator
|
||||
public string SsoSessionId { get; set; } // SSO SAML user session identificator
|
||||
public DateTime CreateDate { get; set; }
|
||||
public long QuotaLimit { get; set; }
|
||||
public string QuotaLimit { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ public class User : BaseEntity, IMapFrom<UserInfo>
|
||||
public bool Removed { get; set; }
|
||||
public DateTime CreateDate { get; set; }
|
||||
public DateTime LastModified { get; set; }
|
||||
public long QuotaLimit { get; set; }
|
||||
public string QuotaLimit { get; set; }
|
||||
|
||||
public override object[] GetKeys()
|
||||
{
|
||||
|
@ -413,10 +413,11 @@ internal class FileDao : AbstractDao, IFileDao<int>
|
||||
}
|
||||
|
||||
var user = _userManager.GetUsers(file.Id == default ? _authContext.CurrentAccount.ID : file.CreateBy);
|
||||
var quotaLimit = ByteConverter.ConvertSizeToBytes(user.QuotaLimit);
|
||||
|
||||
if (user.QuotaLimit - await _globalSpace.GetUserUsedSpaceAsync(file.Id == default ? _authContext.CurrentAccount.ID : file.CreateBy) < file.ContentLength)
|
||||
if (quotaLimit - await _globalSpace.GetUserUsedSpaceAsync(file.Id == default ? _authContext.CurrentAccount.ID : file.CreateBy) < file.ContentLength)
|
||||
{
|
||||
throw FileSizeComment.GetPersonalFreeSpaceException(user.QuotaLimit);
|
||||
throw FileSizeComment.GetPersonalFreeSpaceException(quotaLimit);
|
||||
}
|
||||
|
||||
var isNew = false;
|
||||
|
@ -29,5 +29,5 @@ namespace ASC.People.ApiModels.RequestDto;
|
||||
public class UpdateMembersQuotaRequestDto
|
||||
{
|
||||
public IEnumerable<Guid> UserIds { get; set; }
|
||||
public long Quota { get; set; }
|
||||
public string Quota { get; set; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user