Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kontr 2.0
Portal API Backend
Commits
506113ab
Verified
Commit
506113ab
authored
Mar 31, 2019
by
Kristyna Pekarkova
Committed by
Peter Stanko
Apr 13, 2019
Browse files
Switched to SQlAlchemy-Continuum
parent
0549e9d8
Changes
7
Show whitespace changes
Inline
Side-by-side
Pipfile
View file @
506113ab
...
...
@@ -32,6 +32,7 @@ authlib = "*"
pip
=
"*"
git-url-parse
=
"*"
python-dateutil
=
"*"
sqlalchemy-continuum
=
"*"
[dev-packages]
pylint
=
"*"
...
...
Pipfile.lock
View file @
506113ab
{
"_meta"
:
{
"hash"
:
{
"sha256"
:
"
24bfa7becaf7a9f10d4322af7740f932332a48fb7e32c9f0b8a45337fffa36d9
"
"sha256"
:
"
86aa75e19a1ae3adc6eb5189d660e0ea4ce617df9817a916c7fc7d20def3960f
"
},
"pipfile-spec"
:
6
,
"requires"
:
{
...
...
@@ -636,6 +636,19 @@
],
"version"
:
"==1.3.2"
},
"sqlalchemy-continuum"
:
{
"hashes"
:
[
"sha256:4f4e378938baf3ca7321ee6f5c310c50868b66fef2507fb84ff5e0e27106f82c"
],
"index"
:
"pypi"
,
"version"
:
"==1.3.9"
},
"sqlalchemy-utils"
:
{
"hashes"
:
[
"sha256:3f1cb542cf0549a0de508d4919f3ad693a36230bf4cd13fdd6253549fec71182"
],
"version"
:
"==0.33.11"
},
"text-unidecode"
:
{
"hashes"
:
[
"sha256:5a1375bb2ba7968740508ae38d92e1f889a0832913cb1c447d5e2046061a396d"
,
...
...
migrations/versions/b7f7f426d205_.py
0 → 100644
View file @
506113ab
"""empty message
Revision ID: b7f7f426d205
Revises: ced9d1234d00
Create Date: 2019-03-31 20:37:55.782399
"""
from
alembic
import
op
import
sqlalchemy
as
sa
# revision identifiers, used by Alembic.
revision
=
'b7f7f426d205'
down_revision
=
'ced9d1234d00'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
# ### commands auto generated by Alembic - please adjust! ###
op
.
create_table
(
'reviewItem_version'
,
sa
.
Column
(
'created_at'
,
sa
.
TIMESTAMP
(),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'updated_at'
,
sa
.
TIMESTAMP
(),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'id'
,
sa
.
String
(
length
=
36
),
autoincrement
=
False
,
nullable
=
False
),
sa
.
Column
(
'review_id'
,
sa
.
String
(
length
=
36
),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'user_id'
,
sa
.
String
(
length
=
36
),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'content'
,
sa
.
Text
(),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'file'
,
sa
.
String
(
length
=
256
),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'line_start'
,
sa
.
Integer
(),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'line_end'
,
sa
.
Integer
(),
autoincrement
=
False
,
nullable
=
True
),
sa
.
Column
(
'transaction_id'
,
sa
.
BigInteger
(),
autoincrement
=
False
,
nullable
=
False
),
sa
.
Column
(
'end_transaction_id'
,
sa
.
BigInteger
(),
nullable
=
True
),
sa
.
Column
(
'operation_type'
,
sa
.
SmallInteger
(),
nullable
=
False
),
sa
.
PrimaryKeyConstraint
(
'id'
,
'transaction_id'
)
)
op
.
create_index
(
op
.
f
(
'ix_reviewItem_version_end_transaction_id'
),
'reviewItem_version'
,
[
'end_transaction_id'
],
unique
=
False
)
op
.
create_index
(
op
.
f
(
'ix_reviewItem_version_operation_type'
),
'reviewItem_version'
,
[
'operation_type'
],
unique
=
False
)
op
.
create_index
(
op
.
f
(
'ix_reviewItem_version_transaction_id'
),
'reviewItem_version'
,
[
'transaction_id'
],
unique
=
False
)
op
.
create_table
(
'transaction'
,
sa
.
Column
(
'issued_at'
,
sa
.
DateTime
(),
nullable
=
True
),
sa
.
Column
(
'id'
,
sa
.
BigInteger
(),
autoincrement
=
True
,
nullable
=
False
),
sa
.
Column
(
'remote_addr'
,
sa
.
String
(
length
=
50
),
nullable
=
True
),
sa
.
PrimaryKeyConstraint
(
'id'
)
)
# ### end Alembic commands ###
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
op
.
drop_table
(
'transaction'
)
op
.
drop_index
(
op
.
f
(
'ix_reviewItem_version_transaction_id'
),
table_name
=
'reviewItem_version'
)
op
.
drop_index
(
op
.
f
(
'ix_reviewItem_version_operation_type'
),
table_name
=
'reviewItem_version'
)
op
.
drop_index
(
op
.
f
(
'ix_reviewItem_version_end_transaction_id'
),
table_name
=
'reviewItem_version'
)
op
.
drop_table
(
'reviewItem_version'
)
# ### end Alembic commands ###
migrations/versions/ced9d1234d00_.py
0 → 100644
View file @
506113ab
"""empty message
Revision ID: ced9d1234d00
Revises: 949bc914e571
Create Date: 2019-03-31 20:21:59.038371
"""
from
alembic
import
op
import
sqlalchemy
as
sa
# revision identifiers, used by Alembic.
revision
=
'ced9d1234d00'
down_revision
=
'949bc914e571'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
# ### commands auto generated by Alembic - please adjust! ###
op
.
drop_column
(
'reviewItem'
,
'version_id'
)
# ### end Alembic commands ###
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
op
.
add_column
(
'reviewItem'
,
sa
.
Column
(
'version_id'
,
sa
.
INTEGER
(),
autoincrement
=
False
,
nullable
=
False
))
# ### end Alembic commands ###
portal/database/models.py
View file @
506113ab
...
...
@@ -19,7 +19,10 @@ from portal.database.mixins import EntityBase, NamedMixin
from
portal.database.types
import
JSONEncodedDict
,
YAMLEncodedDict
from
portal.tools
import
time
from
portal.tools.time
import
normalize_time
from
sqlalchemy_continuum
import
make_versioned
import
sqlalchemy
as
sa
make_versioned
(
user_cls
=
None
)
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -1022,6 +1025,7 @@ class ReviewItem(db.Model, EntityBase):
line_start: start line in the file
line_end: end line in the file
"""
__versioned__
=
{}
__tablename__
=
'reviewItem'
EXCLUDED
=
[
'user'
,
'review'
]
id
=
db
.
Column
(
db
.
String
(
length
=
36
),
default
=
lambda
:
str
(
...
...
@@ -1037,7 +1041,6 @@ class ReviewItem(db.Model, EntityBase):
file
=
db
.
Column
(
db
.
String
(
256
),
nullable
=
True
)
line_start
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
)
line_end
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
)
version_id
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
def
__init__
(
self
,
user
:
User
,
review
:
Review
,
content
:
str
=
None
,
file
:
str
=
None
,
line
:
int
=
None
,
line_start
:
int
=
None
,
line_end
:
int
=
None
):
...
...
@@ -1061,10 +1064,6 @@ class ReviewItem(db.Model, EntityBase):
self
.
line_start
=
line
self
.
line_end
=
line
__mapper_args__
=
{
"version_id_col"
:
version_id
}
@
hybrid_property
def
line
(
self
)
->
int
:
"""Get line by default returns line_start
...
...
@@ -1180,3 +1179,5 @@ Client.roles = db.relationship("Role", secondary="clients_roles")
User
.
groups
=
db
.
relationship
(
"Group"
,
secondary
=
"users_groups"
)
Project
.
groups
=
db
.
relationship
(
"Group"
,
secondary
=
"projects_groups"
,
back_populates
=
'projects'
)
sa
.
orm
.
configure_mappers
()
\ No newline at end of file
portal/rest/schemas.py
View file @
506113ab
...
...
@@ -16,20 +16,21 @@ def _in(prefix, params) -> List[str]:
class
NestedCollection
:
DEFAULTS
=
(
'id'
,
'codename'
,
'namespace'
)
USER_PARAMS
=
[
'id'
,
'username'
,
'uco'
,
'name'
,
'codename'
]
NESTED_REPR
=
{
'Role'
:
(
*
DEFAULTS
,
*
_in
(
'course'
,
DEFAULTS
)),
'Group'
:
(
*
DEFAULTS
,
*
_in
(
'course'
,
DEFAULTS
)),
'Project'
:
(
*
DEFAULTS
,
'state'
,
'submit_configurable'
,
*
_in
(
'course'
,
DEFAULTS
)),
'Course'
:
(
*
DEFAULTS
,),
'User'
:
(
'id'
,
'username'
,
'uco'
,
'codename'
,
'name'
),
'User'
:
(
*
USER_PARAMS
,
),
'Worker'
:
(
'id'
,
'codename'
,
'name'
),
'Client'
:
(
'id'
,
'type'
,
'name'
,
'codename'
),
'Component'
:
(
'id'
,
'name'
,
'type'
),
'Submission'
:
(
'id'
,
'state'
,
'created_at'
,
'updated_at'
,
'result'
,
'points'
,
'Submission'
:
(
'id'
,
'state'
,
'created_at'
,
'updated_at'
,
'result'
,
'points'
,
*
_in
(
'user'
,
[
'username'
,
'codename'
,
'name'
,
'uco'
,
'id'
]),
*
_in
(
'project'
,
DEFAULTS
),
*
_in
(
'course'
,
DEFAULTS
)),
'ReviewItem'
:
(
'id'
,
'review.id'
,
'line'
,
'content'
,
'file'
,
'
version_id
'
,
*
_in
(
'user'
,
[
'id'
,
'username'
,
'uco'
,
'name'
]
)),
'ReviewItem'
:
(
'id'
,
'review.id'
,
'line'
,
'content'
,
'file'
,
'
index
'
,
*
_in
(
'user'
,
USER_PARAMS
)),
'Secret'
:
(
'id'
,
'name'
,
'expires_at'
)
}
...
...
@@ -313,6 +314,7 @@ class ReviewItemSchema(BaseSchema, Schema):
line
=
fields
.
Int
()
line_start
=
fields
.
Int
()
line_end
=
fields
.
Int
()
index
=
fields
.
Int
()
review
=
NESTED
(
'Review'
,
only
=
(
'id'
,
'submission.id'
))
user
=
NESTED
[
'user'
]
...
...
tests/database/test_db.py
View file @
506113ab
...
...
@@ -955,8 +955,16 @@ def test_review_item_version_create_valid(session, course1, user1):
assert
ri1
in
user1
.
review_items
assert
ri2
in
user1
.
review_items
assert
ri1
.
version_id
==
1
assert
ri2
.
version_id
==
1
items1
=
ReviewItem
.
query
.
filter_by
(
id
=
ri1
.
id
).
all
()
assert
len
(
items1
)
==
1
items2
=
ReviewItem
.
query
.
filter_by
(
id
=
ri2
.
id
).
all
()
assert
len
(
items2
)
==
1
assert
ri1
.
versions
[
0
].
file
==
"foo"
assert
ri2
.
versions
[
0
].
file
==
"bar"
assert
ri1
.
versions
[
0
].
index
==
0
assert
ri2
.
versions
[
0
].
index
==
0
def
test_review_item_version_update_valid
(
session
,
course1
,
user1
):
...
...
@@ -969,20 +977,23 @@ def test_review_item_version_update_valid(session, course1, user1):
review
=
Review
(
submission
=
submission
)
ri1
=
ReviewItem
(
user
=
user1
,
review
=
review
,
file
=
"foo"
,
line
=
10
,
content
=
"something"
)
session
.
flush
()
session
.
commit
()
assert
ri1
in
user1
.
review_items
assert
ri1
.
version
_id
==
1
assert
ri1
.
version
s
[
0
].
index
==
0
ri1
.
content
=
"new content"
session
.
flush
()
session
.
commit
()
assert
ri1
in
user1
.
review_items
assert
ri1
.
version
_id
==
2
assert
ri1
.
version
s
[
1
].
index
==
1
ri1
.
line_start
=
None
session
.
flush
()
session
.
commit
()
assert
ri1
in
user1
.
review_items
assert
ri1
.
version_id
==
3
assert
ri1
.
versions
[
2
].
index
==
2
assert
ri1
.
versions
[
2
].
content
==
"new content"
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment