Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MO-P
Odevzdávací Systém MO
Commits
d42fd6df
Project 'mj/mo-submit' was moved to 'mo-p/osmo'. Please update any links and bookmarks that may still have the old path.
Commit
d42fd6df
authored
Jan 23, 2021
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Skript na slučování účtů
parent
dcb957a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/merge-users
+68
-0
68 additions, 0 deletions
bin/merge-users
with
68 additions
and
0 deletions
bin/merge-users
0 → 100755
+
68
−
0
View file @
d42fd6df
#!/usr/bin/env python3
import
argparse
import
mo.db
as
db
import
mo.users
import
mo.util
parser
=
argparse
.
ArgumentParser
(
description
=
'
Sloučí dva uživatele do jednoho
'
)
parser
.
add_argument
(
dest
=
'
src
'
,
help
=
'
e-mailová adresa zdrojového účtu
'
)
parser
.
add_argument
(
dest
=
'
dest
'
,
help
=
'
e-mailová adresa cílového účtu
'
)
parser
.
add_argument
(
'
-n
'
,
'
--dry-run
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
vyzkouší sloučení nanečisto (necommitne)
'
)
args
=
parser
.
parse_args
()
mo
.
util
.
init_standalone
()
su
=
mo
.
users
.
user_by_email
(
args
.
src
)
if
su
is
None
:
mo
.
util
.
die
(
f
'
Uživatel <
{
args
.
src
}
> nenalezen
'
)
du
=
mo
.
users
.
user_by_email
(
args
.
dest
)
if
du
is
None
:
mo
.
util
.
die
(
f
'
Uživatel <
{
args
.
dest
}
> nenalezen
'
)
if
(
su
.
is_org
,
su
.
is_admin
)
!=
(
du
.
is_org
,
du
.
is_admin
):
mo
.
util
.
die
(
'
Neumím sloučit účty různého typu
'
)
suid
=
su
.
user_id
duid
=
du
.
user_id
print
(
f
"
Slučuji UID
{
suid
}
do UID
{
duid
}
"
)
sess
=
db
.
get_session
()
conn
=
sess
.
connection
()
conn
.
execute
(
db
.
Log
.
__table__
.
update
().
where
(
db
.
Log
.
changed_by
==
suid
).
values
(
changed_by
=
duid
))
conn
.
execute
(
db
.
Participant
.
__table__
.
delete
().
where
(
db
.
Participant
.
user_id
==
suid
))
conn
.
execute
(
db
.
Participation
.
__table__
.
update
().
where
(
db
.
Participation
.
user_id
==
suid
).
values
(
user_id
=
duid
))
conn
.
execute
(
db
.
UserRole
.
__table__
.
update
().
where
(
db
.
UserRole
.
user_id
==
suid
).
values
(
user_id
=
duid
))
conn
.
execute
(
db
.
UserRole
.
__table__
.
update
().
where
(
db
.
UserRole
.
assigned_by
==
suid
).
values
(
assigned_by
=
duid
))
conn
.
execute
(
db
.
Paper
.
__table__
.
update
().
where
(
db
.
Paper
.
for_user
==
suid
).
values
(
for_user
=
duid
))
conn
.
execute
(
db
.
Paper
.
__table__
.
update
().
where
(
db
.
Paper
.
uploaded_by
==
suid
).
values
(
uploaded_by
=
duid
))
conn
.
execute
(
db
.
PointsHistory
.
__table__
.
update
().
where
(
db
.
PointsHistory
.
participant_id
==
suid
).
values
(
participant_id
=
duid
))
conn
.
execute
(
db
.
PointsHistory
.
__table__
.
update
().
where
(
db
.
PointsHistory
.
points_by
==
suid
).
values
(
points_by
=
duid
))
conn
.
execute
(
db
.
Solution
.
__table__
.
update
().
where
(
db
.
Solution
.
user_id
==
suid
).
values
(
user_id
=
duid
))
conn
.
execute
(
db
.
Job
.
__table__
.
update
().
where
(
db
.
Job
.
user_id
==
suid
).
values
(
user_id
=
duid
))
mo
.
util
.
log
(
db
.
LogType
.
user
,
suid
,
{
'
action
'
:
'
merge
'
,
'
to
'
:
duid
,
})
mo
.
util
.
log
(
db
.
LogType
.
user
,
duid
,
{
'
action
'
:
'
merge
'
,
'
from
'
:
suid
,
})
if
not
args
.
dry_run
:
sess
.
commit
()
else
:
sess
.
rollback
()
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
sign in
to comment