예제 #1
0
        public async Task UpdateProfile(Guid profileId, UpdatableProfile profile, CancellationToken cancellationToken)
        {
            Ensure.Guid.IsNotEmpty(profileId, nameof(profileId));
            Ensure.Any.IsNotNull(profile, nameof(profile));

            var original = await _store.GetProfile(profileId, cancellationToken).ConfigureAwait(false);

            var changes = _calculator.CalculateChanges(original, profile);

            if (changes.ProfileChanged)
            {
                var updated = new Profile(profile)
                {
                    Id            = original.Id,
                    BannedAt      = original.BannedAt,
                    AcceptedCoCAt = original.AcceptedCoCAt,
                    AcceptedToSAt = original.AcceptedToSAt
                };

                // Determine consent changes
                if (original.AcceptCoC == false && profile.AcceptCoC)
                {
                    updated.AcceptedCoCAt = DateTimeOffset.UtcNow;
                }

                if (original.AcceptToS == false && profile.AcceptToS)
                {
                    updated.AcceptedToSAt = DateTimeOffset.UtcNow;
                }

                await _processor.Execute(updated, changes, cancellationToken).ConfigureAwait(false);

                UpdateResultsCache(updated);
            }
        }
        private static void DetermineCategoryChanges(Profile original, UpdatableProfile updated,
                                                     bool findAllCategoryChanges, ProfileChangeResult result)
        {
            // Find the category changes
            DetermineCategoryChanges(CategoryGroup.Gender, original.Gender, updated.Gender, result);

            if (findAllCategoryChanges == false &&
                result.ProfileChanged)
            {
                // We only need to find a single change which we have
                return;
            }

            // Check for changes to languages
            DetermineCategoryChanges(CategoryGroup.Language, original.Languages, updated.Languages,
                                     findAllCategoryChanges, result);

            if (findAllCategoryChanges == false &&
                result.ProfileChanged)
            {
                // We only need to find a single change which we have
                return;
            }

            // Check for changes to skills
            var originalSkillNames = original.Skills.Select(x => x.Name).ToList();
            var updatedSkillNames  = updated.Skills.Select(x => x.Name).ToList();

            DetermineCategoryChanges(CategoryGroup.Skill, originalSkillNames, updatedSkillNames, findAllCategoryChanges,
                                     result);
        }
        public static ClaimsIdentity Build(Account account = null, UpdatableProfile profile = null)
        {
            var claims = new List <Claim>();

            var username = Guid.NewGuid().ToString();

            if (account != null)
            {
                username = account.Provider + "|" + account.Subject;
            }

            if (username.IndexOf("|", StringComparison.OrdinalIgnoreCase) == -1)
            {
                username = "******" + username;
            }

            AddClaim(claims, "sub", username);
            AddClaim(claims, "email", profile?.Email);
            AddClaim(claims, "givenName", profile?.FirstName);
            AddClaim(claims, "surname", profile?.LastName);

            var identity = new ClaimsIdentity(claims, "local", "sub", "role");

            return(identity);
        }
        public void IsCreatedWithDefaultValuesTest()
        {
            var sut = new UpdatableProfile();

            sut.Languages.Should().NotBeNull();
            sut.Skills.Should().NotBeNull();
            sut.Status.Should().Be(ProfileStatus.Hidden);
        }
        public ProfileChangeResult RemoveAllCategoryLinks(UpdatableProfile profile)
        {
            Ensure.Any.IsNotNull(profile, nameof(profile));

            var result = new ProfileChangeResult();

            DetermineAllCategoryRemovalChanges(profile, result);

            return(result);
        }
        public async Task <IActionResult> Put([FromBody] UpdatableProfile model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                return(new ErrorMessageResult(Resources.Controller_NoBodyDataProvided, HttpStatusCode.BadRequest));
            }

            var profileId = User.Identity.GetClaimValue <Guid>(ClaimType.ProfileId);

            await _profileCommand.UpdateProfile(profileId, model, cancellationToken).ConfigureAwait(false);

            return(new NoContentResult());
        }
