Skip to content

Commit

Permalink
variable naming changed
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmi2506 committed Jan 31, 2024
1 parent 03f5252 commit f7e9e48
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 44 deletions.
5 changes: 3 additions & 2 deletions docs/api/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ components:
type: string
format: HashID
readOnly: true
metadatatype_changes:
non_source_changes:
type: object
additionalProperties: {}
readOnly: true
Expand Down Expand Up @@ -2594,9 +2594,10 @@ components:
has_unsaved_changes:
type: boolean
readOnly: true
has_metadatatype_changes:
has_non_source_changes:
type: boolean
readOnly: true
nullable: true
ignored_changes:
type: object
additionalProperties: {}
Expand Down
44 changes: 29 additions & 15 deletions metecho/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
ExtractRulesFile,
flatten_declarations,
)
from collections import defaultdict
from cumulusci.tasks.salesforce.nonsourcetracking import ListComponents, ListNonSourceTrackable
from cumulusci.core.config import TaskConfig
from cumulusci.core.runtime import BaseCumulusCI
from cumulusci.salesforce_api.org_schema import Field, Filters, Schema, get_org_schema
from cumulusci.salesforce_api.utils import get_simple_salesforce_connection
from cumulusci.tasks.github.util import CommitDir
from cumulusci.tasks.salesforce.nonsourcetracking import (
ListComponents,
ListNonSourceTrackable,
)
from cumulusci.tasks.vlocity.vlocity import VlocityRetrieveTask
from cumulusci.utils import temporary_dir
from cumulusci.utils.http.requests_utils import safe_json_from_response
Expand Down Expand Up @@ -276,7 +277,7 @@ def create_repository(

else:
repo = org.create_repository(
project.repo_name, description=project.description, private= True
project.repo_name, description=project.description, private=True
)
team.add_repository(repo.full_name, permission="push")
project.repo_id = repo.id
Expand Down Expand Up @@ -605,6 +606,7 @@ def refresh_scratch_org(scratch_org, *, originating_user_id):

refresh_scratch_org_job = job(refresh_scratch_org)


def get_unsaved_changes(scratch_org, *, originating_user_id):
try:
scratch_org.refresh_from_db()
Expand All @@ -624,14 +626,14 @@ def get_unsaved_changes(scratch_org, *, originating_user_id):
)
scratch_org.unsaved_changes = unsaved_changes
with dataset_env(scratch_org) as (project_config, org_config, sf, schema, repo):
components=ListNonSourceTrackable(
components = ListNonSourceTrackable(
org_config=org_config,
project_config=project_config,
task_config=TaskConfig({"options":{}}),
task_config=TaskConfig({"options": {}}),
)()
scratch_org.metadatatype_changes= {}
scratch_org.non_source_changes = {}
for types in components:
scratch_org.metadatatype_changes[types]=[]
scratch_org.non_source_changes[types] = []
except Exception as e:
scratch_org.refresh_from_db()
scratch_org.finalize_get_unsaved_changes(
Expand All @@ -644,29 +646,41 @@ def get_unsaved_changes(scratch_org, *, originating_user_id):
scratch_org.finalize_get_unsaved_changes(
originating_user_id=originating_user_id
)


get_unsaved_changes_job = job(get_unsaved_changes)

def get_nonsource_components(*,scratch_org,desiredType,originating_user_id):

def get_nonsource_components(*, scratch_org, desiredType, originating_user_id):
try:
scratch_org.refresh_from_db()
with dataset_env(scratch_org) as (project_config, org_config, sf, schema, repo):
components=ListComponents(
components = ListComponents(
org_config=org_config,
project_config=project_config,
task_config=TaskConfig({"options":{"metadata_types":desiredType}}),
task_config=TaskConfig({"options": {"metadata_types": desiredType}}),
)()

scratch_org.metadatatype_changes[desiredType]=[cmp["MemberName"] for cmp in components]
scratch_org.non_source_changes[desiredType] = [
cmp["MemberName"] for cmp in components
]
except Exception as e:
scratch_org.refresh_from_db()

scratch_org.finalize_get_nonsource_components(
error=e, originating_user_id=originating_user_id
)
tb = traceback.format_exc()
logger.error(tb)
raise
else:
scratch_org.finalize_get_nonsource_components(
originating_user_id=originating_user_id
)


get_nonsource_components_job = job(get_nonsource_components)


def commit_changes_from_org(
*,
scratch_org,
Expand Down Expand Up @@ -712,9 +726,9 @@ def commit_changes_from_org(
latest_revision_numbers = get_latest_revision_numbers(
scratch_org, originating_user_id=originating_user_id
)
member_types= list(desired_changes.keys())
member_types = list(desired_changes.keys())
for member_type in member_types:
if member_type in scratch_org.metadatatype_changes:
if member_type in scratch_org.non_source_changes:
del desired_changes[member_type]
for member_type in desired_changes.keys():
for member_name in desired_changes[member_type]:
Expand Down
13 changes: 9 additions & 4 deletions metecho/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ class ScratchOrg(
unsaved_changes = models.JSONField(
default=dict, encoder=DjangoJSONEncoder, blank=True
)
metadatatype_changes = models.JSONField(
non_source_changes = models.JSONField(
default=dict, encoder=DjangoJSONEncoder, blank=True
)
ignored_changes = models.JSONField(
Expand Down Expand Up @@ -1475,12 +1475,17 @@ def queue_get_unsaved_changes(self, *, force_get=False, originating_user_id):

get_unsaved_changes_job.delay(self, originating_user_id=originating_user_id)

def queue_get_nonsource_components(self,*,originating_user_id,desiredType: str):
def queue_get_nonsource_components(self, *, originating_user_id, desiredType: str):
from .jobs import get_nonsource_components_job

self.currently_refreshing_changes = True
self.save()
self.notify_changed(originating_user_id=originating_user_id)
get_nonsource_components_job.delay(scratch_org=self,desiredType=desiredType,originating_user_id=originating_user_id)
get_nonsource_components_job.delay(
scratch_org=self,
desiredType=desiredType,
originating_user_id=originating_user_id,
)

def finalize_get_unsaved_changes(self, *, error=None, originating_user_id):
self.currently_refreshing_changes = False
Expand All @@ -1497,7 +1502,7 @@ def finalize_get_unsaved_changes(self, *, error=None, originating_user_id):
originating_user_id=originating_user_id,
)

def finalize_get_nonsource_components(self,*,error=None,originating_user_id):
def finalize_get_nonsource_components(self, *, error=None, originating_user_id):
self.currently_refreshing_changes = False
if error is None:
self.save()
Expand Down
18 changes: 10 additions & 8 deletions metecho/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,8 @@ class ScratchOrgSerializer(HashIdModelSerializer):
description_rendered = MarkdownField(source="description", read_only=True)
unsaved_changes = serializers.SerializerMethodField()
has_unsaved_changes = serializers.SerializerMethodField()
metadatatype_changes = serializers.SerializerMethodField()
has_metadatatype_changes = serializers.SerializerMethodField()
non_source_changes = serializers.SerializerMethodField()
has_non_source_changes = serializers.SerializerMethodField()
total_unsaved_changes = serializers.SerializerMethodField()
ignored_changes = serializers.SerializerMethodField()
has_ignored_changes = serializers.SerializerMethodField()
Expand Down Expand Up @@ -1051,8 +1051,8 @@ class Meta:
"currently_retrieving_omnistudio",
"installed_packages",
"is_omnistudio_installed",
"metadatatype_changes",
"has_metadatatype_changes",
"non_source_changes",
"has_non_source_changes",
)
extra_kwargs = {
"last_modified_at": {"read_only": True},
Expand Down Expand Up @@ -1093,14 +1093,14 @@ def _total_X_changes(self, obj, kind) -> int:
def get_unsaved_changes(self, obj) -> dict:
return self._X_changes(obj, "unsaved")

def get_metadatatype_changes(self,obj) -> dict:
return self._X_changes(obj, "metadatatype")
def get_non_source_changes(self, obj) -> dict:
return self._X_changes(obj, "non_source")

def get_has_unsaved_changes(self, obj) -> bool:
return self._has_X_changes(obj, "unsaved")

def get_has_metadatatype_changes(self,obj) ->bool:
return self._has_X_changes(obj,"metadatatype")
def get_has_non_source_changes(self, obj) -> bool:
return self._has_X_changes(obj, "non_source")

def get_total_unsaved_changes(self, obj) -> int:
return self._total_X_changes(obj, "unsaved")
Expand Down Expand Up @@ -1152,9 +1152,11 @@ class CommitSerializer(serializers.Serializer):
changes = serializers.DictField(child=StringListField())
target_directory = serializers.CharField()


class ListMetadataSerializer(serializers.Serializer):
desiredType = serializers.CharField()


class CommitDatasetSerializer(serializers.Serializer):
commit_message = serializers.CharField()
dataset_name = serializers.CharField()
Expand Down
21 changes: 14 additions & 7 deletions metecho/api/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging

from django.contrib.auth import get_user_model
from django.contrib.sites.shortcuts import get_current_site
from django.db.models import Case, IntegerField, Q, When
Expand Down Expand Up @@ -52,7 +53,6 @@
CanReassignSerializer,
CheckRepoNameSerializer,
CommitDatasetSerializer,
ListMetadataSerializer,
CommitOmniStudioSerializer,
CommitSerializer,
CreatePrSerializer,
Expand All @@ -63,6 +63,7 @@
GitHubIssueSerializer,
GitHubOrganizationSerializer,
GuidedTourSerializer,
ListMetadataSerializer,
MinimalUserSerializer,
ProjectCreateSerializer,
ProjectDependencySerializer,
Expand All @@ -77,6 +78,7 @@
User = get_user_model()
logger = logging.getLogger()


class RepoPushPermission(BasePermission):
"""
Require repository Push permission for all actions other than list/detail.
Expand Down Expand Up @@ -706,21 +708,26 @@ def commit_dataset(self, request, pk=None):
self.get_serializer(scratch_org).data, status=status.HTTP_202_ACCEPTED
)

@extend_schema(request= ListMetadataSerializer, responses={202: ScratchOrgSerializer})
@extend_schema(
request=ListMetadataSerializer, responses={202: ScratchOrgSerializer}
)
@action(detail=True, methods=["POST"])
def listmetadata(self,request,pk=None):
def listmetadata(self, request, pk=None):
serializer = ListMetadataSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
scratch_org= self.get_object()
scratch_org = self.get_object()
if not request.user == scratch_org.owner:
return Response(
{"error": _("Requesting user did not create Org.")},
status=status.HTTP_403_FORBIDDEN,
)
scratch_org.queue_get_nonsource_components(desiredType=serializer.validated_data["desiredType"],originating_user_id=str(request.user.id))
scratch_org.queue_get_nonsource_components(
desiredType=serializer.validated_data["desiredType"],
originating_user_id=str(request.user.id),
)
return Response(
self.get_serializer(scratch_org).data, status=status.HTTP_202_ACCEPTED
)
self.get_serializer(scratch_org).data, status=status.HTTP_202_ACCEPTED
)

@extend_schema(
request=CommitOmniStudioSerializer, responses={202: ScratchOrgSerializer}
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/tasks/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const TaskDetail = (
orgHasChanges =
(devOrg?.total_unsaved_changes || 0) -
(devOrg?.total_ignored_changes || 0) >
0 || (devOrg?.has_metadatatype_changes)==true;
0 || devOrg?.has_non_source_changes === true;
userIsDevOwner = Boolean(
userIsAssignedDev && devOrg?.is_created && devOrg?.owner === user.id,
);
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/tasks/retrieveMetadata/changes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import Accordion from '@salesforce/design-system-react/components/accordion';
import AccordionPanel from '@salesforce/design-system-react/components/accordion/panel';
import Checkbox from '@salesforce/design-system-react/components/checkbox';
Expand All @@ -8,6 +7,7 @@ import classNames from 'classnames';
import React, { ChangeEvent, RefObject, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';

import {
BooleanObject,
MetadataCommit,
Expand Down
8 changes: 4 additions & 4 deletions src/js/components/tasks/retrieveMetadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const RetrieveMetadataModal = ({ org, isOpen, closeModal }: Props) => {
});

// Separate checked changes into changes/ignored
const { remaining: changesChecked, removed: ignoredChecked} = splitChangeset(
const { remaining: changesChecked, removed: ignoredChecked } = splitChangeset(
inputs.changes,
org.ignored_changes,
);
Expand Down Expand Up @@ -254,10 +254,10 @@ const RetrieveMetadataModal = ({ org, isOpen, closeModal }: Props) => {
errors={errors}
setInputs={setInputs}
ignoredSuccess={isShowingTransientMessage}
hasmetadatachanges={org.has_metadatatype_changes}
metadatachanges={org.metadatatype_changes}
hasmetadatachanges={org.has_non_source_changes}
metadatachanges={org.non_source_changes}
id={org.id}
refreshing= {org.currently_refreshing_changes}
refreshing={org.currently_refreshing_changes}
/>
),
footer: [
Expand Down
4 changes: 2 additions & 2 deletions src/js/store/orgs/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export interface MinimalOrg {
}

export interface Org extends MinimalOrg {
metadatatype_changes: Changeset;
has_metadatatype_changes: boolean;
non_source_changes: Changeset;
has_non_source_changes: boolean;
owner: string | null;
owner_gh_username: string;
owner_gh_id: number | null;
Expand Down

0 comments on commit f7e9e48

Please sign in to comment.