Exemplo n.º 1
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.º 2
0
        public async Task <ge_user_ops> CreateUserOps(ge_user_ops newUserOps)
        {
            await _unitOfWork.UserOps.AddAsync(newUserOps);

            await _unitOfWork.CommitAsync();

            return(newUserOps);
        }
Exemplo n.º 3
0
        public async Task <Boolean> AreGroupOperationsAllowed(string userId, ge_group group, string request_ops)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, group.Id);

            operation_request req = new operation_request(group, group_user);

            return(req.AreGroupOperationsAllowed(request_ops));
        }
Exemplo n.º 4
0
        public async Task <operation_request> GetOperationRequest(string userId, ge_group group)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, group.Id);

            operation_request req = new operation_request(group, group_user);

            return(req);
        }
Exemplo n.º 5
0
        public async Task <string> GetAllowedOperations(string userId, ge_group group)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, group.Id);

            operation_request req = new operation_request(group, group_user);

            return(req._effectiveGroup_ops);
        }
Exemplo n.º 6
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.º 7
0
        public async Task <Boolean> AreProjectOperationsAllowed(string userId, ge_project project, string request_ops)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, project.groupId);

            ge_user_ops project_user = await _unitOfWork.UserOps.GetByUserIdProjectId(userId, project.Id);

            operation_request req = new operation_request(project, group_user, project_user);

            return(req.AreProjectOperationsAllowed(request_ops));
        }
Exemplo n.º 8
0
        public async Task <operation_request> GetOperationRequest(string userId, ge_project project)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, project.groupId);

            ge_user_ops project_user = await _unitOfWork.UserOps.GetByUserIdProjectId(userId, project.Id);

            operation_request req = new operation_request(project, group_user, project_user);

            return(req);
        }
Exemplo n.º 9
0
        public async Task <string> GetAllowedOperations(string userId, ge_project project)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, project.groupId);

            ge_user_ops project_user = await _unitOfWork.UserOps.GetByUserIdProjectId(userId, project.Id);

            operation_request req = new operation_request(project, group_user, project_user);

            return(req._effectiveProject_ops);
        }
Exemplo n.º 10
0
 public void addUser(ge_user u, string operations)
 {
     if (group != null)
     {
         if (group.users != null)
         {
             ge_user_ops os = new ge_user_ops();
             os.user       = u;
             os.operations = operations;
             group.users.Add(os);
         }
     }
 }
Exemplo n.º 11
0
        public async Task <IActionResult> OnGetAsync(Guid?groupId, Guid?projectId)
        {
            var CurrentUserId = GetUserIdAsync().Result;

            user = new ge_user();

            user_ops                 = new ge_user_ops();
            user_ops.operations      = "Read;Update;Delete";
            user_ops.user_operations = "Create;Read;Update;Delete";

            if (groupId != null)
            {
                user_ops.group = _context.ge_group
                                 .Where(o => o.Id == groupId).FirstOrDefault();
                if (user_ops.group != null)
                {
                    bool IsUserGroupAdmin = _context.DoesUserHaveOperation(Constants.AdminOperationName, user_ops.group, CurrentUserId);
                    if (!IsUserGroupAdmin)
                    {
                        return(RedirectToPageMessage(msgCODE.GROUP_OPERATION_CREATE_ADMINREQ));
                    }
                    user_ops.groupId = user_ops.group.Id;
                    setViewData();
                    return(Page());
                }
                if (projectId != null)
                {
                    return(RedirectToPageMessage(msgCODE.USER_OPS_CREATE_AMBIGUOUS));
                }
            }

            if (projectId != null)
            {
                user_ops.project = _context.ge_project
                                   .Where(p => p.Id == projectId).FirstOrDefault();
                if (user_ops.project != null)
                {
                    bool IsUserProjectAdmin = _context.DoesUserHaveOperation(Constants.AdminOperationName, user_ops.project, CurrentUserId);
                    if (!IsUserProjectAdmin)
                    {
                        return(RedirectToPageMessage(msgCODE.PROJECT_OPERATION_CREATE_ADMINREQ));
                    }
                    user_ops.projectId = user_ops.project.Id;
                    setViewData();
                    return(Page());
                }
            }

            return(NotFound());
        }
Exemplo n.º 12
0
        public async Task <Boolean> IsUserProjectAdmin(string userId, ge_project project)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, project.groupId);

            if (group_user.user_operations.Contains("Admin"))
            {
                return(true);
            }
            ;

            ge_user_ops project_user = await _unitOfWork.UserOps.GetByUserIdProjectId(userId, project.Id);

            return(project_user.user_operations.Contains("Admin"));
        }
Exemplo n.º 13
0
        public static int IsOperationAllowed(this ge_DbContext context, string operation, ge_user_ops user_op)
        {
            if (context == null || user_op == null || operation == String.Empty)
            {
                return(geOPSResp.InvalidInput);
            }

            if (user_op.operations == null)
            {
                return(geOPSResp.UserOperation);
            }

            if (!user_op.operations.Contains(operation))
            {
                return(geOPSResp.UserOperation);
            }

            return(geOPSResp.Allowed);
        }
Exemplo n.º 14
0
        public async Task UpdateUserOps(ge_user_ops dest, ge_user_ops src)
        {
            dest.projectId = src.projectId;

            await _unitOfWork.CommitAsync();
        }
Exemplo n.º 15
0
 public async Task DeleteUserOps(ge_user_ops user_ops)
 {
     _unitOfWork.UserOps.Remove(user_ops);
     await _unitOfWork.CommitAsync();
 }
Exemplo n.º 16
0
        public async Task <Boolean> IsUserGroupAdmin(string userId, ge_group group)
        {
            ge_user_ops group_user = await _unitOfWork.UserOps.GetByUserIdGroupId(userId, group.Id);

            return(group_user.user_operations.Contains("Admin"));
        }