Updated_at content modified

updated_at field in projects table now contains a date that signifies the most
recent date a task or story related to the project was last updated/created.
Task: 24368

Change-Id: I03f387a86c7a34e5bf4d653746df535e68813495
This commit is contained in:
Ivoline Ngong 2019-02-23 15:54:49 +03:00
parent 8ab5143cb1
commit 27dbfe207d
3 changed files with 40 additions and 3 deletions

View File

@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import pytz
from storyboard.common.master_branch_helper import MasterBranchHelper
from storyboard.db.api import base as api_base
from storyboard.db.api import branches as branches_api
@ -94,6 +97,16 @@ def project_update(project_id, values):
return api_base.entity_update(models.Project, project_id, values)
def project_update_updated_at(project_id):
session = api_base.get_session()
project = project_get(project_id)
if project:
with session.begin(subtransactions=True):
project.updated_at = datetime.datetime.now(tz=pytz.utc)
session.add(project)
session.expunge(project)
def project_build_query(project_group_id, **kwargs):
# Construct the query
query = api_base.model_query(models.Project)

View File

@ -21,6 +21,7 @@ from sqlalchemy.orm import subqueryload
from storyboard._i18n import _
from storyboard.common import exception as exc
from storyboard.db.api import base as api_base
from storyboard.db.api import projects as projects_api
from storyboard.db.api import story_tags
from storyboard.db.api import story_types
from storyboard.db.api import teams as teams_api
@ -77,7 +78,6 @@ def story_get_all(title=None, description=None, status=None, assignee_id=None,
sort_field = 'id'
if not sort_dir:
sort_dir = 'asc'
if not isinstance(status, list) and status is not None:
status = [status]
@ -253,12 +253,29 @@ def story_create(values):
def story_update(story_id, values, current_user=None):
api_base.entity_update(models.Story, story_id, values)
project_ids = get_project_ids(story_id, current_user=current_user)
for project_id in project_ids:
projects_api.project_update_updated_at(project_id)
return story_get(story_id, current_user=current_user)
def get_project_ids(story_id, current_user=None):
session = api_base.get_session()
with session.begin(subtransactions=True):
story = story_get_simple(story_id, session=session,
current_user=current_user)
if not story:
raise exc.NotFound(_("%(name)s not found") %
{'name': "Story"})
project_ids = {task.project_id for task in story.tasks}
session.expunge(story)
return project_ids
def story_update_updated_at(story_id):
session = api_base.get_session()
with session.begin(subtransactions=True):
story = story_get_simple(story_id, session=session,
no_permissions=True)
@ -293,6 +310,7 @@ def story_add_tag(story_id, tag_name, current_user=None):
story.tags.append(tag)
story.updated_at = datetime.datetime.now(tz=pytz.utc)
session.add(story)
session.expunge(story)

View File

@ -14,6 +14,7 @@
# limitations under the License.
from storyboard.db.api import base as api_base
from storyboard.db.api import projects as projects_api
from storyboard.db.api import stories as stories_api
from storyboard.db import models
@ -66,14 +67,17 @@ def task_create(values):
if task:
stories_api.story_update_updated_at(task.story_id)
# Update updated_at in projects when task is created
projects_api.project_update_updated_at(task.project_id)
return task
def task_update(task_id, values):
task = api_base.entity_update(models.Task, task_id, values)
if task:
stories_api.story_update_updated_at(task.story_id)
# Update updated_at in projects when task is updated
projects_api.project_update_updated_at(task.project_id)
return task
@ -82,6 +86,8 @@ def task_delete(task_id):
if task:
stories_api.story_update_updated_at(task.story_id)
# Update updated_at in projects when task/story is deleted
projects_api.project_update_updated_at(task.project_id)
api_base.entity_hard_delete(models.Task, task_id)