Fix eliminazione e cancellazione utenti

This commit is contained in:
Samuele E. Locatelli
2019-03-15 18:15:38 +01:00
parent 4b326ba796
commit 83f0cac52a
3 changed files with 213 additions and 46 deletions
+74 -17
View File
@@ -878,7 +878,15 @@ namespace MConnectSDK
var userList = new UserPayload();
List<UserData> answ = userListMConnect();
// filtro SOLO per stato (improted)
answ = (List<UserData>)answ.Where(X => X.LoginStatus == UserStatus.IMPORTED);
var resFilt = answ.FindAll(X => X.LoginStatus == UserStatus.IMPORTED);
if (resFilt.Count > 0)
{
answ = resFilt;
}
else
{
answ = new List<UserData>();
}
// aggiungo nella risposta...
userList.UserList = answ;
userList.Message = $"{answ.Count} Users Imported Found!";
@@ -888,28 +896,77 @@ namespace MConnectSDK
return _currStatus;
}
/// <summary>
/// Imposta gli users come IMPORTATI
/// </summary>
/// <param name="UserIds"></param>
/// <returns></returns>
public bool setUsersImported(IEnumerable<string> UserIds)
{
bool answ = false;
return answ;
}
/// <summary>
/// Imposta UN SINGOLO utente come importato (<see langword="true"/>) o eliminato(false)
/// </summary>
/// <param name="UserId"></param>
/// </summary>
/// <param name="sender">CHI invia la richeista (x decidere come impostare status), HMI = LOCAL</param>
/// <param name="username"></param>
/// <param name="imported">true=importato / false = cancellato/non + importato</param>
/// <returns></returns>
public bool setUserImported(string UserId, bool imported)
public async Task<Result> setUserImported(SourceType sender, string username, bool imported = true)
{
bool answ = false;
var _currStatus = reqStatus;
await Task.Run(() =>
{
// inizio da watchdog...
setWatchdog();
var userList = new UserPayload();
List<UserData> answ = userListMConnect();
// CERCO utente x settare importato...
if (answ.Exists(x => x.Username == username))
{
// cerco ed aggiorno
var obj = answ.FirstOrDefault(x => x.Username == username);
if (obj != null)
{
// se mi chiede imported --> setto sempre...
if (imported)
{
obj.LoginStatus = UserStatus.IMPORTED;
}
// altrimenti controllo
else
{
// se chiede HMI/LOCAL --> NOT_IMPORTED
if (sender == SourceType.LOCAL)
{
obj.LoginStatus = UserStatus.NOT_IMPORTED;
}
else
{
// SE CHIEDE CLOUD e NON E' importato --> ELIMINO
if (obj.LoginStatus != UserStatus.IMPORTED)
{
// elimino ANCHE da cache pwd (se c'era)
if (userPwdLocalCache.Exists(x => x.user_id == obj.UserId))
{
var tmpData = userPwdLocalCache;
tmpData.RemoveAll(x => x.user_id == obj.UserId);
userPwdLocalCache = tmpData;
}
// elimino...
answ.Remove(obj);
}
// SE CHIEDE CLOUD ed E' importato --> imposto DELETED
else
{
obj.LoginStatus = UserStatus.DELETED;
}
}
return answ;
}
//obj.LoginStatus = imported ? UserStatus.IMPORTED : UserStatus.DELETED;
}
// salvo
userListCache = answ;
}
// aggiungo nella risposta...
userList.UserList = answ;
userList.Message = "User Updated!";
_currStatus.Payload = userList;
reqStatus = _currStatus;
});
return _currStatus;
}
/// <summary>
+50 -11
View File
@@ -62,6 +62,9 @@
this.label6 = new System.Windows.Forms.Label();
this.lblConsole = new System.Windows.Forms.Label();
this.btnGetUserCreatedList = new System.Windows.Forms.Button();
this.btnImportUser = new System.Windows.Forms.Button();
this.btnDeleteUserHMI = new System.Windows.Forms.Button();
this.btnDeleteUserCloud = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
@@ -176,6 +179,9 @@
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.btnDeleteUserCloud);
this.groupBox2.Controls.Add(this.btnDeleteUserHMI);
this.groupBox2.Controls.Add(this.btnImportUser);
this.groupBox2.Controls.Add(this.btnGetUserCreatedList);
this.groupBox2.Controls.Add(this.btnFlush);
this.groupBox2.Controls.Add(this.btnGetClientStatus);
@@ -208,7 +214,7 @@
//
// btnGetClientStatus
//
this.btnGetClientStatus.Location = new System.Drawing.Point(406, 21);
this.btnGetClientStatus.Location = new System.Drawing.Point(384, 21);
this.btnGetClientStatus.Name = "btnGetClientStatus";
this.btnGetClientStatus.Size = new System.Drawing.Size(111, 32);
this.btnGetClientStatus.TabIndex = 24;
@@ -219,7 +225,7 @@
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(908, 45);
this.label10.Location = new System.Drawing.Point(669, 67);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(33, 17);
this.label10.TabIndex = 23;
@@ -227,7 +233,7 @@
//
// txtPwd
//
this.txtPwd.Location = new System.Drawing.Point(960, 42);
this.txtPwd.Location = new System.Drawing.Point(721, 64);
this.txtPwd.Name = "txtPwd";
this.txtPwd.Size = new System.Drawing.Size(100, 22);
this.txtPwd.TabIndex = 22;
@@ -235,7 +241,7 @@
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(908, 16);
this.label9.Location = new System.Drawing.Point(669, 29);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(36, 17);
this.label9.TabIndex = 21;
@@ -243,16 +249,16 @@
//
// txtUser
//
this.txtUser.Location = new System.Drawing.Point(960, 13);
this.txtUser.Location = new System.Drawing.Point(721, 26);
this.txtUser.Name = "txtUser";
this.txtUser.Size = new System.Drawing.Size(100, 22);
this.txtUser.TabIndex = 20;
//
// btnTryUserLogin
//
this.btnTryUserLogin.Location = new System.Drawing.Point(911, 70);
this.btnTryUserLogin.Location = new System.Drawing.Point(839, 21);
this.btnTryUserLogin.Name = "btnTryUserLogin";
this.btnTryUserLogin.Size = new System.Drawing.Size(149, 27);
this.btnTryUserLogin.Size = new System.Drawing.Size(106, 32);
this.btnTryUserLogin.TabIndex = 19;
this.btnTryUserLogin.Text = "tryUserLogin";
this.btnTryUserLogin.UseVisualStyleBackColor = true;
@@ -260,7 +266,7 @@
//
// btnGetUserList
//
this.btnGetUserList.Location = new System.Drawing.Point(541, 21);
this.btnGetUserList.Location = new System.Drawing.Point(519, 21);
this.btnGetUserList.Name = "btnGetUserList";
this.btnGetUserList.Size = new System.Drawing.Size(132, 32);
this.btnGetUserList.TabIndex = 18;
@@ -270,7 +276,7 @@
//
// btnGetOrgCode
//
this.btnGetOrgCode.Location = new System.Drawing.Point(406, 59);
this.btnGetOrgCode.Location = new System.Drawing.Point(384, 59);
this.btnGetOrgCode.Name = "btnGetOrgCode";
this.btnGetOrgCode.Size = new System.Drawing.Size(111, 32);
this.btnGetOrgCode.TabIndex = 17;
@@ -280,7 +286,7 @@
//
// btnTryAuth
//
this.btnTryAuth.Location = new System.Drawing.Point(278, 21);
this.btnTryAuth.Location = new System.Drawing.Point(256, 21);
this.btnTryAuth.Name = "btnTryAuth";
this.btnTryAuth.Size = new System.Drawing.Size(111, 32);
this.btnTryAuth.TabIndex = 16;
@@ -411,7 +417,7 @@
//
// btnGetUserCreatedList
//
this.btnGetUserCreatedList.Location = new System.Drawing.Point(541, 62);
this.btnGetUserCreatedList.Location = new System.Drawing.Point(519, 59);
this.btnGetUserCreatedList.Name = "btnGetUserCreatedList";
this.btnGetUserCreatedList.Size = new System.Drawing.Size(132, 32);
this.btnGetUserCreatedList.TabIndex = 26;
@@ -419,6 +425,36 @@
this.btnGetUserCreatedList.UseVisualStyleBackColor = true;
this.btnGetUserCreatedList.Click += new System.EventHandler(this.btnGetUserCreatedList_Click);
//
// btnImportUser
//
this.btnImportUser.Location = new System.Drawing.Point(839, 59);
this.btnImportUser.Name = "btnImportUser";
this.btnImportUser.Size = new System.Drawing.Size(106, 32);
this.btnImportUser.TabIndex = 27;
this.btnImportUser.Text = "importUser";
this.btnImportUser.UseVisualStyleBackColor = true;
this.btnImportUser.Click += new System.EventHandler(this.btnImportUser_Click);
//
// btnDeleteUserHMI
//
this.btnDeleteUserHMI.Location = new System.Drawing.Point(951, 21);
this.btnDeleteUserHMI.Name = "btnDeleteUserHMI";
this.btnDeleteUserHMI.Size = new System.Drawing.Size(106, 32);
this.btnDeleteUserHMI.TabIndex = 28;
this.btnDeleteUserHMI.Text = "delete HMI";
this.btnDeleteUserHMI.UseVisualStyleBackColor = true;
this.btnDeleteUserHMI.Click += new System.EventHandler(this.btnDeleteUser_Click);
//
// btnDeleteUserCloud
//
this.btnDeleteUserCloud.Location = new System.Drawing.Point(951, 59);
this.btnDeleteUserCloud.Name = "btnDeleteUserCloud";
this.btnDeleteUserCloud.Size = new System.Drawing.Size(106, 32);
this.btnDeleteUserCloud.TabIndex = 29;
this.btnDeleteUserCloud.Text = "delete Cloud";
this.btnDeleteUserCloud.UseVisualStyleBackColor = true;
this.btnDeleteUserCloud.Click += new System.EventHandler(this.btnDeleteUserCloud_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
@@ -479,6 +515,9 @@
private System.Windows.Forms.Button btnGetClientStatus;
private System.Windows.Forms.Button btnFlush;
private System.Windows.Forms.Button btnGetUserCreatedList;
private System.Windows.Forms.Button btnImportUser;
private System.Windows.Forms.Button btnDeleteUserHMI;
private System.Windows.Forms.Button btnDeleteUserCloud;
}
}
+89 -18
View File
@@ -63,6 +63,8 @@ namespace TestClient
btnGetUserList.Enabled = enableBtn;
btnTryUserLogin.Enabled = enableBtn;
btnGetUserCreatedList.Enabled = enableBtn;
btnImportUser.Enabled = enableBtn;
btnDeleteUserHMI.Enabled = enableBtn;
// controllo se visualizzare parametri di testing...
bool showTP = chkTestMode.Checked;
lblTokRet.Visible = showTP;
@@ -354,13 +356,13 @@ namespace TestClient
sb.AppendLine(string.Format("Cognome: {0}", userList[0].Cognome));
sb.AppendLine(string.Format("Nome: {0}", userList[0].Nome));
sb.AppendLine(string.Format("Status: {0}", userList[0].LoginStatus.ToString()));
lblConsole.Text = sb.ToString();
// aggiungo IMG user... se vuota default...
if (userList[0].UserImage == null)
{
userList[0].UserImage = Image.FromFile(@"resources\userImg.png");
}
pictBox.Image = userList[0].UserImage;
lblConsole.Text = sb.ToString();
// refresh!
refreshRequestStatus();
}), "");
@@ -383,21 +385,24 @@ namespace TestClient
sb.AppendLine("--------------------------------------------------");
sb.AppendLine("USERS CREATED FOUND: " + userList.Count.ToString());
sb.AppendLine("--------------------------------------------------");
sb.AppendLine("first user:");
sb.AppendLine(string.Format("user_id: {0}", userList[0].UserId));
sb.AppendLine(string.Format("isAdmin: {0}", userList[0].IsAdmin));
sb.AppendLine(string.Format("UserName: {0}", userList[0].Username));
sb.AppendLine(string.Format("Email: {0}", userList[0].Email));
sb.AppendLine(string.Format("Cognome: {0}", userList[0].Cognome));
sb.AppendLine(string.Format("Nome: {0}", userList[0].Nome));
sb.AppendLine(string.Format("Status: {0}", userList[0].LoginStatus.ToString()));
lblConsole.Text = sb.ToString();
// aggiungo IMG user... se vuota default...
if (userList[0].UserImage == null)
if (userList.Count > 0)
{
userList[0].UserImage = Image.FromFile(@"resources\userImg.png");
sb.AppendLine("first user:");
sb.AppendLine(string.Format("user_id: {0}", userList[0].UserId));
sb.AppendLine(string.Format("isAdmin: {0}", userList[0].IsAdmin));
sb.AppendLine(string.Format("UserName: {0}", userList[0].Username));
sb.AppendLine(string.Format("Email: {0}", userList[0].Email));
sb.AppendLine(string.Format("Cognome: {0}", userList[0].Cognome));
sb.AppendLine(string.Format("Nome: {0}", userList[0].Nome));
sb.AppendLine(string.Format("Status: {0}", userList[0].LoginStatus.ToString()));
// aggiungo IMG user... se vuota default...
if (userList[0].UserImage == null)
{
userList[0].UserImage = Image.FromFile(@"resources\userImg.png");
}
pictBox.Image = userList[0].UserImage;
}
pictBox.Image = userList[0].UserImage;
lblConsole.Text = sb.ToString();
// refresh!
refreshRequestStatus();
}), "");
@@ -415,7 +420,7 @@ namespace TestClient
UserData userData = new UserData();
var userResult = MCC.TryUserLogin(user, pwd);
List<UserData> userList = ((UserPayload)userResult.Result.Payload).UserList;
var currImage = pictBox.Image;
// controllo se ho risultato...)
if (userList.Count == 1)
{
@@ -436,13 +441,12 @@ namespace TestClient
sb.AppendLine(string.Format("Cognome: {0}", userData.Cognome));
sb.AppendLine(string.Format("Nome: {0}", userData.Nome));
sb.AppendLine(string.Format("Status: {0}", userList[0].LoginStatus.ToString()));
lblConsole.Text = sb.ToString();
// aggiungo IMG user... se vuota default...
if (userList[0].UserImage == null)
{
userList[0].UserImage = Image.FromFile(@"resources\userImg.png");
}
pictBox.Image = userList[0].UserImage;
currImage = userList[0].UserImage;
}
else
{
@@ -455,6 +459,7 @@ namespace TestClient
}
synchronizationContext.Post(new SendOrPostCallback(o =>
{
pictBox.Image = currImage;
lblConsole.Text = sb.ToString();
refreshRequestStatus();
}), "");
@@ -629,6 +634,27 @@ namespace TestClient
sb.AppendLine("");
lblConsole.Text = sb.ToString();
}
/// <summary>
/// Username digitato
/// </summary>
protected string username
{
get
{
return txtUser.Text.Trim();
}
}
/// <summary>
/// Password digitata
/// </summary>
protected string passwd
{
get
{
return txtPwd.Text.Trim();
}
}
/// <summary>
/// chiamata x login utente
/// </summary>
@@ -639,7 +665,7 @@ namespace TestClient
// init in modalità Task based...
await Task.Run(() =>
{
var retObj = doUserLogin(txtUser.Text.Trim(), txtPwd.Text.Trim());
var retObj = doUserLogin(username, passwd);
});
// aggiorno log console
@@ -690,5 +716,50 @@ namespace TestClient
sb.AppendLine("");
lblConsole.Text = sb.ToString();
}
private async void btnImportUser_Click(object sender, EventArgs e)
{
await Task.Run(() =>
{
var taskResult = MCC.setUserImported(SourceType.LOCAL, username, true);
// salvo il risultato restituito...
reqStatus = taskResult.Result;
synchronizationContext.Post(new SendOrPostCallback(o =>
{
refreshRequestStatus();
}), "");
});
}
private async void btnDeleteUser_Click(object sender, EventArgs e)
{
await Task.Run(() =>
{
var taskResult = MCC.setUserImported(SourceType.LOCAL, username, false);
// salvo il risultato restituito...
reqStatus = taskResult.Result;
synchronizationContext.Post(new SendOrPostCallback(o =>
{
refreshRequestStatus();
}), "");
});
}
private async void btnDeleteUserCloud_Click(object sender, EventArgs e)
{
await Task.Run(() =>
{
var taskResult = MCC.setUserImported(SourceType.CLOUD, username, false);
// salvo il risultato restituito...
reqStatus = taskResult.Result;
synchronizationContext.Post(new SendOrPostCallback(o =>
{
refreshRequestStatus();
}), "");
});
}
}
}