-if a user creates an account, he is given admin permissions on that account
-if a user creates a user, he assigns that user trading permissions in one of the accounts he can administer (so he can still see that user, someone else can undo) -bts user has the 'wheel' -bts user can grant other users 'create' permissions, and those users can in turn grant other users create permissions
This commit is contained in:
1 parent
559ab69940
commit
efc490cc0d
7 files changed
+35
-11
No files matched your search
@@ -417,6 +417,7 @@ message AccountCreateAPIArgument{
|
||||
uint32 parent_account_id = 10;
|
||||
string account_name = 20;
|
||||
string description = 30;
|
||||
string creator_user = 40;
|
||||
}
|
||||
message AccountUpdateAPIArgument{
|
||||
BTSAccount complete_data=10;
|
||||
|
||||
@@ -82,6 +82,22 @@ void AdminServiceServer::create_account(
|
||||
request.description(),
|
||||
false,
|
||||
result);
|
||||
if(request.creator_user() != "" && result.new_id() != 0)
|
||||
{
|
||||
const bts::api::admin::BTSUser* user = AdminServiceUtils::find_user(_state, request.creator_user(), false);
|
||||
if(user)
|
||||
{
|
||||
BTSUser update(*user);
|
||||
UserAccountPermissionUnit unit(UserAccountPermissionUnit::default_instance());
|
||||
unit.mutable_admin_permission()->set_has_permissions(true);
|
||||
unit.mutable_admin_permission()->set_has_md_permissions(true);
|
||||
|
||||
google::protobuf::MapPair<uint32_t,UserAccountPermissionUnit> v(result.new_id(), unit);
|
||||
update.mutable_user_data()->mutable_account_permissions()->mutable_account_permissions()->insert(v);
|
||||
AdminServiceOperationResult res;
|
||||
AdminServiceUtils::update_user(_state, update, res);
|
||||
}
|
||||
}
|
||||
_update_and_publish(false);
|
||||
reply(result);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ open bts.api
|
||||
open Elmish
|
||||
open bts.api.orderman
|
||||
|
||||
let superuser = "bts"
|
||||
|
||||
let getAdminData (admin:IAdminService) (token) (fsuc) (ffail) =
|
||||
Cmd.ofPromise
|
||||
admin.get_filtered_admin_data { token = token }
|
||||
|
||||
@@ -37,6 +37,7 @@ let init (context:ServiceContext.ServiceContext) =
|
||||
this_username = context.username
|
||||
}, Access.getAdminData admin context.token UpdateAdminData NoAdminData
|
||||
|
||||
|
||||
let existingSelection (scratch:BTSAccount) (previousScratch:BTSAccount) (data:AdminData) =
|
||||
List.choose id [
|
||||
data.accounts |> Array.tryFind (fun a -> a.id = scratch.id || (scratch.id = 0u && a.name = scratch.name))
|
||||
@@ -82,7 +83,7 @@ let saveAccount (admin:IAdminService) (account:BTSAccount) (model:Model) = promi
|
||||
}
|
||||
|
||||
let createAccount (admin:IAdminService) (account:BTSAccount) (model:Model) = promise {
|
||||
let args = { parentAccountId = 0u; accountName = account.name; description = account.description }
|
||||
let args = { parentAccountId = 0u; accountName = account.name; description = account.description; creatorUser = model.this_username }
|
||||
let! result = admin.create_account args
|
||||
if result.isSuccess then
|
||||
return! saveAccount admin { account with id = result.newId } model
|
||||
|
||||
@@ -116,6 +116,7 @@ let init (context:ServiceContext.ServiceContext) : Model * Cmd<Msg> =
|
||||
ConfirmModal = "", (Msg.SwitchTab Tab.General)
|
||||
token = context.token
|
||||
can_create = context.can_create
|
||||
this_username = context.username
|
||||
}, getAdminData admin context.token
|
||||
|
||||
let rec removeUser (user:BTSUser) (userList:BTSUser list) =
|
||||
|
||||
@@ -62,6 +62,7 @@ type Model = {
|
||||
ConfirmModal: string * Msg
|
||||
token: string
|
||||
can_create: bool
|
||||
this_username: string
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ let generalTabView (model:Model) (dispatch:Msg->Unit) (readonly: bool)=
|
||||
|> List.filter (fun a -> a.isPresent)
|
||||
|> List.map (fun a -> a.id.ToString(), a.name)
|
||||
|> Map.ofList
|
||||
|
||||
|
||||
let can_create = model.can_create || model.this_username = Access.superuser
|
||||
let modal = Modal.showCreate
|
||||
"Create User"
|
||||
(div [][
|
||||
@@ -62,7 +63,7 @@ let generalTabView (model:Model) (dispatch:Msg->Unit) (readonly: bool)=
|
||||
Fields.text "Full Name" model.scratchUser.fullName [] (FullName >> UpdateField >> dispatch)
|
||||
Fields.text "Company" model.scratchUser.company [] (Company >> UpdateField >> dispatch)
|
||||
Fields.checkbox "Can Login and Trade?" "Unchecking this stops the user from logging in and entering orders" model.scratchUser.isActive [] (IsActive >> UpdateField >> dispatch)
|
||||
Fields.checkbox "Can Create?" "Checking this allows the user to create other users and accounts" model.scratchUser.canCreate [] (CanCreate >> UpdateField >> dispatch)
|
||||
Fields.checkbox "Can Create?" "Checking this allows the user to create other users and accounts" model.scratchUser.canCreate [Disabled (not can_create)] (CanCreate >> UpdateField >> dispatch)
|
||||
Fields.mapSelect "Trading Account" accMap (Some "Add Accounts") None ( fun x-> (x,true) |> TradingPerm |> UpdateField |> dispatch )
|
||||
])
|
||||
(fun _ -> dispatch SaveUser)
|
||||
@@ -75,7 +76,7 @@ let generalTabView (model:Model) (dispatch:Msg->Unit) (readonly: bool)=
|
||||
Fields.text "Full Name" model.scratchUser.fullName [Disabled readonly] (FullName >> UpdateField >> dispatch)
|
||||
Fields.text "Company" model.scratchUser.company [Disabled readonly] (Company >> UpdateField >> dispatch)
|
||||
Fields.checkbox "Can Login and Trade?" "Unchecking this stops the user from logging into Spark and entering orders" model.scratchUser.isActive [Disabled readonly] (IsActive >> UpdateField >> dispatch)
|
||||
Fields.checkbox "Can Create?" "Checking this allows the user to create other users and accounts" model.scratchUser.canCreate [Disabled readonly] (CanCreate >> UpdateField >> dispatch)
|
||||
Fields.checkbox "Can Create?" "Checking this allows the user to create other users and accounts" model.scratchUser.canCreate [Disabled (readonly || not can_create)] (CanCreate >> UpdateField >> dispatch)
|
||||
(if (State.isNewUser model.scratchUser) then modal else span[][])
|
||||
]
|
||||
|
||||
@@ -117,7 +118,7 @@ let accountsTabView (model:Model) (dispatch:Msg->Unit) (readonly:bool) =
|
||||
[for acc in realAccList do
|
||||
let string_id = acc.id.ToString()
|
||||
let perm = JSMap.tryFind string_id accountPermissions
|
||||
let is_bts = model.scratchUser.name = "bts"
|
||||
let is_bts = model.scratchUser.name = Access.superuser
|
||||
let hasTradeAdmin = (if perm.IsNone then false else perm.Value.tradingPermission.hasPermissions)
|
||||
let hasRiskAdmin = is_bts || (if perm.IsNone then false else perm.Value.adminPermission.hasPermissions)
|
||||
let hasMdAdmin = is_bts || (if perm.IsNone then false else perm.Value.adminPermission.hasMdPermissions)
|
||||
@@ -229,15 +230,16 @@ let userControls (model:Model) (dispatch:Msg->Unit) =
|
||||
|
||||
let tabContent (model:Model) (dispatch:Msg->Unit) =
|
||||
let adminDisplay = model.scratchUser.userData.exchangeUserData.cmeData.adminDisplayFlag
|
||||
let md_edit = adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.All || adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.MD
|
||||
let risk_edit = adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.All || adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.Routing
|
||||
let is_bts = model.this_username = Access.superuser
|
||||
let md_readonly = if is_bts then false else not (adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.All || adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.MD)
|
||||
let risk_readonly = if is_bts then false else not (adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.All || adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.Routing)
|
||||
div [Key (string model.scratchUser.id); ClassName "is-tab-content"] [
|
||||
(match model.currentTab, ( State.userIsSelected model.scratchUser State.defaultScratchUser) with
|
||||
| _, false -> p [Style [ Color "Red" ]] [ str "Select a User" ]
|
||||
| Tab.General, true -> generalTabView model dispatch (not risk_edit)
|
||||
| Tab.Accounts, true -> accountsTabView model dispatch (not risk_edit)
|
||||
| Tab.MarketData, true -> MarketDataTabView model dispatch (not md_edit)
|
||||
| Tab.OrderRouting, true -> orderRoutingTabView model dispatch (not risk_edit))
|
||||
| Tab.General, true -> generalTabView model dispatch risk_readonly
|
||||
| Tab.Accounts, true -> accountsTabView model dispatch risk_readonly
|
||||
| Tab.MarketData, true -> MarketDataTabView model dispatch md_readonly
|
||||
| Tab.OrderRouting, true -> orderRoutingTabView model dispatch risk_readonly )
|
||||
|
||||
userControls model dispatch
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user