Skip to content

Commit

Permalink
initial pass at modelling a spam_report table
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Feb 20, 2018
1 parent 4ff4846 commit 9809881
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
63 changes: 63 additions & 0 deletions warehouse/migrations/versions/75dde92f5019_create_spam_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
create spam models
Revision ID: 75dde92f5019
Revises: b75709859292
Create Date: 2018-02-19 20:16:00.579309
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = '75dde92f5019'
down_revision = 'b75709859292'


def upgrade():
op.create_table(
'spam_report',
sa.Column(
'id', postgresql.UUID(as_uuid=True),
server_default=sa.text('gen_random_uuid()'), nullable=False
),
sa.Column('release_name', sa.Text(), nullable=False),
sa.Column('release_version', sa.Text(), nullable=False),
sa.Column(
'source',
postgresql.ENUM(
'automation', 'user',
name='report_source_enum'
),
nullable=False
),
sa.Column('reporter_user_id', postgresql.UUID(), nullable=True),
sa.Column('result', sa.Boolean(), nullable=False),
sa.Column('comment', sa.Text(), nullable=True),
sa.Column('valid', sa.Boolean(), nullable=True),
sa.CheckConstraint(
"reporter_user_id IS NOT NULL OR source = 'automation'",
name='valid_reporter_user_id'
),
sa.ForeignKeyConstraint(
['release_name', 'release_version'],
['releases.name', 'releases.version'],
onupdate='CASCADE', ondelete='CASCADE'
),
sa.PrimaryKeyConstraint('id')
)


def downgrade():
op.drop_table('spam_report')
11 changes: 11 additions & 0 deletions warehouse/spam/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
54 changes: 54 additions & 0 deletions warehouse/spam/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from sqlalchemy import (
Boolean,
CheckConstraint,
Column,
ForeignKeyConstraint,
Text,
)
from sqlalchemy.dialects.postgresql import ENUM, UUID

from warehouse import db


report_source = ENUM(
'automation',
'user',
name="report_source_enum",
)


class SpamReport(db.Model):

__tablename__ = "spam_report"
__table_args__ = (
ForeignKeyConstraint(
["release_name", "release_version"],
["releases.name", "releases.version"],
onupdate="CASCADE",
ondelete="CASCADE",
),
CheckConstraint(
"reporter_user_id IS NOT NULL OR source = 'automation'",
name="valid_reporter_user_id",
),
)

release_name = Column(Text, nullable=False)
release_version = Column(Text, nullable=False)
source = Column(report_source, nullable=False)
reporter_user_id = Column(UUID, nullable=True)
result = Column(Boolean, nullable=False)
comment = Column(Text, nullable=True)
valid = Column(Boolean, nullable=True)
21 changes: 21 additions & 0 deletions warehouse/spam/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from warehouse import tasks


@tasks.task(bind=True, ignore_result=True, acks_late=True)
def analyze_upload(task, request):
try:
pass
except Exception as exc:
task.retry(exc=exc)

0 comments on commit 9809881

Please sign in to comment.