Merge pull request #1457 from alexhermida/ft/force_initialize_localstorage_key

Force initialize new_terms_key
stable
Pablo Ruiz Múzquiz 2018-05-24 17:20:28 +02:00 committed by GitHub
commit e99b62592c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -23,7 +23,7 @@
###
TermsAnnouncementDirective = (TermsAnnouncementService, $repo, $auth, $config) ->
TermsAnnouncementDirective = (TermsAnnouncementService, $repo, $auth, $config, $model) ->
link = (scope, el, attrs) ->
scope.privacyPolicyUrl = $config.get("privacyPolicyUrl")
scope.termsOfServiceUrl = $config.get("termsOfServiceUrl")
@ -38,10 +38,18 @@ TermsAnnouncementDirective = (TermsAnnouncementService, $repo, $auth, $config) -
TermsAnnouncementService.open = false
user = $auth.getUser()
# We need to force initialization of rootscope user if localstorage user
# doesn't have the 'read_new_terms' key
if user.read_new_terms == undefined
userData = user.getAttrs()
userData.read_new_terms = false
user = $model.make_model("users", userData)
user.read_new_terms = true
onSuccess = (data) ->
$auth.setUser(data)
user.read_new_terms = true
$repo.save(user).then(onSuccess)
Object.defineProperties(this, {
@ -57,7 +65,8 @@ TermsAnnouncementDirective.$inject = [
"tgTermsAnnouncementService",
"$tgRepo",
"$tgAuth",
"$tgConfig"
"$tgConfig",
"$tgModel"
]
angular.module("taigaComponents")