#2427 Add the date_modified to projects API
Merged 7 years ago by pingou. Opened 7 years ago by cverna.
cverna/pagure project_date_modifed  into  master

@@ -0,0 +1,36 @@ 

+ """Add date_modified for project

+ 

+ Revision ID: 8a5d68f74beb

+ Revises: 27a79ff0fb41

+ Create Date: 2017-07-18 19:28:09.566997

+ 

+ """

+ from alembic import op

+ import sqlalchemy as sa

+ 

+ # revision identifiers, used by Alembic.

+ revision = '8a5d68f74beb'

+ down_revision = '27a79ff0fb41'

+ 

+ 

+ def upgrade():

+     ''' Add the column date_modified to the table projects.

+     '''

+     op.add_column(

+         'projects',

+         sa.Column('date_modified', sa.DateTime, nullable=True,

+                   default=sa.func.now())

+     )

+     op.execute("UPDATE projects SET date_modified=date_created;")

+ 

+     op.alter_column(

+         'projects',

+         column_name='date_modified',

+         nullable=False,

+         exisiting_nullable=True)

+ 

+ 

+ def downgrade():

+     ''' Remove the column date_modified from the table projects.

+     '''

+     op.drop_column('projects', 'date_modified')

file modified
+1
@@ -333,6 +333,7 @@ 

                "close_status": [],

                "custom_keys": [],

                "date_created": "1427441537",

+               "date_modified": "1427441537",

                "description": "A web-based calendar for Fedora",

                "milestones": {},

                "namespace": null,

file modified
+9
@@ -976,7 +976,9 @@ 

      if new_user_obj in project.users:

          access_obj = get_obj_access(session, project, new_user_obj)

          access_obj.access = access

+         project.date_modified = datetime.datetime.utcnow()

          session.add(access_obj)

+         session.add(project)

          session.flush()

  

          pagure.lib.notify.log(
@@ -998,7 +1000,9 @@ 

          user_id=new_user_obj.id,

          access=access,

      )

+     project.date_modified = datetime.datetime.utcnow()

      session.add(project_user)

+     session.add(project)

      # Make sure we won't have SQLAlchemy error before we continue

      session.flush()

  
@@ -1067,6 +1071,8 @@ 

          access_obj = get_obj_access(session, project, group_obj)

          access_obj.access = access

          session.add(access_obj)

+         project.date_modified = datetime.datetime.utcnow()

+         session.add(project)

          session.flush()

  

          pagure.lib.notify.log(
@@ -1090,6 +1096,8 @@ 

      )

      session.add(project_group)

      # Make sure we won't have SQLAlchemy error before we continue

+     project.date_modified = datetime.datetime.utcnow()

