musora-content-services 1.0.178 → 1.0.179

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.179](https://github.com/railroadmedia/musora-content-services/compare/v1.0.178...v1.0.179) (2024-11-19)
6
+
5
7
  ### [1.0.178](https://github.com/railroadmedia/musora-content-services/compare/v1.0.177...v1.0.178) (2024-11-19)
6
8
 
7
9
  ### [1.0.177](https://github.com/railroadmedia/musora-content-services/compare/v1.0.176...v1.0.177) (2024-11-18)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.178",
3
+ "version": "1.0.179",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -86,7 +86,7 @@ let contentTypeConfig = {
86
86
  'fields': [
87
87
  'enrollment_start_time',
88
88
  'enrollment_end_time',
89
- 'registration_url',
89
+ "'registration_url': '/' + brand + '/enrollment/' + slug.current",
90
90
  '"lesson_count": child_count',
91
91
  '"primary_cta_text": select(dateTime(published_on) > dateTime(now()) && dateTime(enrollment_start_time) > dateTime(now()) => "Notify Me", "Start Challenge")',
92
92
  'challenge_state',
@@ -4,6 +4,10 @@ import {fetchUserPermissions} from "./services/userPermissions";
4
4
  export class FilterBuilder {
5
5
 
6
6
  STATUS_SCHEDULED = 'scheduled';
7
+ STATUS_PUBLISHED = 'published';
8
+ STATUS_DRAFT = 'draft';
9
+ STATUS_ARCHIVED = 'archived';
10
+ STATUS_UNLISTED = 'unlisted';
7
11
 
8
12
  constructor(
9
13
  filter = '',
@@ -13,13 +17,18 @@ export class FilterBuilder {
13
17
  pullFutureContent = false,
14
18
  getFutureContentOnly = false,
15
19
  getFutureScheduledContentsOnly = false,
16
-
20
+ bypassStatuses = false,
21
+ bypassPublishedDateRestriction = false,
22
+ isSingle = false
17
23
  } = {}) {
18
24
  this.availableContentStatuses = availableContentStatuses;
19
25
  this.bypassPermissions = bypassPermissions;
26
+ this.bypassStatuses = bypassStatuses;
27
+ this.bypassPublishedDateRestriction = bypassPublishedDateRestriction;
20
28
  this.pullFutureContent = pullFutureContent;
21
29
  this.getFutureContentOnly = getFutureContentOnly;
22
30
  this.getFutureScheduledContentsOnly = getFutureScheduledContentsOnly;
31
+ this.isSingle = isSingle;
23
32
  this.filter = filter;
24
33
  // this.debug = process.env.DEBUG === 'true' || false;
25
34
  this.debug = false;
@@ -48,7 +57,17 @@ export class FilterBuilder {
48
57
 
49
58
  _applyContentStatuses() {
50
59
  // This must be run before _applyPublishDateRestrictions()
51
- if (this.availableContentStatuses.length === 0) return this;
60
+ if(this.bypassStatuses) return this;
61
+ if (this.availableContentStatuses.length === 0) {
62
+ if (this.userData.isAdmin) {
63
+ this.availableContentStatuses = [this.STATUS_DRAFT, this.STATUS_SCHEDULED, this.STATUS_PUBLISHED, this.STATUS_ARCHIVED, this.STATUS_UNLISTED];
64
+ } else if(this.isSingle){
65
+ this.availableContentStatuses = [this.STATUS_SCHEDULED, this.STATUS_PUBLISHED, this.STATUS_UNLISTED, this.STATUS_ARCHIVED];
66
+ } else{
67
+ this.availableContentStatuses = [this.STATUS_SCHEDULED, this.STATUS_PUBLISHED];
68
+ }
69
+ }
70
+
52
71
  // I'm not sure if I'm 100% on this logic, but this is my intepretation of the ContentRepository logic
53
72
  if (this.getFutureScheduledContentsOnly && this.availableContentStatuses.includes(this.STATUS_SCHEDULED)) {
54
73
  // we must pull in future content here, otherwise we'll restrict on content this is published in the past and remove any scheduled content
@@ -77,6 +96,7 @@ export class FilterBuilder {
77
96
  }
78
97
 
79
98
  _applyPublishingDateRestrictions() {
99
+ if(this.bypassPublishedDateRestriction) return this;
80
100
  const now = new Date().toISOString();
81
101
  if (this.getFutureContentOnly) {
82
102
  this._andWhere(`published_on >= '${now}'`);
@@ -510,6 +510,7 @@ export async function fetchAll(brand, type, {
510
510
  let webUrlPathType = config?.slug ?? type;
511
511
  const start = (page - 1) * limit;
512
512
  const end = start + limit;
513
+ let bypassStatusAndPublishedValidation = (type == 'instructor');
513
514
 
514
515
  // Construct the type filter
515
516
  const typeFilter = type ? `&& _type == '${type}'` : "";
@@ -574,8 +575,10 @@ export async function fetchAll(brand, type, {
574
575
  filter = `brand == "${brand}" ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}`
575
576
  entityFieldsString = fieldsString;
576
577
  }
578
+
579
+ const filterWithRestrictions = await new FilterBuilder(filter,{bypassStatuses:bypassStatusAndPublishedValidation, bypassPermissions: bypassStatusAndPublishedValidation, bypassPublishedDateRestriction: bypassStatusAndPublishedValidation} ).buildFilter();
577
580
  query = buildEntityAndTotalQuery(
578
- filter,
581
+ filterWithRestrictions,
579
582
  entityFieldsString,
580
583
  {
581
584
  sortOrder: sortOrder,
@@ -990,7 +993,7 @@ export async function fetchNextPreviousLesson(railcontentId) {
990
993
  * .catch(error => console.error(error));
991
994
  */
992
995
  export async function fetchLessonContent(railContentId) {
993
- const filterParams = {};
996
+ const filterParams = {isSingle:true};
994
997
  // Format changes made to the `fields` object may also need to be reflected in Musora-web-platform SanityGateway.php $fields object
995
998
  // Currently only for challenges and challenge lessons
996
999
  // If you're unsure, message Adrian, or just add them.
@@ -630,13 +630,16 @@ describe('Filter Builder', function () {
630
630
  let finalFilter = await builder.buildFilter(filter);
631
631
  let clauses = spliceFilterForAnds(finalFilter);
632
632
  expect(clauses[0].phrase).toBe(filter);
633
- expect(clauses[1].field).toBe('published_on');
633
+ expect(clauses[1].field).toBe('status');
634
+ expect(clauses[2].field).toBe('published_on');
634
635
 
635
636
  builder = new FilterBuilder('', {bypassPermissions: true});
636
637
  finalFilter = await builder.buildFilter(filter);
637
638
  clauses = spliceFilterForAnds(finalFilter);
638
- expect(clauses[0].field).toBe('published_on');
639
- expect(clauses[0].operator).toBe('<=');
639
+ expect(clauses[0].field).toBe('status');
640
+ expect(clauses[0].operator).toBe('in');
641
+ expect(clauses[1].field).toBe('published_on');
642
+ expect(clauses[1].operator).toBe('<=');
640
643
  });
641
644
 
642
645
  test('withOnlyFilterAvailableStatuses', async () => {
@@ -665,8 +668,6 @@ describe('Filter Builder', function () {
665
668
  expect(clauses[1].operator).toBe('in');
666
669
  // getFutureScheduledContentsOnly doesn't make a filter that's splicable, so we match on the more static string
667
670
  const expected = "['published','unlisted'] || (status == 'scheduled' && published_on >=";
668
- console.log(clauses[1].condition);
669
- console.log(expected)
670
671
  const isMatch = finalFilter.includes(expected);
671
672
  expect(isMatch).toBeTruthy();
672
673
  });
@@ -701,7 +702,9 @@ describe('Filter Builder', function () {
701
702
  expect(isMatch).toBeFalsy();
702
703
  const clauses = spliceFilterForAnds(finalFilter);
703
704
  expect(clauses[0].field).toBe('railcontent_id');
704
- expect(clauses[1].field).toBe('published_on');
705
+ expect(clauses[1].field).toBe('status');
706
+ expect(clauses[2].field).toBe('published_on');
707
+
705
708
  });
706
709
 
707
710
 
@@ -717,10 +720,11 @@ describe('Filter Builder', function () {
717
720
  let finalFilter = await builder.buildFilter();
718
721
  let clauses = spliceFilterForAnds(finalFilter);
719
722
  expect(clauses[0].phrase).toBe(filter);
720
-
721
- expect(clauses[1].field).toBe('published_on');
722
- expect(clauses[1].operator).toBe('<=');
723
- const restrictionDate = new Date(clauses[1].condition)
723
+ expect(clauses[1].field).toBe('status');
724
+ expect(clauses[1].operator).toBe('in');
725
+ expect(clauses[2].field).toBe('published_on');
726
+ expect(clauses[2].operator).toBe('<=');
727
+ const restrictionDate = new Date(clauses[2].condition)
724
728
  const now = new Date();
725
729
  expect(now.getTime()).toBeLessThan(restrictionDate.getTime());
726
730
 
@@ -732,8 +736,8 @@ describe('Filter Builder', function () {
732
736
  finalFilter = await builder.buildFilter();
733
737
  clauses = spliceFilterForAnds(finalFilter);
734
738
  expect(clauses[0].phrase).toBe(filter);
735
- expect(clauses[1].field).toBe('published_on');
736
- expect(clauses[1].operator).toBe('>=');
739
+ expect(clauses[2].field).toBe('published_on');
740
+ expect(clauses[2].operator).toBe('>=');
737
741
  });
738
742
 
739
743
  function spliceFilterForAnds(filter) {