/// <summary> /// Modifica dei dati di un utente in amministrazione /// </summary> /// <param name="utente"></param> /// <returns></returns> public EsitoOperazione ModificaUtente(OrgUtente utente) { EsitoOperazione ret = new EsitoOperazione(); string logMsg = string.Empty; IObjectService objSrvc = null; IQueryService qrySvc = null; string repositoryName = DctmConfigurations.GetRepositoryName(); bool wasSysAdmin = false; bool isSysAdmin = false; string gruppoSysAdm; string codiceAmm; // test sui campi obbligatori if (string.IsNullOrEmpty(utente.Codice) || string.IsNullOrEmpty(utente.Email) || string.IsNullOrEmpty(utente.IDPeople) || string.IsNullOrEmpty(utente.UserId)) { logMsg = ERR_HEADER + "ModificaUtente: dati insufficienti"; ret.Codice = -1; ret.Descrizione = logMsg; logger.Debug(logMsg); return(ret); } try { objSrvc = this.GetObjectServiceInstance(); qrySvc = this.GetQueryServiceInstance(); ObjectIdentity userIdentity = Dfs4DocsPa.getUserIdentityByName(TypeUtente.getUserName(utente)); // non è possibile cambiare il nome di un utente List <string> filters = new List <string>(); filters.Add("user_name"); DataObject oldData = DfsHelper.getAllPropsAndFolders(objSrvc, userIdentity, filters, false); Property oldName = oldData.Properties.Get("user_name"); if (oldName == null) { ret.Codice = -1; logMsg = ERR_HEADER + "ModificaUtente: impossibile leggere il vecchio nome dell'utente"; ret.Descrizione = logMsg; logger.Debug(logMsg); return(ret); } if (!oldName.GetValueAsString().Equals(utente.UserId, StringComparison.OrdinalIgnoreCase)) { ret.Codice = -1; logMsg = ERR_HEADER + "ModificaUtente: non è possibile modificare il nome dell'utente"; ret.Descrizione = logMsg; logger.Debug(logMsg); return(ret); } // dobbiamo capire se prima dell'update era sysAdmin oppure no codiceAmm = DocsPaQueryHelper.getCodiceAmministrazione(utente.IDAmministrazione); gruppoSysAdm = TypeGruppo.GetGroupNameForSysAdminAmministrazione(codiceAmm); wasSysAdmin = DfsHelper.isUserMemberOf(TypeUtente.getUserName(utente), gruppoSysAdm, qrySvc); isSysAdmin = (utente.Amministratore != null && utente.Amministratore != "0"); // verifico se sia stata modificata la password o meno // if (!string.IsNullOrEmpty(utente.Password)) // { // eliminato controllo su presenza password, gli altri dati dell'utente devono essere modificati // anche senza un cambio password (speriamo almeno..) Necessario per replicare stato attivazione rispetto a docspa. // il campo password non viene passato se non è valorizzato DataObject userData = new DataObject(userIdentity, ObjectTypes.UTENTE); // Reperimento properties utente userData.Properties.Properties.AddRange(Dfs4DocsPa.getUserProperties(utente)); DataPackage pkg = new DataPackage(userData); pkg = objSrvc.Update(pkg, null); if (pkg.DataObjects.Count > 0) { // eventuale inserimento nel gruppo dei syadmin if (isSysAdmin && !wasSysAdmin) { DfsHelper.insertUserInGroup(TypeUtente.getUserName(utente), gruppoSysAdm, qrySvc); } else if (wasSysAdmin && !isSysAdmin) { DfsHelper.removeUserFromGroup(TypeUtente.getUserName(utente), gruppoSysAdm, qrySvc); } ret.Codice = 0; ret.Descrizione = string.Empty; logger.Debug(DEBUG_HEADER + "ModificaUtente completata con SUCCESSO"); } else { throw new ApplicationException(); } /** } * else * { * ret.Codice = 0; * ret.Descrizione = string.Empty; * * logger.Debug(DEBUG_HEADER + "ModificaUtente completata con SUCCESSO"); * } */ return(ret); } catch (Exception ex) { String st = ex.ToString(); logger.Error(DEBUG_HEADER + "ModificaUtente FALLITA, Exception=" + st); ret.Codice = -1; ret.Descrizione = ERR_HEADER + "ModificaUtente"; return(ret); } }
/// <summary> /// Inserimento di un nuovo utente in amministrazione /// </summary> /// <param name="utente"></param> /// <returns></returns> public EsitoOperazione InserisciUtente(OrgUtente utente) { EsitoOperazione retValue = new EsitoOperazione(); string logMsg = string.Empty; bool userCreated = false; bool pathCreated = false; // test sui campi obbligatori if (string.IsNullOrEmpty(utente.Codice) || string.IsNullOrEmpty(utente.Email) || string.IsNullOrEmpty(utente.IDPeople) || string.IsNullOrEmpty(utente.UserId)) { retValue.Codice = -1; retValue.Descrizione = ERR_HEADER + "InserisciUtente: dati insufficienti"; logger.Debug(retValue.Descrizione); } else { try { IObjectService objSrvc = this.GetObjectServiceInstance(); string repo = DctmConfigurations.GetRepositoryName(); string homePath = string.Concat("/", TypeUtente.getHomeFolderName(utente.UserId)); ObjectIdentity identityHomeCabinet = objSrvc.CreatePath(new ObjectPath(homePath), repo); pathCreated = true; ObjectIdentity userIdentity = new ObjectIdentity(repo); DataObject userData = new DataObject(userIdentity, ObjectTypes.UTENTE); // Reperimento properties utente userData.Properties.Properties.AddRange(Dfs4DocsPa.getUserProperties(utente)); userData.Properties.Set <string>("default_folder", homePath); DataPackage dataPackage = new DataPackage(userData); dataPackage = objSrvc.Create(dataPackage, null); if (dataPackage.DataObjects.Count > 0) { userCreated = true; // Impotazione proprietà "is_private = 1", per fare in modo // che il cabinet sia visibile solamente all'utente che l'ha creato // e 'owner_name' con il nome dell'utente DataObject homeCabinetData = new DataObject(identityHomeCabinet, "dm_cabinet"); //homeCabinetData.Properties.Set<int>("is_private", 1); //Vecchio 6.0 homeCabinetData.Properties.Set <string>("is_private", "1"); homeCabinetData.Properties.Set <string>("owner_name", TypeUtente.getUserName(utente)); dataPackage = new DataPackage(homeCabinetData); dataPackage = objSrvc.Update(dataPackage, null); if (dataPackage.DataObjects.Count > 0) { this.inserisciUtenteInAmministrazione(utente, userData); retValue.Codice = 0; retValue.Descrizione = string.Empty; logger.Debug(DEBUG_HEADER + "InserisciUtente completata con SUCCESSO"); } else { throw new ApplicationException(); } } else { undoCreateHomeFolder(utente); pathCreated = false; throw new ApplicationException(); } } catch (Exception ex) { string errorMessage = string.Format("Errore in {0}: {1}", DEBUG_HEADER, ex.ToString()); logger.Debug(errorMessage); retValue.Codice = -1; retValue.Descrizione = ERR_HEADER + "InserisciUtente"; if (pathCreated) { this.undoCreateHomeFolder(utente); } if (userCreated) { this.undoCreateUser(utente); } } } return(retValue); }