public async Task <DavResponse> DeleteCardDavAddressBook() { var currUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); var currentUserEmail = currUser.Email; var cardDavAB = new CardDavAddressbook(); var authorization = cardDavAB.GetSystemAuthorization(); var myUri = HttpContext.Current.Request.GetUrlRewriter(); var requestUrlBook = cardDavAB.GetRadicaleUrl(myUri.ToString(), currentUserEmail, true, true); var tenant = CurrentTenant; var davRequest = new DavRequest() { Url = requestUrlBook, Authorization = authorization, Header = myUri.ToString() }; await RadicaleClient.RemoveAsync(davRequest).ConfigureAwait(false); try { var dbConn = new DbRadicale(); dbConn.RemoveCardDavUser(tenant, currUser.ID.ToString()); return(new DavResponse() { Completed = true, Data = Resource.RadicaleCardDavDeleteMessage }); } catch (Exception ex) { Log.Error("ERROR: " + ex.Message); return(new DavResponse() { Completed = false, Error = ex.Message }); } }
public void DeleteUser(Guid id) { if (IsSystemUser(id)) { return; } SecurityContext.DemandPermissions(Constants.Action_AddRemoveUser); if (id == CoreContext.TenantManager.GetCurrentTenant().OwnerId) { throw new InvalidOperationException("Can not remove tenant owner."); } var delUser = CoreContext.UserManager.GetUsers(id); userService.RemoveUser(CoreContext.TenantManager.GetCurrentTenant().TenantId, id); var tenant = CoreContext.TenantManager.GetCurrentTenant(); try { var curreMail = delUser.Email.ToLower(); var currentAccountPaswd = InstanceCrypto.Encrypt(curreMail); var userAuthorization = curreMail + ":" + currentAccountPaswd; var cardDavAddBook = new CardDavAddressbook(); var rootAuthorization = cardDavAddBook.GetSystemAuthorization(); var myUri = (HttpContext.Current != null) ? HttpContext.Current.Request.GetUrlRewriter().ToString() : (Cache.Get <string>("REWRITE_URL" + tenant.TenantId) != null) ? new Uri(Cache.Get <string>("REWRITE_URL" + tenant.TenantId)).ToString() : tenant.GetTenantDomain(); var davUsersEmails = CoreContext.UserManager.GetDavUserEmails(); var requestUrlBook = cardDavAddBook.GetRadicaleUrl(myUri, delUser.Email.ToLower(), true, true); var addBookCollection = cardDavAddBook.GetCollection(requestUrlBook, userAuthorization, myUri.ToString()).Result; if (addBookCollection.Completed && addBookCollection.StatusCode != 404) { var davbookRequest = new DavRequest() { Url = requestUrlBook, Authorization = rootAuthorization, Header = myUri }; RadicaleClient.RemoveAsync(davbookRequest).ConfigureAwait(false); } foreach (string email in davUsersEmails) { var requestUrlItem = cardDavAddBook.GetRadicaleUrl(myUri.ToString(), email.ToLower(), true, true, itemID: delUser.ID.ToString()); try { var davItemRequest = new DavRequest() { Url = requestUrlItem, Authorization = rootAuthorization, Header = myUri }; RadicaleClient.RemoveAsync(davItemRequest).ConfigureAwait(false); } catch (Exception ex) { LogManager.GetLogger("ASC").Error("ERROR: " + ex.Message); } } } catch (Exception ex) { LogManager.GetLogger("ASC").Error("ERROR: " + ex.Message); } }
public UserInfo SaveUserInfo(UserInfo u, bool isVisitor = false, bool syncCardDav = false) { if (IsSystemUser(u.ID)) { return(systemUsers[u.ID]); } if (u.ID == Guid.Empty) { SecurityContext.DemandPermissions(Constants.Action_AddRemoveUser); } else { SecurityContext.DemandPermissions(new UserSecurityProvider(u.ID), Constants.Action_EditUser); } if (!CoreContext.Configuration.Personal) { if (Constants.MaxEveryoneCount <= GetUsersByGroup(Constants.GroupEveryone.ID).Length) { throw new TenantQuotaException("Maximum number of users exceeded"); } if (u.Status == EmployeeStatus.Active) { if (isVisitor) { var maxUsers = CoreContext.TenantManager.GetTenantQuota(CoreContext.TenantManager.GetCurrentTenant().TenantId).ActiveUsers; if (!CoreContext.Configuration.Standalone && CoreContext.UserManager.GetUsersByGroup(Constants.GroupVisitor.ID).Length > Constants.CoefficientOfVisitors * maxUsers) { throw new TenantQuotaException("Maximum number of visitors exceeded"); } } else { var q = CoreContext.TenantManager.GetTenantQuota(CoreContext.TenantManager.GetCurrentTenant().TenantId); if (q.ActiveUsers < GetUsersByGroup(Constants.GroupUser.ID).Length) { throw new TenantQuotaException(string.Format("Exceeds the maximum active users ({0})", q.ActiveUsers)); } } } } if (u.Status == EmployeeStatus.Terminated && u.ID == CoreContext.TenantManager.GetCurrentTenant().OwnerId) { throw new InvalidOperationException("Can not disable tenant owner."); } var oldUserData = userService.GetUserByUserName(CoreContext.TenantManager.GetCurrentTenant().TenantId, u.UserName); var newUser = userService.SaveUser(CoreContext.TenantManager.GetCurrentTenant().TenantId, u); if (syncCardDav) { var tenant = CoreContext.TenantManager.GetCurrentTenant(); var cardDavAB = new CardDavAddressbook(); var myUri = (HttpContext.Current != null) ? HttpContext.Current.Request.GetUrlRewriter().ToString() : (Cache.Get <string>("REWRITE_URL" + tenant.TenantId) != null) ? new Uri(Cache.Get <string>("REWRITE_URL" + tenant.TenantId)).ToString() : tenant.GetTenantDomain(); var rootAuthorization = cardDavAB.GetSystemAuthorization(); var allUserEmails = CoreContext.UserManager.GetDavUserEmails().ToList(); var cardDavAddBook = new CardDavAddressbook(); if (oldUserData != null && oldUserData.Status != newUser.Status && newUser.Status == EmployeeStatus.Terminated) { var userAuthorization = oldUserData.Email.ToLower() + ":" + InstanceCrypto.Encrypt(oldUserData.Email); var requestUrlBook = cardDavAB.GetRadicaleUrl(myUri, newUser.Email.ToLower(), true, true); var collection = cardDavAB.GetCollection(requestUrlBook, userAuthorization, myUri.ToString()).Result; if (collection.Completed && collection.StatusCode != 404) { cardDavAB.Delete(myUri, newUser.ID, newUser.Email, tenant.TenantId); } foreach (string email in allUserEmails) { var requestUrlItem = cardDavAddBook.GetRadicaleUrl(myUri.ToString(), email.ToLower(), true, true, itemID: newUser.ID.ToString()); try { var davItemRequest = new DavRequest() { Url = requestUrlItem, Authorization = rootAuthorization, Header = myUri }; RadicaleClient.RemoveAsync(davItemRequest).ConfigureAwait(false); } catch (Exception ex) { LogManager.GetLogger("ASC").Error("ERROR: " + ex.Message); } } } else { try { var cardDavUser = new CardDavItem(u.ID, u.FirstName, u.LastName, u.UserName, u.BirthDate, u.Sex, u.Title, u.Email, u.Contacts, u.MobilePhone); try { cardDavAB.UpdateItemForAllAddBooks(allUserEmails, myUri, cardDavUser, CoreContext.TenantManager.GetCurrentTenant().TenantId, oldUserData != null && oldUserData.Email != newUser.Email ? oldUserData.Email : null); } catch (Exception ex) { LogManager.GetLogger("ASC").Error("ERROR: " + ex.Message); } } catch (Exception ex) { LogManager.GetLogger("ASC").Error("ERROR: " + ex.Message); } } } return(newUser); }