/// <summary>
 /// Loads dbs configured for an org
 /// </summary>
 /// <param name="organization"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public static async Task LoadDatabasesAsync(this Organization organization, MapHiveDbContext db)
 {
     organization.Databases = await db.OrganizationDatabases.Where(x => x.OrganizationId == organization.Uuid).ToListAsync();
 }
Esempio n. 2
0
        /// <summary>
        /// Checks if a given user is an admin of an organization
        /// </summary>
        /// <param name="org"></param>
        /// <param name="dbCtx"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static async Task <bool> CheckIfUserIsAdminAsync(this Organization org, DbContext dbCtx, Guid userId)
        {
            var owners = await org.GetAdminsAsync(dbCtx);

            return(owners.Any(o => o.Uuid == userId));
        }
 /// <summary>
 /// Loads dbs configured for an org
 /// </summary>
 /// <param name="organization"></param>
 /// <param name="db"></param>
 public static void LoadDatabases(this Organization organization, MapHiveDbContext db)
 {
     organization.Databases = db.OrganizationDatabases.Where(x => x.OrganizationId == organization.Uuid).ToList();
 }
Esempio n. 4
0
        /// <summary>
        /// Gets apps visible by a user
        /// </summary>
        /// <param name="dbCtx"></param>
        /// <param name="userId"></param>
        /// <param name="orgIdentifier"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <Application> > GetUserAppsAsync(DbContext dbCtx, Guid?userId, string orgIdentifier = null)
        {
            var appCollector = new List <Application>();

            //common apps
            //do not return hive apps! they should not be listed in user apps even though they will usually be common apps
            var commonApps = await dbCtx.Set <Application>().Where(a => a.IsCommon && !a.IsHive).ToListAsync();

            appCollector.AddRange(commonApps);


            MapHiveUser user = null;

            if (userId.HasValue)
            {
                user = await dbCtx.Set <MapHiveUser>().FirstOrDefaultAsync(u => u.Uuid == userId);
            }

            Organization org = null;

            if (user != null && !string.IsNullOrEmpty(orgIdentifier))
            {
                org = await dbCtx.Set <Organization>().FirstOrDefaultAsync(o => o.Slug == orgIdentifier);
            }


            //get org apps - the apps that are not public, but assigned to orgs directly
            if (user != null && org != null)
            {
                var orgApps = await org.GetChildrenAsync <Organization, Application>(dbCtx);

                foreach (var app in orgApps)
                {
                    if (!appCollector.Exists(a => a.Uuid == app.Uuid))
                    {
                        appCollector.Add(app);
                    }
                }
            }

            var outApps = new List <Application>();

            foreach (var a in appCollector)
            {
                if (
                    !a.IsApi &&                            //discard apis, they are not 'user apps'
                    (
                        a.IsDefault ||                     //always return the dashboard
                        (a.IsCommon && !a.RequiresAuth) || //and the public apps with no auth
                        (org != null && (await org.GetUserAppAccessCredentialsAsync(dbCtx, user, a)).CanUseApp)
                    )
                    )
                {
                    outApps.Add(a);
                }
            }

            //TODO - more ordering - stuff like special apps that are not public, but assigned to orgs directly, etc. Also, maybe some differentiation between freely accessible apps and the apps with auth.

            //stuff like home & dashboard always at the beginning and such...
            return(outApps.OrderByDescending(a => a.IsHome).ThenByDescending(a => a.IsDefault).ThenBy(a => a.Name));;
        }