public MailOperationStatus RemoveDomain(int id) { if (!IsAdmin) { throw new SecurityException("Need admin privileges."); } if (id < 0) { throw new ArgumentException(@"Invalid domain id.", "id"); } var domain = GetDomain(id); if (domain.IsSharedDomain) { throw new SecurityException("Can not remove shared domain."); } var tenant = CoreContext.TenantManager.GetCurrentTenant(); var user = SecurityContext.CurrentAccount; var operationEngine = new OperationEngine(); var operations = operationEngine.MailOperations.GetTasks() .Where(o => { var oTenant = o.GetProperty <int>(MailOperation.TENANT); var oUser = o.GetProperty <string>(MailOperation.OWNER); var oType = o.GetProperty <MailOperationType>(MailOperation.OPERATION_TYPE); return(oTenant == tenant.TenantId && oUser == user.ID.ToString() && oType == MailOperationType.RemoveDomain); }) .ToList(); var sameOperation = operations.FirstOrDefault(o => { var oSource = o.GetProperty <string>(MailOperation.SOURCE); return(oSource == domain.Id.ToString()); }); if (sameOperation != null) { return(operationEngine.GetMailOperationStatus(sameOperation.Id)); } var runningOperation = operations.FirstOrDefault(o => o.Status <= DistributedTaskStatus.Running); if (runningOperation != null) { throw new MailOperationAlreadyRunningException("Remove mailbox operation already running."); } var op = new MailRemoveMailserverDomainOperation(tenant, user, domain); return(operationEngine.QueueTask(op)); }
public MailOperationStatus RemoveMailbox(int id) { if (id < 0) { throw new ArgumentException(@"Invalid server mailbox id.", "id"); } var engine = new EngineFactory(Tenant); var mailbox = engine.MailboxEngine.GetMailboxData(new ConcreteTenantServerMailboxExp(id, Tenant, false)); if (mailbox == null) { throw new ItemNotFoundException("Mailbox not found."); } var isSharedDomain = mailbox.TenantId == Defines.SHARED_TENANT_ID; if (!IsAdmin && !isSharedDomain) { throw new SecurityException("Need admin privileges."); } if (isSharedDomain && !IsAdmin && !mailbox.UserId.Equals(SecurityContext.CurrentAccount.ID.ToString(), StringComparison.InvariantCultureIgnoreCase)) { throw new SecurityException( "Removing of a shared mailbox is allowed only for the current account if user is not admin."); } var tenant = CoreContext.TenantManager.GetCurrentTenant(); var user = SecurityContext.CurrentAccount; var operationEngine = new OperationEngine(); var operations = operationEngine.MailOperations.GetTasks() .Where(o => { var oTenant = o.GetProperty <int>(MailOperation.TENANT); var oUser = o.GetProperty <string>(MailOperation.OWNER); var oType = o.GetProperty <MailOperationType>(MailOperation.OPERATION_TYPE); return(oTenant == tenant.TenantId && oUser == user.ID.ToString() && oType == MailOperationType.RemoveMailbox); }) .ToList(); var sameOperation = operations.FirstOrDefault(o => { var oSource = o.GetProperty <string>(MailOperation.SOURCE); return(oSource == mailbox.MailBoxId.ToString()); }); if (sameOperation != null) { return(operationEngine.GetMailOperationStatus(sameOperation.Id)); } var runningOperation = operations.FirstOrDefault(o => o.Status <= DistributedTaskStatus.Running); if (runningOperation != null) { throw new MailOperationAlreadyRunningException("Remove mailbox operation already running."); } var op = new MailRemoveMailserverMailboxOperation(tenant, user, mailbox); return(operationEngine.QueueTask(op)); }