Ejemplo n.º 1
0
        public async Task<IActionResult> GetResourcesforUser(string userId)
        {
            List<ScampResourceSummary> resourceList = new List<ScampResourceSummary>();
            ScampUser currentUser = await _securityHelper.GetOrCreateCurrentUser();

            // request must be systemAdmin, or the requesting user
            if (!currentUser.IsSystemAdmin && currentUser.Id != userId)
                return new ObjectResult("User is not authorized to perform this action against specific resource(s)") { StatusCode = 401 };

            // execute query
            ScampUser user = await _userRepository.GetUserById(userId);
            if (user == null)
                return new ObjectResult("requested resource not available") { StatusCode = 204 };

            foreach (ScampUserGroupMbrship groupMbrship in user.GroupMembership)
            {
                foreach (ScampUserGroupResources resource in groupMbrship.Resources)
                {
                    // get resource state from volatile store
                    CurrentResourceState currentState = await _volatileStorageController.GetResourceState(resource.Id);

                    ScampResourceSummary tmpSummary = new ScampResourceSummary()
                    {
                        Id = resource.Id,
                        Name = resource.Name,
                        Type = resource.type,
                        State = currentState.State,
                        totUnitsUsed = currentState.UnitsUsed
                    };

                    resourceList.Add(tmpSummary);
                }
            }

            return new ObjectResult(resourceList) { StatusCode = 200 };
        }
Ejemplo n.º 2
0
        public async Task<IActionResult> Get(string groupId, string userId)
        {
            //TODO: add in group admin/manager authorization check
            //if (!await CurrentUserCanViewGroup(group))
            //    return new HttpStatusCodeResult(403); // Forbidden
            //}

            // get group details
            var tmpUser = await _userRepository.GetUserById(userId);
            if (tmpUser == null) // group not found, return appropriately
                return HttpNotFound();

            ScampUserGroupMbrship tmpGroup = tmpUser.GroupMembership.FirstOrDefault(g => g.Id == groupId);
            if (tmpGroup == null) // user not found in group, return appropriately
                return new HttpStatusCodeResult(204); // nothing found

            // build return view
            List<ScampResourceSummary> rtnView = new List<ScampResourceSummary>();

            foreach (ScampUserGroupResources resourceRef in tmpGroup.Resources)
            {
                // get resource usage
                var rscState = await _volatileStorageController.GetResourceState(resourceRef.Id);

                ScampResourceSummary tmpSummary = new ScampResourceSummary()
                {
                    Id = resourceRef.Id,
                    Name = resourceRef.Name,
                    State = rscState.State,
                    totUnitsUsed = rscState.UnitsUsed
                };
                rtnView.Add(tmpSummary);
            }

            return new ObjectResult(rtnView) { StatusCode = 200 };
        }