Exemplo n.º 1
0
        /*
		public static bool ViewerMayWatchPerson (int viewingPersonId, int watchedPersonId)
		{
			Authority authority = GetPersonAuthority(viewingPersonId);

			int[] resultingList = FilterPersonList(new int[] { watchedPersonId }, authority);

			resultingList = FilterUnlistedPeople(resultingList);

			if (resultingList.Length == 0)
			{
				return false;
			}

			return true;
		}*/


        /// <summary>
        /// Checks for authorization for a specific activity.
        /// </summary>
        /// <param name="permissionsNeeded">The permissions to allow or disallow.</param>
        /// <param name="organizationId">The organization the activity is applied to.</param>
        /// <param name="geographyId">The node the activity is applied to, or zero for world.</param>
        /// <param name="checkedPersonId">The person performing the activity (NOT the victim of it).</param>
        /// <returns>True if allowed under current authority.</returns>
        public static bool CheckAuthorization (PermissionSet permissionsNeeded, int organizationId, int geoNodeId, int checkedPersonId, Flag flags)
        {
            return CheckAuthorization(permissionsNeeded, organizationId, geoNodeId, GetPersonAuthority(checkedPersonId), flags);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks for authorization for a specific activity.
        /// </summary>
        /// <param name="permissionsNeeded">The permissions to allow or disallow.</param>
        /// <param name="organizationId">The organization the activity is applied to.</param>
        /// <param name="geographyId">The node the activity is applied to, or zero for world.</param>
        /// <param name="authority">The authority to test against.</param>
        /// <returns>True if allowed under current authority.</returns>
        public static bool CheckAuthorization (PermissionSet permissionsNeeded, int organizationId, int geoNodeId, Authority authority, Flag flags)
        {
            if (permissionsNeeded == null)
                return false;
            Geography currentGeo = null;
            if (geoNodeId > 0)
            {
                try { currentGeo = Geography.FromIdentity(geoNodeId); }
                catch { }
            }

            Organization currentOrg = null;
            if (organizationId > 0)
            {
                try { currentOrg = Organization.FromIdentity(organizationId); }
                catch { }
            }


            foreach (PermissionSet.Item perm in permissionsNeeded)
            {
                int thisFound = 0;
                Geography innerCurrentGeo = null;
                Organization innerCurrentOrg = null;

                if (perm.geographyId > 0)
                {
                    try { innerCurrentGeo = Geography.FromIdentity(perm.geographyId); }
                    catch { }
                }
                else
                    innerCurrentGeo = currentGeo;

                if (perm.orgId > 0)
                {
                    try { innerCurrentOrg = Organization.FromIdentity(perm.orgId); }
                    catch { }
                }
                else
                    innerCurrentOrg = currentOrg;

                RoleType[] rolesForPerm = new RoleType[] { };
                if (PermissonsDict.ContainsKey(perm.perm))
                    rolesForPerm = PermissonsDict[perm.perm];

                if (perm.perm == Permission.CanSeeSelf)
                    thisFound = 1;
                else if (rolesForPerm.Length > 0)
                    thisFound = CheckSpecificValidRoles(authority, rolesForPerm, innerCurrentGeo, innerCurrentOrg, thisFound, flags);


                if (permissionsNeeded.NeedOne && thisFound == 1)
                    return true;
                if (permissionsNeeded.NeedAll && thisFound == -1)
                    return false;

            }

            //If Need all and not already returned, no false one was found
            if (permissionsNeeded.NeedAll)
                return true;
            else

                return false;
        }
Exemplo n.º 3
0
 public PermissionSet (PermissionSet.Item pi)
 {
     permsList.Add(pi);
 }
Exemplo n.º 4
0
 internal Enumerator (PermissionSet p)
 {
     this.parent = p;
     this.Reset();
 }
Exemplo n.º 5
0
 public bool IsAnyInSet (PermissionSet ps)
 {
     foreach (Permission p in ps)
         if (this.IsInSet(p))
             return true;
     return false;
 }
Exemplo n.º 6
0
 public bool HasPermission (PermissionSet perm, int organizationId, int geographyId, Authorization.Flag flags)
 {
     return Authorization.CheckAuthorization(perm, organizationId, geographyId, this, flags);
 }
Exemplo n.º 7
0
 public bool HasPermission (PermissionSet perm, Authorization.Flag flags)
 {
     return Authorization.CheckAuthorization(perm, -1, -1, this, flags);
 }