Commit 43d0bc16 authored by Jason's avatar Jason

1.新增欄位使用者和權限

2.編輯欄位使用者和權限未完成
parent 8c30004c
...@@ -599,7 +599,7 @@ namespace backstage.Controllers ...@@ -599,7 +599,7 @@ namespace backstage.Controllers
var matchingMask = existField.masks.FirstOrDefault(m => m.id == maskId); var matchingMask = existField.masks.FirstOrDefault(m => m.id == maskId);
if (matchingMask != null) if (matchingMask != null)
{ {
string maskText = $"[{matchingMask.id}] - {matchingMask.name} - {matchingMask.setting}"; string maskText = $"[{matchingMask.id}] - {matchingMask.name} - {matchingMask.setting}<br/>";
maskTextList.Add(maskText); maskTextList.Add(maskText);
} }
} }
...@@ -628,25 +628,48 @@ namespace backstage.Controllers ...@@ -628,25 +628,48 @@ namespace backstage.Controllers
/// <returns></returns> /// <returns></returns>
[Authorize(Policy = "AdminOnly")] [Authorize(Policy = "AdminOnly")]
[HttpPost] [HttpPost]
public async Task<ResultModel> AddUsers([FromBody] IFormCollection form) public async Task<ResultModel> AddUsers(IFormCollection form)
{ {
string msg; string msg;
var result = new ResultModel(); var result = new ResultModel();
int merchant_id = Convert.ToInt32( form["merchant_id"]);
if (!form.ContainsKey("allow_decrypt") ||
!form.ContainsKey("allow_new") ||
!form.ContainsKey("allow_update") ||
!form.ContainsKey("allow_del") ||
!form.ContainsKey("allow_masks") ||
!form.ContainsKey("default_mask_id")||
!form.ContainsKey("allow_masks") ||
!form.ContainsKey("vault_id") ||
!form.ContainsKey("field_id") ||
!form.ContainsKey("merchant_id")
)
{
// 至少有一個鍵不存在,處理這種情況
switch (_currentLanguage)
{
case "en":
msg = "All fields are required.";
break;
case "zh":
msg = "所有欄位必填";
break;
default:
msg = "所有欄位必填";
break;
}
result.IsSuccess = false;
result.Message = msg;
return result;
}
int merchant_id = Convert.ToInt32(form["merchant_id"]);
int vault_id = Convert.ToInt32(form["vault_id"]); int vault_id = Convert.ToInt32(form["vault_id"]);
int field_id = Convert.ToInt32(form["field_id"]); int field_id = Convert.ToInt32(form["field_id"]);
int user_id = Convert.ToInt32(form["id"]); int user_id = Convert.ToInt32(form["id"]);
// 構建包含參數的查詢字串
var queryString = new RouteValueDictionary {
{ "Merchant_id", merchant_id },
{ "vault_id", vault_id },
{ "field_id", field_id },
};
// 取得使用者的 "token" Claim 值 // 取得使用者的 "token" Claim 值
string token = User.FindFirstValue("token"); string token = User.FindFirstValue("token");
...@@ -980,34 +1003,49 @@ namespace backstage.Controllers ...@@ -980,34 +1003,49 @@ namespace backstage.Controllers
var FieldsResponse2 = new FieldsResponse(); var FieldsResponse2 = new FieldsResponse();
url = _config["IP"] + "/v2/vault"; url = _config["IP"] + "/v2/vault";
httpMethod = HttpMethod.Post; httpMethod = HttpMethod.Post;
var addUserToField_data = new[] try
{ {
new var x = form["allow_masks"].ToString().Split(',').Select(int.Parse).ToArray();
string numberString = form["allow_masks"].ToString();
int[] allow_masks = Array.ConvertAll(numberString.Split(','), int.Parse);
var addUserToField_data = new[]
{ {
action = "ADD",
id = user_id,
field_id = field_id,
allow_decrypt = "1",
allow_new = "1",
allow_update = "1",
allow_del = "1",
default_mask_id = "1"
}
};
parameters = new Dictionary<string, string>
{
{ "id", vault_id.ToString()}, new
{ "info", "USERS"}, {
{ "Merchant_id", merchant_id.ToString()}, action = "ADD",
{ "data", JsonConvert.SerializeObject(addUserToField_data)}, id = user_id,
field_id = field_id,
allow_decrypt = Convert.ToInt32(form["allow_decrypt"].ToString()),
allow_new = Convert.ToInt32(form["allow_new"].ToString()),
allow_update = Convert.ToInt32(form["allow_update"].ToString()),
allow_del = Convert.ToInt32(form["allow_del"].ToString()),
allow_masks=allow_masks,
default_mask_id = Convert.ToInt32( form["default_mask_id"])
}
}; };
parameters = new Dictionary<string, string>
{
{ "id", vault_id.ToString()},
{ "info", "USERS"},
{ "Merchant_id", merchant_id.ToString()},
{ "data", JsonConvert.SerializeObject(addUserToField_data)},
};
}
catch (Exception e)
{
return result;
}
apiResult = await _callApi.CallAPI(url, parameters, httpMethod); apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
if (apiResult.IsSuccess) if (apiResult.IsSuccess)
{ {
FieldsResponse2 = JsonConvert.DeserializeObject<FieldsResponse>(apiResult.Data.ToString()); var response = JsonConvert.DeserializeObject<Response>(apiResult.Data.ToString());
if (FieldsResponse2.failInfo != null) if (response.r!=0)
{ {
switch (_currentLanguage) switch (_currentLanguage)
{ {
...@@ -1024,7 +1062,7 @@ namespace backstage.Controllers ...@@ -1024,7 +1062,7 @@ namespace backstage.Controllers
} }
result.IsSuccess = false; result.IsSuccess = false;
result.Message = msg + FieldsResponse2.m; result.Message = msg + response.r+","+response.m;
return result; return result;
} }
else else
......
...@@ -120,18 +120,30 @@ ...@@ -120,18 +120,30 @@
<data name="Add User" xml:space="preserve"> <data name="Add User" xml:space="preserve">
<value>新增使用者</value> <value>新增使用者</value>
</data> </data>
<data name="Allow decrypt" xml:space="preserve">
<value>允許解密</value>
</data>
<data name="Allow decryption" xml:space="preserve"> <data name="Allow decryption" xml:space="preserve">
<value>允許解密</value> <value>允許解密</value>
</data> </data>
<data name="Allow delete" xml:space="preserve"> <data name="Allow delete" xml:space="preserve">
<value>允許刪除</value> <value>允許刪除</value>
</data> </data>
<data name="Allow new" xml:space="preserve">
<value>允許新增</value>
</data>
<data name="Allow to add" xml:space="preserve"> <data name="Allow to add" xml:space="preserve">
<value>允許新增</value> <value>允許新增</value>
</data> </data>
<data name="Allow update" xml:space="preserve"> <data name="Allow update" xml:space="preserve">
<value>允許更新</value> <value>允許更新</value>
</data> </data>
<data name="Are you sure you want to remove this user?" xml:space="preserve">
<value>確認移除使用者?</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>取消</value>
</data>
<data name="Choose department" xml:space="preserve"> <data name="Choose department" xml:space="preserve">
<value>選擇部門</value> <value>選擇部門</value>
</data> </data>
...@@ -153,6 +165,9 @@ ...@@ -153,6 +165,9 @@
<data name="Data Token Vault" xml:space="preserve"> <data name="Data Token Vault" xml:space="preserve">
<value>資料代碼保險庫</value> <value>資料代碼保險庫</value>
</data> </data>
<data name="Default mask" xml:space="preserve">
<value>預設遮罩</value>
</data>
<data name="Default Mask ID" xml:space="preserve"> <data name="Default Mask ID" xml:space="preserve">
<value>預設遮罩ID</value> <value>預設遮罩ID</value>
</data> </data>
...@@ -162,6 +177,9 @@ ...@@ -162,6 +177,9 @@
<data name="Description" xml:space="preserve"> <data name="Description" xml:space="preserve">
<value>描述</value> <value>描述</value>
</data> </data>
<data name="Edit user" xml:space="preserve">
<value>編輯使用者</value>
</data>
<data name="Enable" xml:space="preserve"> <data name="Enable" xml:space="preserve">
<value>啟用</value> <value>啟用</value>
</data> </data>
...@@ -180,13 +198,25 @@ ...@@ -180,13 +198,25 @@
<data name="Name" xml:space="preserve"> <data name="Name" xml:space="preserve">
<value>名稱</value> <value>名稱</value>
</data> </data>
<data name="No" xml:space="preserve">
<value></value>
</data>
<data name="Number of codes" xml:space="preserve"> <data name="Number of codes" xml:space="preserve">
<value>代碼數量</value> <value>代碼數量</value>
</data> </data>
<data name="Number of users" xml:space="preserve"> <data name="Number of users" xml:space="preserve">
<value>使用者數量</value> <value>使用者數量</value>
</data> </data>
<data name="Remove User" xml:space="preserve"> <data name="Please select default mask(Single option)." xml:space="preserve">
<value>請選預設遮罩(單選)</value>
</data>
<data name="Please select mask(multiple options)." xml:space="preserve">
<value>請選遮罩(複選)</value>
</data>
<data name="Please select user(Single option)." xml:space="preserve">
<value>請選使用者名稱(單選)</value>
</data>
<data name="Remove user" xml:space="preserve">
<value>移除使用者</value> <value>移除使用者</value>
</data> </data>
<data name="Revise" xml:space="preserve"> <data name="Revise" xml:space="preserve">
...@@ -219,4 +249,7 @@ ...@@ -219,4 +249,7 @@
<data name="Vault" xml:space="preserve"> <data name="Vault" xml:space="preserve">
<value>保險庫</value> <value>保險庫</value>
</data> </data>
<data name="Yes" xml:space="preserve">
<value></value>
</data>
</root> </root>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment