Skip to content

Commit

Permalink
Merge pull request #187 from openedx/saleem-latif/ENT-7622
Browse files Browse the repository at this point in the history
ENT-7622: Removed direct usages objects in favour of whitelisted or blacklisted query sets.
  • Loading branch information
saleem-latif authored Oct 24, 2023
2 parents c35fa23 + 31c4dce commit 14f72dc
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Change Log
Unreleased

[1.46.0] - 2023-10-23
---------------------
* feat: Removed direct usages of JobSkills and IndustryJobSkills objects in favour of whitelisted or blacklisted query sets.

[1.45.0] - 2023-10-13
---------------------
* feat: Added the ability to blacklist job-skill relationship.
Expand Down
2 changes: 1 addition & 1 deletion taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# 2. MINOR version when you add functionality in a backwards compatible manner, and
# 3. PATCH version when you make backwards compatible bug fixes.
# More details can be found at https://semver.org/
__version__ = '1.45.0'
__version__ = '1.46.0'

default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name
10 changes: 7 additions & 3 deletions taxonomy/algolia/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def get_skills(self, obj):
obj (Job): Job instance whose skills need to be fetched.
"""
# We only need to fetch up-to 20 skills per job.
qs = JobSkills.objects.filter(job=obj).select_related('skill')[:EMBEDDED_OBJECT_LENGTH_CAP]
qs = JobSkills.get_whitelisted_job_skill_qs().filter(
job=obj
).select_related(
'skill'
)[:EMBEDDED_OBJECT_LENGTH_CAP]
serializer = JobSkillSerializer(qs, many=True)
return serializer.data

Expand All @@ -97,7 +101,7 @@ def get_industry_names(self, obj):
obj (Job): Job instance whose industries need to be fetched.
"""
return list(
IndustryJobSkill.objects.filter(
IndustryJobSkill.get_whitelisted_job_skill_qs().filter(
job=obj
).order_by(
'industry__name'
Expand All @@ -114,7 +118,7 @@ def get_industries(self, obj):
"""
industries = []
job_industries = list(
IndustryJobSkill.objects.filter(
IndustryJobSkill.get_whitelisted_job_skill_qs().filter(
job=obj
).order_by(
'industry__name'
Expand Down
8 changes: 4 additions & 4 deletions taxonomy/algolia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def calculate_job_skills(jobs_qs):
job_details = {}
for job in jobs_qs.all():
skills = set(
JobSkills.objects.filter(job=job).values_list('skill__name', flat=True)
JobSkills.get_whitelisted_job_skill_qs().filter(job=job).values_list('skill__name', flat=True)
)
job_details[job.name] = {
'skills': skills,
Expand Down Expand Up @@ -207,7 +207,7 @@ def combine_industry_skills():
for industry in Industry.objects.all():
# sum all significances for the same skill and then sort on total significance
skills = list(
IndustryJobSkill.objects.filter(
IndustryJobSkill.get_whitelisted_job_skill_qs().filter(
industry=industry
).values_list(
'skill__name', flat=True
Expand Down Expand Up @@ -262,8 +262,8 @@ def fetch_jobs_data():
context={
'jobs_data': jobs_data,
'industry_skills': industry_skills,
'jobs_having_job_skills': get_job_ids(JobSkills.objects),
'jobs_having_industry_skills': get_job_ids(IndustryJobSkill.objects),
'jobs_having_job_skills': get_job_ids(JobSkills.get_whitelisted_job_skill_qs()),
'jobs_having_industry_skills': get_job_ids(IndustryJobSkill.get_whitelisted_job_skill_qs()),
},
)
jobs.extend(job_serializer.data)
Expand Down
11 changes: 10 additions & 1 deletion taxonomy/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,22 @@ class Meta:


class JobsListSerializer(ModelSerializer):
skills = JobSkillSerializer(source='jobskills_set.all', many=True)
skills = serializers.SerializerMethodField()

class Meta:
model = Job
fields = '__all__'
extra_fields = ('skills',)

def get_skills(self, instance):
"""
Get JobSkill records.
"""
return JobSkillSerializer(
JobSkills.get_whitelisted_job_skill_qs().filter(job=instance),
many=True,
).data


class CourseSkillsSerializer(ModelSerializer):

Expand Down
2 changes: 1 addition & 1 deletion taxonomy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def get_course_jobs(course_key, product_type=ProductTypes.Course):
list: A list of dicts where each dict contain information about a particular job.
"""
course_skills = get_whitelisted_product_skills(course_key, product_type)
job_skills = JobSkills.objects.select_related(
job_skills = JobSkills.get_whitelisted_job_skill_qs().select_related(
'skill',
'job',
'job__jobpostings',
Expand Down

0 comments on commit 14f72dc

Please sign in to comment.