예제 #7
0
    protected virtual void OnTriggerExit(Collider other)
    {
        if (state.behavioursInTransit.Count == 0)
        {
            return;
        }

        UpdatableProfile updProf = other.GetComponentInChildren <UpdatableProfile> ();

        if (updProf != null && state.behavioursInTransit.Contains(updProf))
        {
            updProf.StopLerping();
        }
    }
        private static void DetermineAllCategoryAddChanges(UpdatableProfile profile, ProfileChangeResult result)
        {
            // Remove gender link
            DetermineCategoryChanges(CategoryGroup.Gender, null, profile.Gender, result);

            // Check for changes to languages
            var emptyCategoryNames = new List <string>();

            // Remove all language links
            DetermineCategoryChanges(CategoryGroup.Language, emptyCategoryNames, profile.Languages, true, result);

            var skillNames = profile.Skills.Select(x => x.Name).ToList();

            // Remove all skill links
            DetermineCategoryChanges(CategoryGroup.Skill, emptyCategoryNames, skillNames, true, result);
        }
        public void ValidateIncludesToSConsentErrorTest()
        {
            var sut = new UpdatableProfile
            {
                AcceptCoC = true,
                AcceptToS = false,
                Status    = ProfileStatus.Available
            };

            var context = new ValidationContext(sut);

            var errors = sut.Validate(context).ToList();

            errors[0].MemberNames.Should().HaveCount(1);
            errors[0].MemberNames.Should().Contain(x => x == nameof(UpdatableProfile.AcceptToS));
        }
        public void ValidateEvaluatesConsentTest(ProfileStatus status, bool acceptCoC, bool acceptToS,
                                                 bool hasErrors)
        {
            var sut = new UpdatableProfile
            {
                AcceptCoC = acceptCoC,
                AcceptToS = acceptToS,
                Status    = status
            };

            var context = new ValidationContext(sut);

            var errors = sut.Validate(context).ToList();

            if (hasErrors)
            {
                errors.Should().NotBeEmpty();
            }
            else
            {
                errors.Should().BeEmpty();
            }
        }
        private static bool HasProfileChanged(Profile original, UpdatableProfile updated)
        {
            Debug.Assert(original != null, "No original profile provided");
            Debug.Assert(updated != null, "No updated profile provided");

            if (original.AcceptCoC != updated.AcceptCoC)
            {
                return(true);
            }

            if (original.AcceptToS != updated.AcceptToS)
            {
                return(true);
            }

            if (HasStringChanged(original.About, updated.About))
            {
                return(true);
            }

            if (HasStringChanged(original.PhotoHash, updated.PhotoHash))
            {
                return(true);
            }

            if (HasGuidChanged(original.PhotoId, updated.PhotoId))
            {
                return(true);
            }

            if (HasIntChanged(original.BirthYear, updated.BirthYear))
            {
                return(true);
            }

            if (HasStringChanged(original.Email, updated.Email))
            {
                return(true);
            }

            if (HasStringChanged(original.FirstName, updated.FirstName))
            {
                return(true);
            }

            if (HasStringChanged(original.GitHubUsername, updated.GitHubUsername))
            {
                return(true);
            }

            if (HasStringChanged(original.LastName, updated.LastName))
            {
                return(true);
            }

            if (original.Status != updated.Status)
            {
                return(true);
            }

            if (HasStringChanged(original.TimeZone, updated.TimeZone))
            {
                return(true);
            }

            if (HasStringChanged(original.TwitterUsername, updated.TwitterUsername))
            {
                return(true);
            }

            if (HasStringChanged(original.Website, updated.Website))
            {
                return(true);
            }

            if (HasIntChanged(original.YearStartedInTech, updated.YearStartedInTech))
            {
                return(true);
            }

            return(false);
        }
        public ProfileChangeResult CalculateChanges(Profile original, UpdatableProfile updated)
        {
            Ensure.Any.IsNotNull(original, nameof(original));
            Ensure.Any.IsNotNull(updated, nameof(updated));

            var result = new ProfileChangeResult();
            var canUpdateCategoryLinks = true;

            if (original.Status == ProfileStatus.Hidden &&
                updated.Status == ProfileStatus.Hidden)
            {
                // We don't calculate any changes to category links for a hidden profiles that are still hidden
                // If we do look for category links to determine if the profile should be saved, we can exit once at least one is found
                canUpdateCategoryLinks = false;
            }
            else if (original.BannedAt != null)
            {
                // We don't calculate any changes to category links for a banned profile
                // If we do look for category links to determine if the profile should be saved, we can exit once at least one is found
                canUpdateCategoryLinks = false;
            }

            if (original.Status != ProfileStatus.Hidden &&
                updated.Status == ProfileStatus.Hidden)
            {
                // The profile is being hidden
                // Remove all the existing category links
                // We will remove all the links from the original profile
                // This is because if there are any changes from the original profile to the updated profile,
                // they aren't stored yet in the links so we don't care
                DetermineAllCategoryRemovalChanges(original, result);
            }
            else if (original.Status == ProfileStatus.Hidden &&
                     updated.Status != ProfileStatus.Hidden)
            {
                // The profile is being displayed after being hidden
                // We need to add all the links to the updated profile
                DetermineAllCategoryAddChanges(updated, result);
            }
            else
            {
                // Find the category changes between the original and updated profiles
                DetermineCategoryChanges(original, updated, canUpdateCategoryLinks, result);
            }

            if (result.ProfileChanged == false)
            {
                result.ProfileChanged = HasProfileChanged(original, updated);
            }

            if (result.ProfileChanged == false)
            {
                // The profile properties have not changed
                // We haven't checked for category items added or removed yet, but we also need to check
                // if any skills have been changed
                // Search for changes to skill metadata
                result.ProfileChanged = HaveSkillsChanged(original.Skills, updated.Skills);
            }

            if (canUpdateCategoryLinks == false)
            {
                // We may have calculated category link changes in order to figure out if the profile should be saved
                // but we are not going make any category link changes so we need to clear them out
                result.CategoryChanges.Clear();
            }

            return(result);
        }