+     session.add(project)

      session.flush()

  

      pagure.lib.notify.log(
@@ -1738,6 +1746,7 @@ 

          return 'No settings to change'

      else:

          repo.settings = new_settings

+         repo.date_modified = datetime.datetime.utcnow()

          session.add(repo)

          session.flush()

  

file modified
+3 -1
@@ -371,7 +371,8 @@ 

  

      date_created = sa.Column(sa.DateTime, nullable=False,

                               default=datetime.datetime.utcnow)

- 

+     date_modified = sa.Column(sa.DateTime, nullable=False,

+                               default=datetime.datetime.utcnow)

      parent = relation('Project', remote_side=[id], backref='forks')

      user = relation('User', foreign_keys=[user_id],

                      remote_side=[User.id], backref='projects')
@@ -821,6 +822,7 @@ 

              'parent': self.parent.to_json(

                  public=public, api=api) if self.parent else None,

              'date_created': self.date_created.strftime('%s'),

+             'date_modified': self.date_modified.strftime('%s'),

              'user': self.user.to_json(public=public),

              'access_users': self.access_users_json,

              'access_groups': self.access_groups_json,

@@ -89,7 +89,9 @@ 

          data['requests'][0]['date_created'] = '1431414800'

          data['requests'][0]['updated_on'] = '1431414800'

          data['requests'][0]['project']['date_created'] = '1431414800'

+         data['requests'][0]['project']['date_modified'] = '1431414800'

          data['requests'][0]['repo_from']['date_created'] = '1431414800'

+         data['requests'][0]['repo_from']['date_modified'] = '1431414800'

          data['requests'][0]['uid'] = '1431414800'

          data['requests'][0]['last_updated'] = '1431414800'

          expected_data = {
@@ -131,6 +133,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1431414800",

+                     "date_modified": "1431414800",

                      "description": "test project #1",

                      "fullname": "test",

                      "id": 1,
@@ -165,6 +168,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1431414800",

+                     "date_modified": "1431414800",

                      "description": "test project #1",

                      "fullname": "test",

                      "id": 1,
@@ -201,7 +205,9 @@ 

          data2['requests'][0]['date_created'] = '1431414800'

          data2['requests'][0]['updated_on'] = '1431414800'

          data2['requests'][0]['project']['date_created'] = '1431414800'

+         data2['requests'][0]['project']['date_modified'] = '1431414800'

          data2['requests'][0]['repo_from']['date_created'] = '1431414800'

+         data2['requests'][0]['repo_from']['date_modified'] = '1431414800'

          data2['requests'][0]['uid'] = '1431414800'

          data2['requests'][0]['last_updated'] = '1431414800'

          self.assertDictEqual(data, data2)
@@ -262,7 +268,9 @@ 

          data['date_created'] = '1431414800'

          data['updated_on'] = '1431414800'

          data['project']['date_created'] = '1431414800'

+         data['project']['date_modified'] = '1431414800'

          data['repo_from']['date_created'] = '1431414800'

+         data['repo_from']['date_modified'] = '1431414800'

          data['uid'] = '1431414800'

          data['last_updated'] = '1431414800'

          expected_data = {
@@ -298,6 +306,7 @@ 

                  ],

                  "custom_keys": [],

                  "date_created": "1431414800",

+                 "date_modified": "1431414800",

                  "description": "test project #1",

                  "fullname": "test",

                  "id": 1,
@@ -330,6 +339,7 @@ 

                      "Duplicate"],

                      "custom_keys": [],

                      "date_created": "1431414800",

+                     "date_modified": "1431414800",

                      "description": "test project #1",

                      "fullname": "test",

                      "id": 1,
@@ -363,7 +373,9 @@ 

          data2 = json.loads(output.data)

          data2['date_created'] = '1431414800'

          data2['project']['date_created'] = '1431414800'

+         data2['project']['date_modified'] = '1431414800'

          data2['repo_from']['date_created'] = '1431414800'

+         data2['repo_from']['date_modified'] = '1431414800'

          data2['uid'] = '1431414800'

          data2['date_created'] = '1431414800'

          data2['updated_on'] = '1431414800'

@@ -243,6 +243,7 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['projects'][0]['date_created'] = "1436527638"

+         data['projects'][0]['date_modified'] = "1436527638"

          expected_data = {

            "args": {

              "fork": None,
@@ -276,6 +277,7 @@ 

                ],

                "custom_keys": [],

                "date_created": "1436527638",

+               "date_modified": "1436527638",

                "description": "test project #1",

                "fullname": "test",

                "id": 1,
@@ -367,6 +369,7 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['projects'][0]['date_created'] = "1436527638"

+         data['projects'][0]['date_modified'] = "1436527638"

          expected_data = {

              "args": {

                  "fork": None,
@@ -395,6 +398,7 @@ 

                  ],

                  "custom_keys": [],

                  "date_created": "1436527638",

+                 "date_modified": "1436527638",

                  "description": "test project #1",

                  "fullname": "test",

                  "id": 1,
@@ -417,8 +421,11 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['projects'][0]['date_created'] = "1436527638"

+         data['projects'][0]['date_modified'] = "1436527638"

          data['projects'][1]['date_created'] = "1436527638"

+         data['projects'][1]['date_modified'] = "1436527638"

          data['projects'][2]['date_created'] = "1436527638"

+         data['projects'][2]['date_modified'] = "1436527638"

          expected_data = {

              "args": {

                  "fork": None,
@@ -450,6 +457,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "test project #1",

                      "fullname": "test",

                      "id": 1,
@@ -484,6 +492,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "test project #2",

                      "fullname": "test2",

                      "id": 2,
@@ -518,6 +527,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "namespaced test project",

                      "fullname": "somenamespace/test3",

                      "id": 3,
@@ -541,8 +551,11 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['projects'][0]['date_created'] = "1436527638"

+         data['projects'][0]['date_modified'] = "1436527638"

          data['projects'][1]['date_created'] = "1436527638"

+         data['projects'][1]['date_modified'] = "1436527638"

          data['projects'][2]['date_created'] = "1436527638"

+         data['projects'][2]['date_modified'] = "1436527638"

          expected_data = {

              "args": {

                  "fork": None,
@@ -573,6 +586,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "test project #1",

                      "fullname": "test",

                      "id": 1,
@@ -607,6 +621,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "test project #2",

                      "fullname": "test2",

                      "id": 2,
@@ -639,6 +654,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "namespaced test project",

                      "fullname": "somenamespace/test3",

                      "id": 3,
@@ -662,6 +678,7 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['projects'][0]['date_created'] = "1436527638"

+         data['projects'][0]['date_modified'] = "1436527638"

          expected_data = {

              "args": {

                  "fork": None,
@@ -690,6 +707,7 @@ 

                      "Duplicate"],

                  "custom_keys": [],

                  "date_created": "1436527638",

+                 "date_modified": "1436527638",

                  "description": "test project #1",

                  "fullname": "test",

                  "id": 1,
@@ -712,6 +730,7 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['projects'][0]['date_created'] = "1436527638"

+         data['projects'][0]['date_modified'] = "1436527638"

          expected_data = {

              "args": {

                  "fork": None,
@@ -741,6 +760,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "namespaced test project",

                      "fullname": "somenamespace/test3",

                      "id": 3,
@@ -795,6 +815,7 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['date_created'] = "1436527638"

+         data['date_modified'] = "1436527638"

          expected_data ={

              "access_groups": {

                  "admin": [],
@@ -814,6 +835,7 @@ 

              ],

              "custom_keys": [],

              "date_created": "1436527638",

+             "date_modified": "1436527638",

              "description": "test project #1",

              "fullname": "test",

              "id": 1,
@@ -837,9 +859,9 @@ 

          output = self.app.get('/api/0/projects?page=1')

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

-         data['projects'][0]['date_created'] = "1436527638"

-         data['projects'][1]['date_created'] = "1436527638"

-         data['projects'][2]['date_created'] = "1436527638"

+         for i in range(3):

+             data['projects'][i]['date_created'] = "1436527638"

+             data['projects'][i]['date_modified'] = "1436527638"

          expected_data = {

              "args": {

                  "fork": None,
@@ -881,6 +903,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "test project #1",

                      "fullname": "test",

                      "id": 1,
@@ -915,6 +938,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "test project #2",

                      "fullname": "test2",

                      "id": 2,
@@ -947,6 +971,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "namespaced test project",

                      "fullname": "somenamespace/test3",

                      "id": 3,
@@ -975,6 +1000,7 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['projects'][0]['date_created'] = "1436527638"

+         data['projects'][0]['date_modified'] = "1436527638"

          expected_data = {

              "args": {

                  "fork": None,
@@ -1017,6 +1043,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1436527638",

+                     "date_modified": "1436527638",

                      "description": "namespaced test project",

                      "fullname": "somenamespace/test3",

                      "id": 3,
@@ -1106,6 +1133,7 @@ 

              self.assertEqual(output.status_code, 200)

              data = json.loads(output.data)

              data['date_created'] = '1496338274'

+             data['date_modified'] = '1496338274'

              expected_output = {

                  "access_groups": {

                      "admin": [],
@@ -1128,6 +1156,7 @@ 

                  ],

                  "custom_keys": [],

                  "date_created": "1496338274",

+                 "date_modified": "1496338274",

                  "description": "test project #1",

                  "fullname": "test",

                  "id": 1,

@@ -1021,6 +1021,7 @@ 

              self.assertEqual(output.status_code, 200)

              data = json.loads(output.get_data(as_text=True))

              data['projects'][0]['date_created'] = "1436527638"

+             data['projects'][0]['date_modified'] = "1436527638"

              self.assertDictEqual(

                  data,

                  {
@@ -1053,6 +1054,7 @@ 

                              "close_status": [],

                              "custom_keys": [],

                              "date_created": "1436527638",

+                             "date_modified": "1436527638",

                              "description": "test project description",

                              "id": 1,

                              "milestones": {},
@@ -1075,6 +1077,7 @@ 

              self.assertEqual(output.status_code, 200)

              data = json.loads(output.get_data(as_text=True))

              data['projects'][0]['date_created'] = "1436527638"

+             data['projects'][0]['date_modified'] = "1436527638"

              self.assertDictEqual(

                  data,

                  {
@@ -1106,6 +1109,7 @@ 

                              "close_status": [],

                              "custom_keys": [],

                              "date_created": "1436527638",

+                             "date_modified": "1436527638",

                              "description": "test project description",

                              "id": 1,

                              "milestones": {},
@@ -1181,7 +1185,9 @@ 

              data['requests'][0]['date_created'] = '1431414800'

              data['requests'][0]['updated_on'] = '1431414800'

              data['requests'][0]['project']['date_created'] = '1431414800'

+             data['requests'][0]['project']['date_modified'] = '1431414800'

              data['requests'][0]['repo_from']['date_created'] = '1431414800'

+             data['requests'][0]['repo_from']['date_modified'] = '1431414800'

              data['requests'][0]['uid'] = '1431414800'

              data['requests'][0]['last_updated'] = '1431414800'

              self.assertDictEqual(
@@ -1223,6 +1229,7 @@ 

                                  "close_status": [],

                                  "custom_keys": [],

                                  "date_created": "1431414800",

+                                 "date_modified": "1431414800",

                                  "description": "test project description",

                                  "id": 1,

                                  "milestones": {},
@@ -1255,6 +1262,7 @@ 

                                  "close_status": [],

                                  "custom_keys": [],

                                  "date_created": "1431414800",

+                                 "date_modified": "1431414800",

                                  "description": "test project description",

                                  "id": 1,

                                  "milestones": {},
@@ -1292,7 +1300,9 @@ 

              data2['requests'][0]['date_created'] = '1431414800'

              data2['requests'][0]['updated_on'] = '1431414800'

              data2['requests'][0]['project']['date_created'] = '1431414800'

+             data2['requests'][0]['project']['date_modified'] = '1431414800'

              data2['requests'][0]['repo_from']['date_created'] = '1431414800'

+             data2['requests'][0]['repo_from']['date_modified'] = '1431414800'

              data2['requests'][0]['uid'] = '1431414800'

              data2['requests'][0]['last_updated'] = '1431414800'

              self.assertDictEqual(data, data2)
@@ -1304,7 +1314,9 @@ 

              data['date_created'] = '1431414800'

              data['updated_on'] = '1431414800'

              data['project']['date_created'] = '1431414800'

+             data['project']['date_modified'] = '1431414800'

              data['repo_from']['date_created'] = '1431414800'

+             data['repo_from']['date_modified'] = '1431414800'

              data['uid'] = '1431414800'

              data['last_updated'] = '1431414800'

              self.assertDictEqual(
@@ -1339,6 +1351,7 @@ 

                          "close_status": [],

                          "custom_keys": [],

                          "date_created": "1431414800",

+                         "date_modified": "1431414800",

                          "description": "test project description",

                          "id": 1,

                          "milestones": {},
@@ -1371,6 +1384,7 @@ 

                          "close_status": [],

                          "custom_keys": [],

                          "date_created": "1431414800",

+                         "date_modified": "1431414800",

                          "description": "test project description",

                          "id": 1,

                          "milestones": {},
@@ -1404,7 +1418,9 @@ 

              data2 = json.loads(output.get_data(as_text=True))

              data2['date_created'] = '1431414800'

              data2['project']['date_created'] = '1431414800'

+             data2['project']['date_modified'] = '1431414800'

              data2['repo_from']['date_created'] = '1431414800'

+             data2['repo_from']['date_modified'] = '1431414800'

              data2['uid'] = '1431414800'

              data2['date_created'] = '1431414800'

              data2['updated_on'] = '1431414800'

@@ -88,8 +88,11 @@ 

          self.assertEqual(output.status_code, 200)

          data = json.loads(output.data)

          data['repos'][0]['date_created'] = "1490272832"

+         data['repos'][0]['date_modified'] = "1490272832"

          data['repos'][1]['date_created'] = "1490272832"

+         data['repos'][1]['date_modified'] = "1490272832"

          data['repos'][2]['date_created'] = "1490272832"

+         data['repos'][2]['date_modified'] = "1490272832"

          expected_data = {

              "forks": [],

              "repos": [
@@ -113,6 +116,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1490272832",

+                     "date_modified": "1490272832",

                      "description": "test project #1",

                      "fullname": "test",

                      "id": 1,
@@ -160,6 +164,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1490272832",

+                     "date_modified": "1490272832",

                      "description": "test project #2",

                      "fullname": "test2",

                      "id": 2,
@@ -206,6 +211,7 @@ 

                      ],

                      "custom_keys": [],

                      "date_created": "1490272832",

+                     "date_modified": "1490272832",

                      "description": "namespaced test project",

                      "fullname": "somenamespace/test3",

                      "id": 3,

file modified
+7 -2
@@ -1850,7 +1850,7 @@ 

  index 0000000..60f7480

  --- /dev/null

  +++ b/456

- @@ -0,0 +1,126 @@

+ @@ -0,0 +1,128 @@

  +{

  +    "assignee": null,

  +    "branch": "master",
@@ -1881,6 +1881,7 @@ 

  +        "close_status": [],

  +        "custom_keys": [],

  +        "date_created": null,

+ +        "date_modified": null,

  +        "description": "test project for ticket",

  +        "fullname": "test_ticket_repo",

  +        "id": 1,
@@ -1931,6 +1932,7 @@ 

  +        "close_status": [],

  +        "custom_keys": [],

  +        "date_created": null,

+ +        "date_modified": null,

  +        "description": "test project for ticket",

  +        "fullname": "test_ticket_repo",

  +        "id": 1,
@@ -1998,6 +2000,9 @@ 

              elif 'date_created' in row:

                  t = row.split(': ')[0]

                  row = '%s: null,' % t

+             elif 'date_modified' in row:

+                 t = row.split(': ')[0]

+                 row = '%s: null,' % t

              elif 'last_updated' in row:

                  t = row.split(': ')[0]

                  row = '%s: null,' % t
@@ -2010,7 +2015,7 @@ 

                  row = '+++ b/456'

              npatch.append(row)

          patch = '\n'.join(npatch)

-         # print patch

+         print patch

          self.assertEqual(patch, exp)

  

      def test_update_ticket_from_git_no_priority(self):

This commit add the date_modified timestamp to the projects API,
the date_modified timestamp is updated whenever the project's settings,
project's group settings or the project's user settings are modified.

Fixes #2412

Signed-off-by: Clement Verna cverna@tutanota.com

this shouldn't work because existing projects don't have date_modified and the field is non-nullable

rebased

7 years ago

For PEP-8 the imports should be above the revision and down_revision variables.

You can probably fix this in the alembic template, so that it does it this way by default in the future.

rebased

7 years ago

Updated to make pep8 happy :smile:

rebased

7 years ago

Some of the tests are failing here, I'll fix them before merging

rebased

7 years ago

Pull-Request has been merged by pingou

7 years ago