Exemplo n.º 1
0
        /// <summary>
        /// Returns if the member has the given permission
        /// </summary>
        public async Task <bool> HasPermissionAsync(PlanetPermission permission, ValourDB db = null)
        {
            // Make sure we didn't include the planet already
            if (Planet == null)
            {
                bool createdb = false;
                if (db == null)
                {
                    db       = new ValourDB(ValourDB.DBOptions);
                    createdb = true;
                }

                Planet = await db.Planets.FindAsync(Planet_Id);

                if (createdb)
                {
                    await db.DisposeAsync();
                }
            }

            // Special case for owner
            if (User_Id == Planet.Owner_Id)
            {
                return(true);
            }

            return((await GetPrimaryRoleAsync(db)).HasPermission(permission));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns if the given user is authorized to access this planet
        /// </summary>
        public async Task <bool> HasPermissionAsync(ServerPlanetMember member, PlanetPermission permission, ValourDB db)
        {
            // Special case for viewing planets
            if (permission.Value == PlanetPermissions.View.Value)
            {
                if (Public || (member != null))
                {
                    return(true);
                }
            }

            // At this point all permissions require membership
            if (member == null)
            {
                return(false);
            }

            // Owner has all permissions
            if (member.User_Id == Owner_Id)
            {
                return(true);
            }

            // Get user main role
            var mainRole = await db.Entry(member).Collection(x => x.RoleMembership)
                           .Query()
                           .Include(x => x.Role)
                           .OrderBy(x => x.Role.Position)
                           .Select(x => x.Role)
                           .FirstAsync();

            // Return permission state
            return(mainRole.HasPermission(permission));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Returns if the role has the permission
 /// </summary>
 /// <param name="permission"></param>
 /// <returns></returns>
 public bool HasPermission(PlanetPermission permission)
 {
     return(Permission.HasPermission(Permissions, permission));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns if the member has the given permission
        /// </summary>
        public async Task <bool> HasPermissionAsync(PlanetPermission permission, ValourDB db)
        {
            Planet ??= await db.Planets.FindAsync(Planet_Id);

            return(await Planet.HasPermissionAsync(this, permission, db));
        }