chore: handled the tirage state forn intake (#4928)
This commit is contained in:
@@ -30,7 +30,13 @@ from .intake import (
|
||||
from .issues import get_issue_stats_count_async
|
||||
from .page import is_shared_page_feature_flagged, is_shared_page_feature_flagged_async
|
||||
from .project import _get_project, get_project, get_project_member
|
||||
from .state import get_project_default_state
|
||||
from .state import (
|
||||
get_project_default_state,
|
||||
get_project_triage_states,
|
||||
get_project_triage_states_async,
|
||||
get_triage_state,
|
||||
get_triage_state_async,
|
||||
)
|
||||
from .teamspace import (
|
||||
is_teamspace_enabled,
|
||||
is_teamspace_enabled_async,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
# Third Party Imports
|
||||
# Strawberry Imports
|
||||
from asgiref.sync import sync_to_async
|
||||
|
||||
# Strawberry Imports
|
||||
from strawberry.exceptions import GraphQLError
|
||||
|
||||
# Module Imports
|
||||
from plane.db.models import State
|
||||
from plane.graphql.types.state import StateType
|
||||
|
||||
|
||||
@sync_to_async
|
||||
@@ -35,3 +38,50 @@ def get_state(workspace_slug: str, project_id: str, state_id: str):
|
||||
Get the state for the given project and state id
|
||||
"""
|
||||
return State.objects.get(workspace__slug=workspace_slug, project_id=project_id, id=state_id)
|
||||
|
||||
|
||||
# project triage states for intake
|
||||
def get_project_triage_states(workspace_slug: str, project_id: str) -> list[StateType]:
|
||||
"""
|
||||
Get the triage states for the given project
|
||||
"""
|
||||
try:
|
||||
project_triage_states = State.triage_objects.filter(workspace__slug=workspace_slug, project_id=project_id)
|
||||
return list(project_triage_states)
|
||||
except State.DoesNotExist:
|
||||
return []
|
||||
|
||||
|
||||
@sync_to_async
|
||||
def get_project_triage_states_async(workspace_slug: str, project_id: str) -> list[StateType]:
|
||||
"""
|
||||
Get the triage states for the given project
|
||||
"""
|
||||
project_triage_states = get_project_triage_states(
|
||||
workspace_slug=workspace_slug,
|
||||
project_id=project_id,
|
||||
)
|
||||
|
||||
return project_triage_states
|
||||
|
||||
|
||||
def get_triage_state(workspace_slug: str, project_id: str, state_id: str) -> StateType:
|
||||
"""
|
||||
Get the triage state for the given project and state id
|
||||
"""
|
||||
try:
|
||||
return State.triage_objects.get(workspace__slug=workspace_slug, project_id=project_id, id=state_id)
|
||||
except State.DoesNotExist:
|
||||
message = "Triage state not found"
|
||||
error_extensions = {"code": "NOT_FOUND", "statusCode": 404}
|
||||
raise GraphQLError(message, extensions=error_extensions)
|
||||
|
||||
|
||||
@sync_to_async
|
||||
def get_triage_state_async(workspace_slug: str, project_id: str, state_id: str) -> StateType:
|
||||
"""
|
||||
Get the triage state for the given project and state id
|
||||
"""
|
||||
triage_state = get_triage_state(workspace_slug=workspace_slug, project_id=project_id, state_id=state_id)
|
||||
|
||||
return triage_state
|
||||
|
||||
@@ -22,15 +22,12 @@ from plane.graphql.helpers import (
|
||||
get_intake_async,
|
||||
get_intake_work_item_async,
|
||||
get_project,
|
||||
get_project_default_state,
|
||||
get_project_member,
|
||||
get_project_triage_states_async,
|
||||
get_triage_state_async,
|
||||
get_workspace,
|
||||
is_project_intakes_enabled_async,
|
||||
is_project_settings_enabled_by_settings_key_async,
|
||||
is_project_workflow_enabled,
|
||||
is_workflow_create_allowed,
|
||||
is_workflow_feature_flagged,
|
||||
is_workflow_update_allowed,
|
||||
)
|
||||
from plane.graphql.helpers.teamspace import project_member_filter_via_teamspaces_async
|
||||
from plane.graphql.permissions.project import ProjectPermission, Roles
|
||||
@@ -92,21 +89,14 @@ class IntakeWorkItemMutation:
|
||||
|
||||
# check if the workflow is enabled for the project and the state is not passed
|
||||
if work_item_state_id is None:
|
||||
state = await get_project_default_state(workspace_slug=workspace_slug, project_id=project_id)
|
||||
work_item_state_id = str(state.id)
|
||||
triage_states = await get_project_triage_states_async(workspace_slug=workspace_slug, project_id=project_id)
|
||||
triage_state = triage_states[0]
|
||||
work_item_state_id = str(triage_state.id)
|
||||
else:
|
||||
workflow_feature_flagged = await is_workflow_feature_flagged(user_id=user_id, workspace_slug=workspace_slug)
|
||||
if workflow_feature_flagged:
|
||||
project_workflow_enabled = await is_project_workflow_enabled(
|
||||
workspace_slug=workspace_slug, project_id=project_id
|
||||
)
|
||||
if project_workflow_enabled:
|
||||
await is_workflow_create_allowed(
|
||||
workspace_slug=workspace_slug,
|
||||
project_id=project_id,
|
||||
user_id=user_id,
|
||||
state_id=work_item_state_id,
|
||||
)
|
||||
triage_state = await get_triage_state_async(
|
||||
workspace_slug=workspace_slug, project_id=project_id, state_id=work_item_state_id
|
||||
)
|
||||
work_item_state_id = str(triage_state.id)
|
||||
|
||||
# get the issue type
|
||||
work_item_type = await default_work_item_type(workspace_slug=slug, project_id=project)
|
||||
@@ -331,18 +321,10 @@ class IntakeWorkItemMutation:
|
||||
activity_payload["parent_id"] = provided_fields["parent"]
|
||||
current_activity_payload["parent_id"] = current_intake_work_item_activity["parent_id"]
|
||||
|
||||
# validate the workflow if the project has workflows enabled
|
||||
# validate the triage state
|
||||
state_id = provided_fields["state"] if "state" in provided_fields else None
|
||||
if state_id:
|
||||
workflow_enabled = await is_workflow_feature_flagged(workspace_slug=workspace_slug, user_id=user_id)
|
||||
if workflow_enabled:
|
||||
await is_workflow_update_allowed(
|
||||
workspace_slug=workspace_slug,
|
||||
project_id=project_id,
|
||||
user_id=user_id,
|
||||
current_state_id=work_item.state_id,
|
||||
new_state_id=state_id,
|
||||
)
|
||||
await get_triage_state_async(workspace_slug=workspace_slug, project_id=project_id, state_id=state_id)
|
||||
|
||||
# updating the intake work item
|
||||
work_item.updated_by_id = user_id
|
||||
|
||||
@@ -13,7 +13,7 @@ from strawberry.types import Info
|
||||
|
||||
# Module imports
|
||||
from plane.graphql.bgtasks.issue_activity_task import issue_activity
|
||||
from plane.db.models import Issue, State, IntakeIssue
|
||||
from plane.db.models import Issue, State, IntakeIssue, StateGroup
|
||||
from plane.graphql.helpers import (
|
||||
get_intake_work_item_async,
|
||||
get_project,
|
||||
@@ -98,7 +98,7 @@ def handle_intake_work_item_status_accept(workspace_slug: str, project_id: str,
|
||||
id=work_item_id,
|
||||
)
|
||||
|
||||
if work_item.state.is_triage:
|
||||
if work_item.state.group == StateGroup.TRIAGE.value:
|
||||
state = State.objects.filter(workspace__slug=workspace_slug, project_id=project_id, default=True).first()
|
||||
|
||||
if state is not None:
|
||||
@@ -115,22 +115,6 @@ def handle_intake_work_item_status_decline(workspace_slug: str, project_id: str,
|
||||
intake_work_item.duplicate_to = None
|
||||
intake_work_item.save()
|
||||
|
||||
work_item_id = intake_work_item.issue_id
|
||||
work_item = Issue.objects.get(
|
||||
workspace__slug=workspace_slug,
|
||||
project_id=project_id,
|
||||
id=work_item_id,
|
||||
)
|
||||
state = State.objects.filter(
|
||||
workspace__slug=workspace_slug,
|
||||
project_id=project_id,
|
||||
group="cancelled",
|
||||
).first()
|
||||
|
||||
if state is not None and work_item is not None:
|
||||
work_item.state = state
|
||||
work_item.save()
|
||||
|
||||
return intake_work_item
|
||||
|
||||
|
||||
@@ -155,22 +139,6 @@ def handle_intake_work_item_status_duplicate(
|
||||
intake_work_item.snoozed_till = None
|
||||
intake_work_item.save()
|
||||
|
||||
work_item_id = intake_work_item.issue_id
|
||||
work_item = Issue.objects.get(
|
||||
workspace__slug=workspace_slug,
|
||||
project_id=project_id,
|
||||
id=work_item_id,
|
||||
)
|
||||
state = State.objects.filter(
|
||||
workspace__slug=workspace_slug,
|
||||
project_id=project_id,
|
||||
group="cancelled",
|
||||
).first()
|
||||
|
||||
if state is not None and work_item is not None:
|
||||
work_item.state = state
|
||||
work_item.save()
|
||||
|
||||
return intake_work_item
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
@@ -48,3 +48,23 @@ class StateQuery:
|
||||
.filter(is_triage=False)
|
||||
)
|
||||
return states
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class TriageStateQuery:
|
||||
@strawberry.field(extensions=[PermissionExtension(permissions=[ProjectBasePermission()])])
|
||||
async def triage_states(self, info: Info, slug: str, project: strawberry.ID) -> list[StateType]:
|
||||
user = info.context.user
|
||||
user_id = str(user.id)
|
||||
|
||||
project_teamspace_filter = await project_member_filter_via_teamspaces_async(
|
||||
user_id=user_id,
|
||||
workspace_slug=slug,
|
||||
)
|
||||
triage_states = await sync_to_async(list)(
|
||||
State.triage_objects.filter(workspace__slug=slug, project_id=project)
|
||||
.filter(project_teamspace_filter.query)
|
||||
.filter(is_triage=False)
|
||||
)
|
||||
|
||||
return triage_states
|
||||
|
||||
@@ -162,7 +162,7 @@ from .queries.page import (
|
||||
from .queries.project import ProjectFeatureQuery, ProjectMembersQuery, ProjectQuery
|
||||
from .queries.roles import UserProjectRolesQuery
|
||||
from .queries.search import GlobalSearchQuery
|
||||
from .queries.state import StateQuery, WorkspaceStateQuery
|
||||
from .queries.state import StateQuery, WorkspaceStateQuery, TriageStateQuery
|
||||
from .queries.stickies import WorkspaceStickiesQuery
|
||||
from .queries.teamspace import TeamspaceMemberQuery
|
||||
from .queries.timezone import TimezoneListQuery
|
||||
@@ -255,6 +255,7 @@ class Query(
|
||||
# state
|
||||
WorkspaceStateQuery,
|
||||
StateQuery,
|
||||
TriageStateQuery,
|
||||
# estimate
|
||||
EstimatePointQuery,
|
||||
# cycle
|
||||
|
||||
Reference in New Issue
Block a user