public UserAuthorization(IEphItUser userObj, EphItContext context)
 {
     _userObj = userObj;
     _db      = context;
 }
Esempio n. 2
0
 public ODataScripts(EphItContext context, IEphItUser ephItUser)
 {
     _dbContext = context;
     DbContext  = _dbContext;
     _ephItUser = ephItUser;
 }
Esempio n. 3
0
        public void ConfigureDb(IEphItUser user, EphItContext _context)
        {
            bool migrateDb = true;

            try
            {
                migrateDb = _context.Database.EnsureCreated();
                if (!migrateDb)
                {
                    migrateDb = _context.Database.GetPendingMigrations().Any();
                }
            }
            catch
            {
                migrateDb = true;
            }
            if (migrateDb)
            {
                _context.Database.Migrate();
                var internalUser = _context.User.Where(p => p.AuthenticationId.Equals((short)AuthenticationEnum.EphItInternal)).First();
                var admin        = _context.Role.Where(p => p.Name.Equals("Administrators")).FirstOrDefault();
                if (admin == null)
                {
                    admin = new Role();
                    admin.CreatedByUserId  = internalUser.UserId;
                    admin.Created          = DateTime.UtcNow;
                    admin.Description      = "Full administrator of all objects";
                    admin.Name             = "Administrators";
                    admin.IsGlobal         = true;
                    admin.Modified         = DateTime.UtcNow;
                    admin.ModifiedByUserId = internalUser.UserId;
                    _context.Add(admin);
                    _context.SaveChanges();
                }
                foreach (RBACActionEnum a in (RBACActionEnum[])Enum.GetValues(typeof(RBACActionEnum)))
                {
                    foreach (RBACObjectEnum b in (RBACObjectEnum[])Enum.GetValues(typeof(RBACObjectEnum)))
                    {
                        if (!_context.RoleObjectAction.Where(p =>
                                                             p.RoleId.Equals(admin.RoleId) &&
                                                             p.RbacObjectId.Equals((short)b) &&
                                                             p.RbacActionId.Equals((short)a)
                                                             )
                            .Any()
                            )
                        {
                            var tempObject = new RoleObjectAction();
                            tempObject.RoleId       = admin.RoleId;
                            tempObject.RbacObjectId = (short)b;
                            tempObject.RbacActionId = (short)a;
                            _context.Add(tempObject);
                        }
                    }
                }
                _context.SaveChanges();
            }
            // Add current user to full admin role
            var vUser = user.RegisterCurrent();

            if (!_context.RoleMembershipUser.Where(p => p.UserId == vUser.UserId && p.Role.Name.Equals("Administrators")).Any())
            {
                var admin             = _context.Role.Where(p => p.Name.Equals("Administrators")).FirstOrDefault();
                var newRoleMembership = new RoleMembershipUser();
                newRoleMembership.RoleId = admin.RoleId;
                newRoleMembership.UserId = vUser.UserId;
                _context.Add(newRoleMembership);
            }
            _context.SaveChanges();
        }
Esempio n. 4
0
 public ScriptVersionController(EphItContext dbContext, IEphItUser ephItUser)
 {
     _dbContext = dbContext;
     _ephItUser = ephItUser;
 }