Exemplo n.º 1
0
        public static void SeedDB2(ge_DbContext context, string source)
        {
            var u1 = context.Users.Where(user => user.UserName == "*****@*****.**").Single();
            var u2 = context.Users.Where(user => user.UserName == "*****@*****.**").Single();
            var u3 = context.Users.Where(a => a.UserName == "*****@*****.**").Single();
            var u4 = context.Users.Where(a => a.UserName == "*****@*****.**").Single();
            var u5 = context.Users.Where(a => a.UserName == "*****@*****.**").Single();
            var u6 = context.Users.Where(a => a.UserName == "*****@*****.**").Single();;
            var u7 = context.Users.Where(a => a.UserName == "*****@*****.**").Single();;

            var g1 = new ge_group {
                Id                 = Guid.NewGuid(),
                name               = "Primary Geotechnical Group",
                locName            = "",
                createdDT          = DateTime.Now,
                locAddress         = "",
                locPostcode        = "",
                datumProjection    = datumProjection.NONE,
                managerId          = u4.Id,
                operations         = "Read;",
                project_operations = "Create;Read;Update;Delete",
                projects           = new List <ge_project>(),
                users              = new List <ge_user_ops>()
            };

            g1.users.Add(new ge_user_ops {
                userId          = u1.Id,
                user_operations = "Read;Download;Create;Update;Delete;Approve;Admin"
            });
            g1.users.Add(new ge_user_ops {
                userId          = u2.Id,
                user_operations = "Read;Download;Create;Update;Delete"
            });
        }
Exemplo n.º 2
0
        public static bool DoesUserHaveOperation(this ge_DbContext context, string operation, ge_group group, string userId)
        {
            if (context == null || group == null || operation == null || userId == String.Empty)
            {
                return(false);
            }

            bool        retvar     = false;
            ge_user_ops user_group = null;

            if (group.Id == Guid.Empty)
            {
                return(IsUserAnyGroupAdmin(context, userId));
            }

            user_group = context.ge_user_ops
                         .AsNoTracking()
                         .Where(u => u.groupId == group.Id)
                         .Where(u => u.userId == userId).FirstOrDefault();
            if (user_group != null)
            {
                if (user_group.user_operations.Contains(operation))
                {
                    context.Entry <ge_user_ops>(user_group).State = EntityState.Detached;
                    user_group = null;
                    retvar     = true;
                }
            }

            return(retvar);
        }
Exemplo n.º 3
0
 public DeleteModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IOptions <ge_config> ge_config) : base(context, authorizationService, userManager, ge_config)
 {
 }
Exemplo n.º 4
0
 //    public Expression<Func<T, TResult>> orderByProperty {get; set;}
 public _geFullPagedTypedModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     int defaultPageSize) : base(context, authorizationService, userManager, defaultPageSize)
 {
 }
Exemplo n.º 5
0
 public DeleteModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager)
     : base(context, authorizationService, userManager)
 {
 }
Exemplo n.º 6
0
 public IndexModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager)
     : base(context, authorizationService, userManager, 10)
 {
 }
Exemplo n.º 7
0
 public static int GetUserProjectCount(this ge_DbContext context, string userId)
 {
     return(context.ge_user_ops
            .AsNoTracking()
            .Where(u => u.userId == userId)
            .Where(u => u.projectId != null)
            .Count());
 }
Exemplo n.º 8
0
        public static bool IsUserAnyGroupAdmin(this ge_DbContext context, string userId)
        {
            var user_group = context.ge_user_ops
                             .AsNoTracking()
                             .Where(u => u.userId == userId && u.groupId != null && u.user_operations.Contains(Constants.AdminOperationName));

            return(user_group.Any());
        }
Exemplo n.º 9
0
 public MessageModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager)
     : base(context, authorizationService, userManager)
 {
     msg = new ge_messages();
 }
Exemplo n.º 10
0
 public _ProjectPageModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IOptions <ge_config> ge_config) : base(context, authorizationService, userManager)
 {
     _config = ge_config.Value;
 }
Exemplo n.º 11
0
        public static void FixUsers(ge_DbContext context)
        {
            var user1 = context.Users.Where(a => a.UserName == "*****@*****.**").Single();

            user1.FirstName = "WeiJian";
            user1.LastName  = "Ng";
            context.SaveChanges();
        }
