Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
c1b2adf8
Commit
c1b2adf8
authored
7 years ago
by
Dan Braghis
Browse files
Options
Downloads
Patches
Plain Diff
Add anonymisation option to user migration
parent
ec641cce
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentech/apply/users/management/commands/migrate_users.py
+13
-2
13 additions, 2 deletions
opentech/apply/users/management/commands/migrate_users.py
with
13 additions
and
2 deletions
opentech/apply/users/management/commands/migrate_users.py
+
13
−
2
View file @
c1b2adf8
...
@@ -15,7 +15,8 @@ class Command(BaseCommand):
...
@@ -15,7 +15,8 @@ class Command(BaseCommand):
groups
=
Group
.
objects
.
all
()
groups
=
Group
.
objects
.
all
()
def
add_arguments
(
self
,
parser
):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
source
'
,
type
=
argparse
.
FileType
(
'
r
'
),
help
=
'
Migration source JSON file
'
)
parser
.
add_argument
(
'
source
'
,
type
=
argparse
.
FileType
(
'
r
'
),
help
=
"
Migration source JSON file
"
)
parser
.
add_argument
(
'
--anonymize
'
,
action
=
'
store_true
'
,
help
=
"
Anonymizes non-OTF emails
"
)
@transaction.atomic
@transaction.atomic
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
...
@@ -28,7 +29,7 @@ class Command(BaseCommand):
...
@@ -28,7 +29,7 @@ class Command(BaseCommand):
full_name
=
self
.
get_full_name
(
user
)
full_name
=
self
.
get_full_name
(
user
)
user_object
,
created
=
User
.
objects
.
get_or_create
(
user_object
,
created
=
User
.
objects
.
get_or_create
(
email
=
user
[
'
mail
'
],
email
=
self
.
get_email
(
user
,
options
[
'
anonymize
'
]
)
,
defaults
=
{
defaults
=
{
'
full_name
'
:
full_name
,
'
full_name
'
:
full_name
,
'
drupal_id
'
:
uid
,
'
drupal_id
'
:
uid
,
...
@@ -78,3 +79,13 @@ class Command(BaseCommand):
...
@@ -78,3 +79,13 @@ class Command(BaseCommand):
groups
.
append
(
self
.
groups
.
filter
(
name
=
group_name
).
first
())
groups
.
append
(
self
.
groups
.
filter
(
name
=
group_name
).
first
())
return
groups
return
groups
def
get_email
(
self
,
user
,
anonymize
=
False
):
if
not
anonymize
:
return
user
[
'
mail
'
]
_
,
email_domain
=
user
[
'
mail
'
].
split
(
'
@
'
)
if
email_domain
in
settings
.
STAFF_EMAIL_DOMAINS
:
return
user
[
'
mail
'
]
return
"
aeon+%s@torchbox.com
"
%
user
[
'
uid
'
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment