private void OnAccessClicked(object o, EventArgs args)
 {
     TreeModel tModel;
        iFolderAccessDialog accDialog = null;
        string defaultRights = "ReadWrite";
        string userName = null;
        bool allowOwner = false;
        TreeSelection tSelect = UserTreeView.Selection;
        if(tSelect.CountSelectedRows() == 1)
        {
     Array treePaths = tSelect.GetSelectedRows(out tModel);
     foreach(TreePath tPath in treePaths)
     {
      TreeIter iter;
      if(UserTreeStore.GetIter(out iter, tPath))
      {
       iFolderUser user =
     (iFolderUser) tModel.GetValue(iter, 0);
       if (user.FN != null)
        userName = user.FN;
       else
        userName = user.Name;
       defaultRights = user.Rights;
       if( (ifolder.CurrentUserID == ifolder.OwnerID) &&
        (user.State == "Member") )
        allowOwner = true;
      }
      break;
     }
        }
        accDialog = new iFolderAccessDialog(
     topLevelWindow, userName, defaultRights, allowOwner);
        int rc = accDialog.Run();
        accDialog.Hide();
        if(rc == -5)
        {
     string newrights = accDialog.Rights;
     string oldOwnerID;
     Array treePaths = tSelect.GetSelectedRows(out tModel);
     foreach(TreePath tPath in treePaths)
     {
      TreeIter iter;
      if(UserTreeStore.GetIter(out iter, tPath))
      {
       iFolderUser user =
     (iFolderUser) tModel.GetValue(iter,0);
       try
       {
       ifws.SetUserRights( ifolder.ID,
     user.UserID,
     newrights);
        user.Rights = newrights;
        if(accDialog.IsOwner)
        {
     if( ifws.CanOwnerBeChanged(user.UserID,ifolder.DomainID))
     {
      ifws.ChangeOwner( ifolder.ID,
      user.UserID,
      "Admin");
      oldOwnerID = ifolder.OwnerID;
      user.Rights = "Admin";
      ifolder.Owner = user.Name;
      ifolder.OwnerID = user.UserID;
      TreeIter ownIter;
      if(UserTreeStore.GetIterFirst(out ownIter))
      {
       do
       {
        iFolderUser ownUser = (iFolderUser)
        UserTreeStore.GetValue(ownIter,0);
        if(oldOwnerID == ownUser.UserID)
        {
     ownUser.Rights = "Admin";
     tModel.SetValue(ownIter,
          0, ownUser);
     break;
        }
       }
       while(UserTreeStore.IterNext(ref ownIter));
      }
     }
     else
     {
      iFolderMsgDialog messdialog = new iFolderMsgDialog(
                                      null,
                                      iFolderMsgDialog.DialogType.Error,
                                      iFolderMsgDialog.ButtonSet.Ok,
                                      Util.GS("Policy Violation"),
                                      String.Format(Util.GS("Ownership of the iFolder {0} could not be transferred to {1} as it is violating the limit of iFolders set by the Administrator."),ifolder.Name,user.Name),Util.GS(" "));
                              messdialog.Run();
                              messdialog.Hide();
                              messdialog.Destroy();
     }
        }
        tModel.SetValue(iter, 0, user);
       }
       catch(Exception e)
       {
        iFolderExceptionDialog ied =
      new iFolderExceptionDialog(
        topLevelWindow, e);
        ied.Run();
        ied.Hide();
        ied.Destroy();
        ied = null;
       }
      }
     }
        }
        accDialog.Destroy();
        accDialog = null;
 }
 private void OnAccessClicked(object o, EventArgs args)
 {
     TreeModel tModel;
        iFolderAccessDialog accDialog = null;
        string defaultRights = "ReadWrite";
        string userName = null;
        bool allowOwner = false;
        TreeSelection tSelect = UserTreeView.Selection;
        if(tSelect.CountSelectedRows() == 1)
        {
     Array treePaths = tSelect.GetSelectedRows(out tModel);
     foreach(TreePath tPath in treePaths)
     {
      TreeIter iter;
      if(UserTreeStore.GetIter(out iter, tPath))
      {
       iFolderUser user =
     (iFolderUser) tModel.GetValue(iter, 0);
       if (user.FN != null)
        userName = user.FN;
       else
        userName = user.Name;
       defaultRights = user.Rights;
       if( (ifolder.CurrentUserID == ifolder.OwnerID) &&
        (user.State == "Member") )
        allowOwner = true;
      }
      break;
     }
        }
        accDialog = new iFolderAccessDialog(
     topLevelWindow, userName, defaultRights, allowOwner);
        int rc = accDialog.Run();
        accDialog.Hide();
        if(rc == -5)
        {
     string newrights = accDialog.Rights;
     string oldOwnerID;
     Array treePaths = tSelect.GetSelectedRows(out tModel);
     foreach(TreePath tPath in treePaths)
     {
      TreeIter iter;
      if(UserTreeStore.GetIter(out iter, tPath))
      {
       iFolderUser user =
     (iFolderUser) tModel.GetValue(iter,0);
       try
       {
       ifws.SetUserRights( ifolder.ID,
     user.UserID,
     newrights);
        user.Rights = newrights;
        if(accDialog.IsOwner)
        {
     ifws.ChangeOwner( ifolder.ID,
      user.UserID,
      "Admin");
     oldOwnerID = ifolder.OwnerID;
     user.Rights = "Admin";
     ifolder.Owner = user.Name;
     ifolder.OwnerID = user.UserID;
     TreeIter ownIter;
     if(UserTreeStore.GetIterFirst(out ownIter))
     {
      do
      {
       iFolderUser ownUser = (iFolderUser)
        UserTreeStore.GetValue(ownIter,0);
       if(oldOwnerID == ownUser.UserID)
       {
        ownUser.Rights = "Admin";
        tModel.SetValue(ownIter,
         0, ownUser);
        break;
       }
      }
      while(UserTreeStore.IterNext(ref ownIter));
     }
        }
        tModel.SetValue(iter, 0, user);
       }
       catch(Exception e)
       {
        iFolderExceptionDialog ied =
      new iFolderExceptionDialog(
        topLevelWindow, e);
        ied.Run();
        ied.Hide();
        ied.Destroy();
        ied = null;
       }
      }
     }
        }
        accDialog.Destroy();
        accDialog = null;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Event handler for Access Clicked
        /// </summary>
        private void OnAccessClicked(object o, EventArgs args)
        {
            TreeModel           tModel;
            iFolderAccessDialog accDialog = null;
            string defaultRights          = "ReadWrite";
            string userName   = null;
            bool   allowOwner = false;

            TreeSelection tSelect = UserTreeView.Selection;

            // only allow the changing of the owner if the current
            // user is the owner and if the selected users are members
            if (tSelect.CountSelectedRows() == 1)
            {
                Array treePaths = tSelect.GetSelectedRows(out tModel);

                foreach (TreePath tPath in treePaths)
                {
                    TreeIter iter;

                    if (UserTreeStore.GetIter(out iter, tPath))
                    {
                        iFolderUser user =
                            (iFolderUser)tModel.GetValue(iter, 0);
                        if (user.FN != null)
                        {
                            userName = user.FN;
                        }
                        else
                        {
                            userName = user.Name;
                        }
                        defaultRights = user.Rights;

                        if ((ifolder.CurrentUserID == ifolder.OwnerID) &&
                            (user.State == "Member"))
                        {
                            allowOwner = true;
                        }
                    }
                    break;
                }
            }

            accDialog = new iFolderAccessDialog(
                topLevelWindow, userName, defaultRights, allowOwner);

            int rc = accDialog.Run();

            accDialog.Hide();
            if (rc == -5)
            {
                string newrights = accDialog.Rights;
                string oldOwnerID;

                Array treePaths = tSelect.GetSelectedRows(out tModel);

                foreach (TreePath tPath in treePaths)
                {
                    TreeIter iter;

                    if (UserTreeStore.GetIter(out iter, tPath))
                    {
                        iFolderUser user =
                            (iFolderUser)tModel.GetValue(iter, 0);

                        try
                        {
                            ifws.SetUserRights(ifolder.ID,
                                               user.UserID,
                                               newrights);
                            user.Rights = newrights;

                            // if the user selected to make this
                            // use the owner set that right now
                            if (accDialog.IsOwner)
                            {
                                if (ifws.CanOwnerBeChanged(user.UserID, ifolder.DomainID))
                                {
                                    ifws.ChangeOwner(ifolder.ID,
                                                     user.UserID,
                                                     "Admin");

                                    // update the objects here instead of
                                    // re-reading them, that's expensive!
                                    oldOwnerID      = ifolder.OwnerID;
                                    user.Rights     = "Admin";
                                    ifolder.Owner   = user.Name;
                                    ifolder.OwnerID = user.UserID;

                                    // now loop through the users, find
                                    // the current owner, and set him to
                                    // not be the owner any more
                                    TreeIter ownIter;
                                    if (UserTreeStore.GetIterFirst(out ownIter))
                                    {
                                        do
                                        {
                                            iFolderUser ownUser = (iFolderUser)
                                                                  UserTreeStore.GetValue(ownIter, 0);
                                            if (oldOwnerID == ownUser.UserID)
                                            {
                                                ownUser.Rights = "Admin";
                                                tModel.SetValue(ownIter,
                                                                0, ownUser);
                                                break;
                                            }
                                        }while(UserTreeStore.IterNext(ref ownIter));
                                    }
                                }
                                else
                                {
                                    iFolderMsgDialog messdialog = new iFolderMsgDialog(
                                        null,
                                        iFolderMsgDialog.DialogType.Error,
                                        iFolderMsgDialog.ButtonSet.Ok,
                                        Util.GS("Policy Violation"),
                                        String.Format(Util.GS("Ownership of the iFolder {0} could not be transferred to {1} as it is violating the limit of iFolders set by the Administrator."), ifolder.Name, user.Name), Util.GS(" "));
                                    messdialog.Run();
                                    messdialog.Hide();
                                    messdialog.Destroy();
                                }
                            }

                            tModel.SetValue(iter, 0, user);
                        }
                        catch (Exception e)
                        {
                            iFolderExceptionDialog ied =
                                new iFolderExceptionDialog(
                                    topLevelWindow, e);
                            ied.Run();
                            ied.Hide();
                            ied.Destroy();
                            ied = null;
                        }
                    }
                }
            }
            accDialog.Destroy();
            accDialog = null;
        }