Ejemplo n.º 1
0
    protected void ButtonAddOrgRole_Click(object sender, EventArgs e)
    {
        int personId      = (Person.FromIdentity(Convert.ToInt32("" + Request["id"]))).Identity;
        int currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

        RoleType roleType       = (RoleType)Enum.Parse(typeof(RoleType), DropRolesOrg.SelectedValue);
        int      nodeId         = Geography.RootIdentity;
        int      organizationId = Convert.ToInt32(DropOrganizationsOrg.SelectedValue);

        if (!_authority.HasPermission(Permission.CanEditOrganisationalRoles, organizationId, nodeId, Authorization.Flag.Default))
        {
            Page.ClientScript.RegisterStartupScript(typeof(Page), "ErrorMessage",
                                                    "alert ('You do not have permissions to add organisation roles for that organisation.');",
                                                    true);
            return;
        }

        int roleId = PersonRole.Create(personId, roleType, organizationId, nodeId).Identity;

        // If we made it this far, add the role
        Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.AddedRole, currentUserId, organizationId,
                                                    nodeId, personId, (int)roleType, string.Empty);

        this.GridOrgRoles.DataBind();
    }
Ejemplo n.º 2
0
    protected void ButtonAddRole_Click(object sender, EventArgs e)
    {
        int personId      = (Person.FromIdentity(Convert.ToInt32("" + Request["id"]))).Identity;
        int currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

        RoleType roleType       = (RoleType)Enum.Parse(typeof(RoleType), DropRolesLocal.SelectedValue);
        int      nodeId         = Convert.ToInt32(DropGeographies.SelectedValue);
        int      organizationId = Convert.ToInt32(DropOrganizationsLocal.SelectedValue);

        if (!_authority.HasPermission(Permission.CanEditLocalRoles, organizationId, nodeId, Authorization.Flag.Default))
        {
            Page.ClientScript.RegisterStartupScript(typeof(Page), "ErrorMessage",
                                                    "alert ('You do not have permissions to add local roles for that combination of organisation and geography.');",
                                                    true);
            return;
        }

        /* Fix for Ticket #46 */

        // Check if role being added is lead, if so check if lead is already filled, if so return error, else continue
        if (roleType == RoleType.LocalLead)
        {
            List <Person> aggregate = new List <Person>();
            RoleLookup    lead      = RoleLookup.FromGeographyAndOrganization(nodeId, organizationId);
            foreach (PersonRole role in lead[RoleType.LocalLead])
            {
                aggregate.Add(role.Person);
            }

            // If we have one or more people in this role already, throw error (typically it should only be filled by one other person)
            if (aggregate.Count > 0)
            {
                string name = aggregate[0].Name;

                // Handle multiple users with this role
                if (aggregate.Count > 1)
                {
                    name = String.Empty;
                    int count = 0;
                    foreach (Person person in aggregate)
                    {
                        count++;
                        name += person.Name;
                        if (count < aggregate.Count)
                        {
                            name += ", ";
                        }
                    }
                }

                Page.ClientScript.RegisterStartupScript(typeof(Page), "ErrorMessage",
                                                        "alert ('This role is already filled by " + name + ". To assign a new user to this role please remove the old user first.');",
                                                        true);

                return;
            }
        }

        int roleId = PersonRole.Create(personId, roleType, organizationId, nodeId).Identity;

        // If we made it this far, add the role
        Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.AddedRole, currentUserId, organizationId,
                                                    nodeId, personId, (int)roleType, string.Empty);

        this.GridLocalRoles.DataBind();
    }