private KwsAnpEventStatus HandleKwsCreatedEvent(AnpMsg msg) { KwsCredentials creds = m_kws.CoreData.Credentials; // Add the creator to the user list. KwsUser user = new KwsUser(); user.UserID = msg.Elements[2].UInt32; user.InvitationDate = msg.Elements[1].UInt64; user.AdminName = msg.Elements[3].String; user.EmailAddress = msg.Elements[4].String; user.OrgName = msg.Elements[msg.Minor <= 2 ? 7 : 5].String; user.AdminFlag = true; user.ManagerFlag = true; user.RegisterFlag = true; m_kws.CoreData.UserInfo.UserTree[user.UserID] = user; // Update the workspace data. if (msg.Minor <= 2) { creds.SecureFlag = true; } if (msg.Minor >= 3) { creds.KwsName = msg.Elements[6].String; creds.Flags = msg.Elements[7].UInt32; creds.KwmoAddress = msg.Elements[8].String; } m_kws.StateChangeUpdate(false); return KwsAnpEventStatus.Processed; }
private KwsAnpEventStatus HandleKwsCreatedEvent(AnpMsg msg) { // FIXME store the workspace creation date. KwsUser user = new KwsUser(); user.UserID = msg.Elements[2].UInt32; user.InvitationDate = msg.Elements[1].UInt64; user.AdminName = msg.Elements[3].String; user.EmailAddress = msg.Elements[4].String; user.Power = 1; user.OrgName = msg.Elements[msg.Minor <= 2 ? 7 : 5].String; // Add the creator to the user list. m_kws.CoreData.UserInfo.UserTree[user.UserID] = user; m_kws.CoreData.UserInfo.Creator = user; // FIXME do something better when we look into the user powers. // If we are the creator of this workspace, set our Admin flag. if (m_kws.CoreData.Credentials.UserID == user.UserID) m_kws.CoreData.Credentials.AdminFlag = true; m_kws.StateChangeUpdate(false); return KwsAnpEventStatus.Processed; }
private void FillFields(KwsUser targetUser) { if (targetUser.UserName == "") { lblUserName.Text = targetUser.EmailAddress; } else { lblUserName.Text = targetUser.UiSimpleName; lblUserEmail.Text = targetUser.EmailAddress; } txtUserName.Text = targetUser.HasAdminName() ? targetUser.AdminName : targetUser.UserName; // FIXME adapt for new roles. cboRole.SelectedIndex = targetUser.Power == 0 ? 2 : 0; // FIXME adapt disabled account. }
private KwsAnpEventStatus HandleKwsInvitationEvent(AnpMsg msg) { UInt32 nbUser = msg.Elements[msg.Minor <= 2 ? 2 : 3].UInt32; // This is not supposed to happen, unless in the case of a broken // KWM. Indeed, the server does not enforce any kind of restriction // regarding the number of invitees in an INVITE command. If a KWM // sends such a command with no invitees, the server will fire an // empty INVITE event. if (nbUser < 1) return KwsAnpEventStatus.Processed; List<KwsUser> users = new List<KwsUser>(); // Add the users in the user list. int j = (msg.Minor <= 2) ? 3 : 4; for (int i = 0; i < nbUser; i++) { KwsUser user = new KwsUser(); user.UserID = msg.Elements[j++].UInt32; user.InvitationDate = msg.Elements[1].UInt64; if (msg.Minor >= 3) user.InvitedBy = msg.Elements[2].UInt32; user.AdminName = msg.Elements[j++].String; user.EmailAddress = msg.Elements[j++].String; if (msg.Minor <= 2) j += 2; user.OrgName = msg.Elements[j++].String; users.Add(user); m_kws.CoreData.UserInfo.UserTree[user.UserID] = user; } m_kws.StateChangeUpdate(false); // Never notify new public workspace invitations. They are automatically // generated when a recipient takes an action on the Web page. if (!m_kws.IsPublicKws()) { // Notify the new invitees to the user if it was not him that invited them. // Note: we only have this information from v3 and later. In case of an older // version, notify in all cases. if (msg.Minor >= 3) { if (msg.Elements[2].UInt32 != m_kws.CoreData.Credentials.UserID) m_kws.NotifyUser(new KwsInvitationNotificationItem(m_kws, users)); } else { m_kws.NotifyUser(new KwsInvitationNotificationItem(m_kws, users)); } } return KwsAnpEventStatus.Processed; }
/// <summary> /// Set the field's enabled status. Only the fields that can be /// changed by the user are enabled. /// </summary> private void SetFieldStatus(KwsUser targetUser) { String deniedExpl = ""; Workspace kws = m_uiBroker.Browser.SelectedKws; txtUserName.Enabled = m_uiBroker.CanPerformUserAction(KwsUserAction.SetName, kws, targetUser, ref deniedExpl); txtUserName.Tag = deniedExpl; cboRole.Enabled = m_uiBroker.CanPerformUserAction(KwsUserAction.ChangeManagerFlag, kws, targetUser, ref deniedExpl); cboRole.Tag = deniedExpl; chkLockedAccount.Enabled = m_uiBroker.CanPerformUserAction(KwsUserAction.ChangeLockFlag, kws, targetUser, ref deniedExpl); chkLockedAccount.Tag = deniedExpl; }
/// <summary> /// Fill the content of the various fields. /// </summary> private void FillFields(KwsUser targetUser) { lblUserName.Text = targetUser.UiSimpleName; txtUserName.Text = lblUserName.Text; lblUserEmail.Text = targetUser.EmailAddress; if (targetUser.AdminFlag) cboRole.SelectedIndex = 0; else if (targetUser.ManagerFlag) cboRole.SelectedIndex = 1; else cboRole.SelectedIndex = 2; chkLockedAccount.Checked = targetUser.LockFlag; // Remember the original data so that we can know what was changed. InitialUserName = lblUserName.Text; InitialRole = cboRole.SelectedIndex; m_lastSelectedRole = InitialRole; InitialLockedAccountChecked = chkLockedAccount.Checked; }
private void SetFieldStatus(KwsUser targetUser) { String deniedExpl = ""; txtUserName.Enabled = m_uiBroker.CanPerformUserAction(UserAction.SetName, m_uiBroker.Browser.SelectedKws, targetUser, ref deniedExpl); if (txtUserName.Enabled) txtUserName.Tag = "You can change this user's display name here."; else txtUserName.Tag = deniedExpl; cboRole.Enabled = m_uiBroker.CanPerformUserAction(UserAction.ChangeRole, m_uiBroker.Browser.SelectedKws, targetUser, ref deniedExpl); chkDisabledAccount.Enabled = m_uiBroker.CanPerformUserAction(UserAction.ChangeDisabledAccountFlag, m_uiBroker.Browser.SelectedKws, targetUser, ref deniedExpl); }
//////////////////////////////////// // Complex user request handlers. // //////////////////////////////////// /// <summary> /// Return true if the user is allowed to perform the requested action on /// the given user in the given workspace. If the user is not allowed, false is returned and denyReason /// is set with a user-friendly string. /// </summary> public bool CanPerformUserAction(UserAction action, Workspace kws, KwsUser target, ref String denyReason) { // To perform any action, we must be connected to the workspace. if (!kws.IsOnlineCapable()) { denyReason = "You are not allowed to perform this operation: the " + Base.GetKwsString() + " is not connected."; return false; } switch (action) { case UserAction.ChangeRole: { denyReason = "Feature not available yet."; return false; } case UserAction.Copy: { return true; } case UserAction.Delete: { denyReason = "Feature not available yet."; return false; } case UserAction.ChangeDisabledAccountFlag: { denyReason = "Feature not available yet."; return false; } case UserAction.ShowProperties: { return true; } case UserAction.ResendInvitation: { denyReason = "Feature not available yet."; return false; } case UserAction.ResetPassword: { if (!kws.CoreData.Credentials.SecureFlag) { denyReason = "Feature available in Secure " + Base.GetKwsString() + " only."; return false; } // Everyone can reset his own password. Only admins can set other // people's. if (target.UserID != kws.CoreData.Credentials.UserID && !kws.CoreData.Credentials.AdminFlag) { denyReason = "This functionnality is only available to " + Base.GetKwsString() + " Administrators and Managers."; return false; } return true; } case UserAction.SetName: { denyReason = "Changing the name of a user is not supported yet."; // FIXME adapt for new user powers. if (kws.CoreData.Credentials.AdminFlag) { return false; } // A normal user cannot change his name if he has an // Admin name set. else if (kws.CoreData.Credentials.UserID == target.UserID && target.HasAdminName()) { denyReason = "Your name has been set by an Administrator. Only an Administrator may change it."; } // A normal user cannot change someone else's Admin name. else if (kws.CoreData.Credentials.UserID != target.UserID) { denyReason = "Only Administrators can change someone else's username."; } return false; } default: denyReason = "unknown action"; return false; } }