Example #1
0
 public Task <TeamResource> Create(TeamResource resource)
 => ApiClientWrapper.Create <TeamResource>(RootUri, resource);
        public async Task <IActionResult> UpdateUserTeamAsync(int teamId, [FromBody] TeamResource teamResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Verify email address has valid structure
            string normalizedAddress;

            if (!EmailExtension.TryNormalizeEmail(teamResource.OwnerEmail, out normalizedAddress))
            {
                return(BadRequest("Not a valid email address!"));
            }

            var dbTeam = await unitOfWork.UserTeamRepository.GetUserTeamAsync(teamId);

            // Validate that the user editing the team is the owner
            var tokenOwnerEmail = User.FindFirst("Email").Value;

            if (!tokenOwnerEmail.Equals(dbTeam.OwnerEmail))
            {
                return(Forbid());
            }

            // Fetch an account from the DB asynchronously
            var account = await unitOfWork.UserAccountRepository
                          .GetUserAccountAsync(tokenOwnerEmail);

            // Return not found exception if account doesn't exist
            if (account == null)
            {
                return(NotFound("Couldn't find an account matching that ownerId."));
            }

            // Get the team
            var team = await unitOfWork.UserTeamRepository
                       .GetUserTeamAsync(teamId);

            // Nothing was retrieved, no id match
            if (team == null || team.IsDeleted)
            {
                return(NotFound("Couldn't find a team matching that teamId."));
            }

            // Map resource to model
            team.TeamName        = teamResource.TeamName;
            team.TeamDescription = teamResource.TeamDescription;

            // check if owner is changing
            if (tokenOwnerEmail != normalizedAddress)
            {
                await unitOfWork.TeamMemberRepository.ChangeTeamOwnership(teamId, normalizedAddress);
            }

            // Save updated team to database
            Task.WaitAll(unitOfWork.CompleteAsync());

            // Return mapped team resource
            return(Ok(_mapper.Map <TeamResource>(team)));
        }
        /// <summary>
        /// Gathers the Users from a Team.
        /// </summary>
        /// <param name="client">The Repository this is tacked on to.</param>
        /// <param name="team">The team to return the user resources from.</param>
        /// <returns>Enumerable of UserResources.</returns>
        internal static IEnumerable <UserResource> GetTeamUsers(this IOctopusClient client, TeamResource team)
        {
            List <UserResource> users = new List <UserResource>();

            foreach (var userId in team.MemberUserIds)
            {
                var user = client.Get <UserResource>(string.Format(ResourceStrings.TeamUserIdFormat, userId));
                if (user != null)
                {
                    users.Add(user);
                }
            }
            return(users);
        }
Example #4
0
 internal Team DownloadTeam(TeamResource resource)
 {
     Logger.Trace($"Downloading {nameof(TeamResource)}: {resource.Name}");
     return(resource.ToModel(_repository));
 }
        protected override void ProcessRecord()
        {
            object baseresource = null;

            switch (Resource)
            {
            case "Environment":
                baseresource = new EnvironmentResource();
                break;

            case "Project":
                baseresource = new ProjectResource();
                break;

            case "ProjectGroup":
                baseresource = new ProjectGroupResource();
                break;

            case "NugetFeed":
            case "ExternalFeed":
                baseresource = new NuGetFeedResource();
                break;

            case "LibraryVariableSet":
                baseresource = new LibraryVariableSetResource();
                break;

            case "Machine":
            case "Target":
                baseresource = new MachineResource();
                break;

            case "Lifecycle":
                baseresource = new LifecycleResource();
                break;

            case "Team":
                baseresource = new TeamResource();
                break;

            case "User":
                baseresource = new UserResource();
                break;

            case "Channel":
                baseresource = new ChannelResource();
                break;

            case "Tenant":
                baseresource = new TenantResource();
                break;

            case "TagSet":
                baseresource = new TagSetResource();
                break;

            case "UserRole":
                baseresource = new UserRoleResource();
                break;
            }

            WriteObject(baseresource, true);
        }
Example #6
0
 public static bool IsEnoughResources(GameEntity company, TeamResource resource)
 {
     return(company.companyResource.Resources.IsEnoughResources(resource));
 }
Example #7
0
 public static void SetResources(GameEntity company, TeamResource resource, string purpose)
 {
     company.ReplaceCompanyResource(resource);
     RegisterTransaction(company, resource, purpose);
 }
 private Team ReadTeam(TeamResource resource)
 {
     Logger.Info($"Downloading {nameof(TeamResource)}: {resource.Name}");
     return(resource.ToModel(_repository));
 }
Example #9
0
 public void Awake()
 {
     state     = FindObjectOfType <GameState>();
     resources = state.resources;
 }
Example #10
0
 /// <summary>
 /// Gathers a List of Users in a Team by Team.
 /// </summary>
 /// <param name="octRepository">The repository to call against.</param>
 /// <param name="team">Team to get users from</param>
 /// <returns>Enumerable of UserResources</returns>
 public static IEnumerable <UserResource> GetUsersByTeam(OctopusRepository octRepository, TeamResource team)
 {
     return(octRepository.Client.GetTeamUsers(team));
 }