private void _comboAdd_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count < 1 || e.AddedItems[0] is string) { return; } // Get the item to add (one of 'em will always be null, eh, what) Oltp.UserRow user = e.AddedItems[0] as Oltp.UserRow; Oltp.UserGroupRow group = e.AddedItems[0] as Oltp.UserGroupRow; // Add default permissions Oltp.AccountPermissionDataTable pTable = new Oltp.AccountPermissionDataTable(); foreach (Type pageClass in Const.DefaultPermissions) { Oltp.AccountPermissionRow pRow = pTable.NewAccountPermissionRow(); pRow.AccountID = Window.CurrentAccount.ID; pRow.TargetID = user != null ? user.ID : group.ID; pRow.TargetIsGroup = user == null; pRow.PermissionType = pageClass.FullName; pRow.Value = true; pTable.Rows.Add(pRow); } // Save the new permissions Window.AsyncOperation(delegate() { using (OltpProxy proxy = new OltpProxy()) { proxy.Service.AccountPermission_Save(pTable); } }, delegate(Exception ex) { MainWindow.MessageBoxError("Failed to add new permissions.", ex); return(false); }, delegate() { //... now update the GUI // Remove from the items of the combobox (user != null ? _usersToAdd : _groupsToAdd) .Remove(user != null ? user as DataRow : group as DataRow); // Insert in the cirrect new index int newIndex = user != null ? _items.Count : GetFirstUserIndex(); _items.Insert( newIndex, user != null ? user as DataRow : group as DataRow ); (sender as ComboBox).SelectedIndex = 0; _listTable.ListView.SelectedIndex = newIndex; }); }
/*=========================*/ #endregion #region Permission targets /*=========================*/ /// <summary> /// /// </summary> private void PermissionTarget_Delete(object sender, RoutedEventArgs e) { // Get the select item ListViewItem item = VisualTree.GetParent <ListViewItem>(sender as DependencyObject); Oltp.UserRow user = item.Content as Oltp.UserRow; Oltp.UserGroupRow group = item.Content as Oltp.UserGroupRow; // Confirm with the user MessageBoxResult result = MessageBox.Show(String.Format("Remove all permissions for {0}?", user == null ? group.Name : user.Name), "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.OK); if (result != MessageBoxResult.OK) { return; } Window.AsyncOperation(delegate() { using (OltpProxy proxy = new OltpProxy()) { proxy.Service.AccountPermission_RemovePermissions( Window.CurrentAccount.ID, user == null ? group.ID : user.ID, user == null); } }, delegate(Exception ex) { MainWindow.MessageBoxError("Failed to remove permissions.", ex); return(false); }, delegate() { _items.Remove(user == null ? group as DataRow : user as DataRow); if (user == null) { _groupsToAdd.Add(group); } else { _usersToAdd.Add(user); } }); }
void SessionStart(string sessionID) { InitProxy(); _currentUser = (Oltp.UserRow)_internalProxy.Service.User_LoginBySessionID(sessionID).Rows[0]; _currentSessionID = sessionID; }
private void radio_Checked(object sender, RoutedEventArgs e) { if (_openingDialog) { return; } // Check which radio button was pressed bool?state = (sender as RadioButton).Name == "radioAllow" ? (bool?)true : (sender as RadioButton).Name == "radioDeny" ? (bool?)false : (bool?)null; // Retrieve the data of the permission being set ListBoxItem lbItem = VisualTree.GetParent <ListBoxItem>(sender as RadioButton); ApiMenuItem x = (ApiMenuItem)lbItem.Content; string permissionValue = x.Path; if (permissionValue == null) { return; } // Retrieve relevant parameters object[] parameters = PermissionTarget_dialog.Content as object[]; Oltp.UserRow user = parameters[0] as Oltp.UserRow; Oltp.UserGroupRow group = parameters[0] as Oltp.UserGroupRow; Oltp.AccountPermissionDataTable permissionsTable = parameters[1] as Oltp.AccountPermissionDataTable; // Get the row with the last value for this permissions Oltp.AccountPermissionRow perm = permissionsTable.FindByAccountIDTargetIDTargetIsGroupPermissionType( Window.CurrentAccount.ID, user == null ? group.ID : user.ID, user == null, permissionValue); if (state == null && perm != null) { // Moving to unset, so if a permission exists, delete it perm.Delete(); } else if (state != null) { if (perm == null) { // Create a new permission target if none exists perm = permissionsTable.NewAccountPermissionRow(); perm.AccountID = Window.CurrentAccount.ID; perm.TargetID = user != null ? user.ID : group.ID; perm.TargetIsGroup = user == null; perm.PermissionType = permissionValue; perm.Value = true; permissionsTable.Rows.Add(perm); } else if (perm.RowState == DataRowState.Deleted) { // If the target was deleted, restore it perm.RejectChanges(); } // Apply the correct value if (state == true) { perm.Value = true; } else { perm.Value = false; } } }
/// <summary> /// Open the dialog /// </summary> private void PermissionTarget_dialog_Open(object sender, RoutedEventArgs e) { // Set dataItem as current item ListViewItem currentItem = _listTable.GetParentListViewItem(e.OriginalSource as FrameworkElement); Oltp.UserRow user = currentItem.Content as Oltp.UserRow; Oltp.UserGroupRow group = currentItem.Content as Oltp.UserGroupRow; // Retrieve applied permissions from the server Oltp.AccountPermissionDataTable permissionsTable = null; Window.AsyncOperation(delegate() { using (OltpProxy proxy = new OltpProxy()) { permissionsTable = proxy.Service.AccountPermission_Get(Window.CurrentAccount.ID, user == null ? group.ID : user.ID, user == null ); } }, delegate(Exception ex) { MainWindow.MessageBoxError("Failed to open permissions.", ex); return(false); }, delegate() { _openingDialog = true; // Apply retrieved permissions to the GUI radio buttons ListBox permissionsList = VisualTree.GetChild <ListBox>(PermissionTarget_dialog); for (int i = 0; i < permissionsList.Items.Count; i++) { ApiMenuItem x = (ApiMenuItem)permissionsList.Items[i]; string permissionValue = x.Path; if (permissionValue == null) { continue; } Oltp.AccountPermissionRow perm = permissionsTable.FindByAccountIDTargetIDTargetIsGroupPermissionType( Window.CurrentAccount.ID, user == null ? group.ID : user.ID, user == null, permissionValue); ListBoxItem lbItem = (ListBoxItem)permissionsList.ItemContainerGenerator.ContainerFromIndex(i); if (perm == null) { VisualTree.GetChild <RadioButton>(lbItem, "radioNotSet").IsChecked = true; } else if (perm.Value) { VisualTree.GetChild <RadioButton>(lbItem, "radioAllow").IsChecked = true; } else { VisualTree.GetChild <RadioButton>(lbItem, "radioDeny").IsChecked = true; } } currentItem.IsSelected = true; // Show the dialog PermissionTarget_dialog.Title = String.Format("Editing permissions for {0}", user == null ? group.Name : user.Name); PermissionTarget_dialog.BeginEdit(new object[] { user == null ? group as DataRow : user as DataRow, permissionsTable }); _openingDialog = false; }); }
public static void SessionStart(int userID) { InitProxy(); _currentUser = (Oltp.UserRow)_internalProxy.Service.User_LoginByID(userID).Rows[0]; }
public static void SessionStart(string email, string password) { InitProxy(); _currentUser = (Oltp.UserRow)_internalProxy.Service.User_LoginByEmail(email, password).Rows[0]; }