Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
c6466f4f
Commit
c6466f4f
authored
7 years ago
by
hkethi002
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #793 from scitran/group-upd-modified
Group modified updates correctly
parents
b79fc519
9a0480dd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/dao/liststorage.py
+17
-4
17 additions, 4 deletions
api/dao/liststorage.py
api/handlers/grouphandler.py
+1
-0
1 addition, 0 deletions
api/handlers/grouphandler.py
test/integration_tests/python/test_groups.py
+81
-0
81 additions, 0 deletions
test/integration_tests/python/test_groups.py
with
99 additions
and
4 deletions
api/dao/liststorage.py
+
17
−
4
View file @
c6466f4f
...
...
@@ -74,7 +74,10 @@ class ListStorage(object):
query
=
{
'
_id
'
:
_id
}
if
exclude_params
:
query
[
self
.
list_name
]
=
{
'
$not
'
:
{
'
$elemMatch
'
:
exclude_params
}
}
update
=
{
'
$push
'
:
{
self
.
list_name
:
payload
}
}
update
=
{
'
$push
'
:
{
self
.
list_name
:
payload
},
'
$set
'
:
{
'
modified
'
:
datetime
.
datetime
.
utcnow
()}
}
log
.
debug
(
'
query {}
'
.
format
(
query
))
log
.
debug
(
'
update {}
'
.
format
(
update
))
result
=
self
.
dbc
.
update_one
(
query
,
update
)
...
...
@@ -96,6 +99,7 @@ class ListStorage(object):
{
self
.
list_name
:
{
'
$elemMatch
'
:
query_params
}},
{
self
.
list_name
:
{
'
$not
'
:
{
'
$elemMatch
'
:
exclude_params
}
}}
]
mod_elem
[
'
modified
'
]
=
datetime
.
datetime
.
utcnow
()
update
=
{
'
$set
'
:
mod_elem
}
...
...
@@ -106,7 +110,10 @@ class ListStorage(object):
def
_delete_el
(
self
,
_id
,
query_params
):
log
.
debug
(
'
query_params {}
'
.
format
(
query_params
))
query
=
{
'
_id
'
:
_id
}
update
=
{
'
$pull
'
:
{
self
.
list_name
:
query_params
}
}
update
=
{
'
$pull
'
:
{
self
.
list_name
:
query_params
},
'
$set
'
:
{
'
modified
'
:
datetime
.
datetime
.
utcnow
()}
}
log
.
debug
(
'
query {}
'
.
format
(
query
))
log
.
debug
(
'
update {}
'
.
format
(
update
))
result
=
self
.
dbc
.
update_one
(
query
,
update
)
...
...
@@ -162,7 +169,10 @@ class StringListStorage(ListStorage):
def
_create_el
(
self
,
_id
,
payload
,
exclude_params
):
log
.
debug
(
'
payload {}
'
.
format
(
payload
))
query
=
{
'
_id
'
:
_id
,
self
.
list_name
:
{
'
$ne
'
:
payload
}}
update
=
{
'
$push
'
:
{
self
.
list_name
:
payload
}}
update
=
{
'
$push
'
:
{
self
.
list_name
:
payload
},
'
$set
'
:
{
'
modified
'
:
datetime
.
datetime
.
utcnow
()}
}
log
.
debug
(
'
query {}
'
.
format
(
query
))
log
.
debug
(
'
update {}
'
.
format
(
update
))
result
=
self
.
dbc
.
update_one
(
query
,
update
)
...
...
@@ -180,7 +190,10 @@ class StringListStorage(ListStorage):
{
self
.
list_name
:
{
'
$ne
'
:
payload
}
}
]
}
update
=
{
'
$set
'
:
{
self
.
list_name
+
'
.$
'
:
payload
}}
update
=
{
'
$set
'
:
{
self
.
list_name
+
'
.$
'
:
payload
,
'
modified
'
:
datetime
.
datetime
.
utcnow
()}
}
log
.
debug
(
'
query {}
'
.
format
(
query
))
log
.
debug
(
'
update {}
'
.
format
(
update
))
return
self
.
dbc
.
update_one
(
query
,
update
)
...
...
This diff is collapsed.
Click to expand it.
api/handlers/grouphandler.py
+
1
−
0
View file @
c6466f4f
...
...
@@ -55,6 +55,7 @@ class GroupHandler(base.RequestHandler):
payload_schema_uri
=
validators
.
schema_uri
(
'
input
'
,
'
group-update.json
'
)
payload_validator
=
validators
.
from_schema_path
(
payload_schema_uri
)
payload_validator
(
payload
,
'
PUT
'
)
payload
[
'
modified
'
]
=
datetime
.
datetime
.
utcnow
()
result
=
mongo_validator
(
permchecker
(
self
.
storage
.
exec_op
))(
'
PUT
'
,
_id
=
_id
,
payload
=
payload
)
if
result
.
modified_count
==
1
:
return
{
'
modified
'
:
result
.
modified_count
}
...
...
This diff is collapsed.
Click to expand it.
test/integration_tests/python/test_groups.py
+
81
−
0
View file @
c6466f4f
from
dateutil.parser
import
parse
def
test_groups
(
as_admin
,
data_builder
):
# Cannot find a non-existant group
r
=
as_admin
.
get
(
'
/groups/non-existent
'
)
...
...
@@ -8,12 +10,91 @@ def test_groups(as_admin, data_builder):
# Able to find new group
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
first_modified
=
r
.
json
()[
'
modified
'
]
# Able to change group name
group_name
=
'
New group name
'
r
=
as_admin
.
put
(
'
/groups/
'
+
group
,
json
=
{
'
name
'
:
group_name
})
assert
r
.
ok
# Get the group again to compare timestamps
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
second_modified
=
r
.
json
()[
'
modified
'
]
d1
=
parse
(
first_modified
)
d2
=
parse
(
second_modified
)
assert
d2
>
d1
# Add a tag to the group
tag_name
=
'
Grey2
'
r
=
as_admin
.
post
(
'
/groups/
'
+
group
+
'
/tags
'
,
json
=
{
'
value
'
:
tag_name
})
assert
r
.
ok
# Get the group again to compare timestamps for the Add tag test groups
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
third_modified
=
r
.
json
()[
'
modified
'
]
d3
=
parse
(
third_modified
)
assert
d3
>
d2
# Edit the tag
new_tag_name
=
'
Brown
'
r
=
as_admin
.
put
(
'
/groups/
'
+
group
+
'
/tags/
'
+
tag_name
,
json
=
{
'
value
'
:
new_tag_name
})
assert
r
.
ok
# Get the group again to compare timestamps for the Edit tag test groups
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
fourth_modified
=
r
.
json
()[
'
modified
'
]
d4
=
parse
(
fourth_modified
)
assert
d4
>
d3
# Delete the tag
r
=
as_admin
.
delete
(
'
/groups/
'
+
group
+
'
/tags/
'
+
new_tag_name
)
assert
r
.
ok
# Get the group again to compare timestamps for the Delete tag test groups
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
fith_modified
=
r
.
json
()[
'
modified
'
]
d5
=
parse
(
fith_modified
)
assert
d5
>
d4
# Add a role to the group
user
=
{
'
access
'
:
'
rw
'
,
'
site
'
:
'
local
'
,
'
_id
'
:
'
newUser@fakeuser.com
'
}
r
=
as_admin
.
post
(
'
/groups/
'
+
group
+
'
/roles
'
,
json
=
user
)
assert
r
.
ok
# Get the group again to compare timestamps for the Add role test groups
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
six_modified
=
r
.
json
()[
'
modified
'
]
d6
=
parse
(
six_modified
)
assert
d6
>
d5
# Edit a role in the group
user
=
{
'
access
'
:
'
ro
'
,
'
site
'
:
'
local
'
,
'
_id
'
:
'
newUser@fakeuser.com
'
}
r
=
as_admin
.
put
(
'
/groups/
'
+
group
+
'
/roles/
'
+
user
[
'
site
'
]
+
'
/
'
+
user
[
'
_id
'
],
json
=
user
)
assert
r
.
ok
# Get the group again to compare timestamps for the Edit role test groups
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
seven_modified
=
r
.
json
()[
'
modified
'
]
d7
=
parse
(
seven_modified
)
assert
d7
>
d6
# Delete a role in the group
r
=
as_admin
.
delete
(
'
/groups/
'
+
group
+
'
/roles/
'
+
user
[
'
site
'
]
+
'
/
'
+
user
[
'
_id
'
])
assert
r
.
ok
# Get the group again to compare timestamps for the Edit role test groups
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
eight_modified
=
r
.
json
()[
'
modified
'
]
d8
=
parse
(
eight_modified
)
assert
d8
>
d7
r
=
as_admin
.
get
(
'
/groups/
'
+
group
)
assert
r
.
ok
assert
r
.
json
()[
'
name
'
]
==
group_name
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