Exemplo n.º 12
0
 public static bool IsUserAdmin(this ge_DbContext context, ge_group group, string userId)
 {
     if (context == null || group == null || userId == String.Empty)
     {
         return(false);
     }
     return(DoesUserHaveOperation(context, Constants.AdminOperationName, group, userId));
 }
Exemplo n.º 13
0
 public static bool IsUserApprover(this ge_DbContext context, ge_project project, string userId)
 {
     if (context == null || project == null || userId == String.Empty)
     {
         return(false);
     }
     return(DoesUserHaveOperation(context, Constants.ApproveOperationName, project, userId));
 }
Exemplo n.º 14
0
 public _geBaseLocaPageModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager)
     : base(context, authorizationService, userManager)
 {
     locSelect = "";
 }
Exemplo n.º 15
0
        public static int IsOperationAllowed(this ge_DbContext context, string operation, ge_group group, ge_project project, ge_data data)
        {
            if (context == null || data == null || project == null || group == null || operation == String.Empty)
            {
                return(geOPSResp.InvalidInput);
            }

            // Check at group level;
            if (group.project_operations == null)
            {
                return(geOPSResp.GroupProject);;
            }

            if (!group.project_operations.Contains(operation))
            {
                return(geOPSResp.GroupProject);
            }

            // check project record status
            if (project.data_operations == null)
            {
                return(geOPSResp.ProjectData);
            }
            if (!project.data_operations.Contains(operation))
            {
                return(geOPSResp.ProjectData);
            }
            if (operation == Constants.UpdateOperationName || operation == Constants.DeleteOperationName)
            {
                if (project.pstatus == Constants.PublishStatus.Approved)
                {
                    return(geOPSResp.ProjectApproved);
                }
            }

            //Check data record status
            if (data.Id == Guid.Empty)
            {
                return(geOPSResp.Allowed);
            }
            if (operation == Constants.UpdateOperationName || operation == Constants.DeleteOperationName)
            {
                if (data.pstatus == Constants.PublishStatus.Approved)
                {
                    return(geOPSResp.DataApproved);
                }
            }
            if (data.operations == null)
            {
                return(geOPSResp.Data);
            }
            if (!data.operations.Contains(operation))
            {
                return(geOPSResp.Data);
            }

            return(geOPSResp.Allowed);
        }
Exemplo n.º 16
0
 public ge_gisController(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IHostingEnvironment env,
     IOptions <ge_config> ge_config)
     : base(context, authorizationService, userManager, env, ge_config)
 {
 }
Exemplo n.º 17
0
 public _geBasePageModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager) : base()
 {
     _context              = context;
     _userManager          = userManager;
     _authorizationService = authorizationService;
 }
Exemplo n.º 18
0
 public CreateModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IEmailSender emailSender) : base(context, authorizationService, userManager)
 {
     _emailSender       = emailSender;
     _new_user_password = "******";
 }
Exemplo n.º 19
0
 public CreateAGSModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IOptions <ge_config> config
     )
     : base(context, authorizationService, userManager, config)
 {
 }
Exemplo n.º 20
0
        public static bool DoesUserHaveOperation(this ge_DbContext context, string operation, ge_project project, string userId)
        {
            if (context == null || project == null || operation == null || userId == null)
            {
                return(false);
            }

            if (userId == String.Empty)
            {
                return(false);
            }

            bool retvar = false;

            ge_user_ops user_proj  = null;
            ge_user_ops user_group = null;

            if (project.Id == Guid.Empty && operation == geOPS.Create.Name)
            {
                if (project.group == null)
                {
                    return(false);
                }
                return(DoesUserHaveOperation(context, geOPS.Create.Name, project.group, userId));
            }
            user_proj = context.ge_user_ops
                        .AsNoTracking()
                        .Where(p => p.userId == userId && p.projectId == project.Id).FirstOrDefault();

            if (user_proj != null)
            {
                if (user_proj.user_operations.Contains(operation))
                {
                    retvar = true;
                }
                else
                {
                    retvar = false;
                }
            }
            else
            {
                user_group = context.ge_user_ops
                             .AsNoTracking()
                             .Where(u => u.userId == userId && u.groupId == project.groupId).FirstOrDefault();
                if (user_group.user_operations.Contains(operation))
                {
                    retvar = true;
                }
                else
                {
                    retvar = false;
                }
            }

            return(retvar);
        }
Exemplo n.º 21
0
 public _geBasePagedModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     int defaultPageSize) : base(context, authorizationService, userManager)
 {
     pageSize  = defaultPageSize;
     pageIndex = 1;
     pageTotal = 1;
 }
Exemplo n.º 22
0
 public _geFullPagedModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     int defaultPageSize) : base(context, authorizationService, userManager, defaultPageSize)
 {
     groupId   = null;
     projectId = null;
     pStatus   = Constants.PublishStatus.Uncontrolled;
 }
Exemplo n.º 23
0
 public EditModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IOptions <ge_config> config,
     ILogger <_DataPageModel> logger
     )
     : base(context, authorizationService, userManager, config, logger)
 {
 }
Exemplo n.º 24
0
 public _DataPageModel(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IOptions <ge_config> ge_config,
     ILogger <_DataPageModel> logger)
     : base(context, authorizationService, userManager)
 {
     _config = ge_config;
     _logger = logger;
 }
Exemplo n.º 25
0
 public ge_ags2Controller(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IOptions <ags_config> agsConfig,
     IHostingEnvironment env,
     IOptions <ge_config> ge_config)
     : base(context, authorizationService, userManager, env, ge_config)
 {
     _agsConfig = agsConfig;
     context.Database.SetCommandTimeout(1200);
 }
Exemplo n.º 26
0
 public ge_Controller(
     ge_DbContext context,
     IAuthorizationService authorizationService,
     UserManager <ge_user> userManager,
     IHostingEnvironment env,
     IOptions <ge_config> ge_config) : base()
 {
     _context              = context;
     _userManager          = userManager;
     _authorizationService = authorizationService;
     _env       = env;
     _ge_config = ge_config;
 }
Exemplo n.º 27
0
        public static bool IsUserLastAdmin(this ge_DbContext context, ge_project project, string userId)
        {
            string LastAdminUserId = context.lastAdminUserId(project);

            if (!String.IsNullOrEmpty(LastAdminUserId))
            {
                if (LastAdminUserId == userId)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 28
0
        public static bool DoesUserHaveAnyOperations(this ge_DbContext context, ge_group group, string userEmail)
        {
            if (context == null || group == null || userEmail == String.Empty)
            {
                return(false);
            }
            var user_group = context.ge_user_ops
                             .AsNoTracking()
                             .Include(u => u.user)
                             .Where(u => u.user.Email == userEmail && u.groupId == group.Id);

            return(user_group.Any());
        }
Exemplo n.º 29
0
        public static bool DoesUserHaveAnyOperations(this ge_DbContext context, ge_project project, string userEmail)
        {
            if (context == null || project == null || userEmail == String.Empty)
            {
                return(false);
            }
            var user_project = context.ge_user_ops
                               .AsNoTracking()
                               .Include(u => u.user)
                               .Where(u => u.user.Email == userEmail && u.projectId == project.Id);

            return(user_project.Any());
        }
Exemplo n.º 30
0
        public static int IsOperationAllowed(this ge_DbContext context, string operation, ge_project project, ge_transform transform)
        {
            if (context == null || transform == null || project == null || operation == String.Empty)
            {
                return(geOPSResp.InvalidInput);
            }

            // check project record status
            if (project.data_operations == null)
            {
                return(geOPSResp.ProjectData);
            }
            if (!project.data_operations.Contains(operation))
            {
                return(geOPSResp.ProjectData);
            }
            if (operation == Constants.UpdateOperationName || operation == Constants.DeleteOperationName)
            {
                if (project.pstatus == Constants.PublishStatus.Approved)
                {
                    return(geOPSResp.ProjectApproved);
                }
            }

            //Check data record status

            if (transform.Id == Guid.Empty)
            {
                return(geOPSResp.Allowed);
            }

            // if (operation == geOPS.Update || operation==geOPS.Delete) {
            //    if (transform.pstatus == Constants.PublishStatus.Approved) {
            //        return geOPSResp.DataApproved;
            //    }
            // }

            if (transform.operations == null)
            {
                return(geOPSResp.Data);
            }
            if (!transform.operations.Contains(operation))
            {
                return(geOPSResp.Data);
            }

            return(geOPSResp.Allowed);
        }