Skip to content

Commit

Permalink
Merge branch 'authoring-react-post-broadcasting' into unlink-as-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Nov 6, 2023
2 parents 39161ab + 9a8ec9e commit 22f9466
Show file tree
Hide file tree
Showing 260 changed files with 8,656 additions and 5,234 deletions.
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.git
.github
.env
.mypy_cache
.pytest_cache
.vscode
*.egg-info
__pycache__
dist
env
node_modules
client
e2e/node_modules
e2e/server/env
e2e/dist
server/env
3 changes: 0 additions & 3 deletions .fireq.json

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/lint-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install black~=23.0
- run: black --check server

Expand All @@ -16,6 +18,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install flake8
- run: flake8 server

Expand All @@ -24,5 +28,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install -Ur server/mypy-requirements.txt
- run: mypy server
107 changes: 58 additions & 49 deletions client/actions/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {cloneDeep, pick, get, sortBy, findIndex} from 'lodash';
import {Moment} from 'moment';

import {IEventItem, IPlanningItem, IAgenda} from '../interfaces';
import {planningApi} from '../superdeskApi';

import {AGENDA, MODALS, EVENTS} from '../constants';
import {getErrorMessage, gettext, planningUtils, stringUtils} from '../utils';
import {getErrorMessage, gettext, planningUtils} from '../utils';
import {planning, showModal, main} from './index';
import {convertStringFields} from '../utils/strings';

const openAgenda = () => (
(dispatch) => (
Expand Down Expand Up @@ -238,6 +240,48 @@ const addEventToCurrentAgenda = (
}
);

export function convertEventToPlanningItem(event: IEventItem): Partial<IPlanningItem> {
const defaultPlace = selectors.general.defaultPlaceList(planningApi.redux.store.getState());
const defaultValues = planningUtils.defaultPlanningValues(null, defaultPlace);

let newPlanningItem: Partial<IPlanningItem> = {
...defaultValues,
type: 'planning',
event_item: event._id,
planning_date: event._sortDate || event.dates?.start,
place: event.place || defaultPlace,
subject: event.subject,
anpa_category: event.anpa_category,
agendas: [],
language: event.language || defaultValues.language,
languages: event.languages || defaultValues.languages,
};

newPlanningItem = convertStringFields(
event,
newPlanningItem,
'event',
'planning',
[
['slugline', 'slugline'],
['internal_note', 'internal_note'],
['name', 'name'],
['definition_short', 'description_text'],
['ednote', 'ednote'],
],
) as Partial<IPlanningItem>;

if (event.languages != null) {
newPlanningItem.languages = event.languages;
}

if (event.priority != null) {
newPlanningItem.priority = event.priority;
}

return newPlanningItem;
}

/**
* Action dispatcher that creates a planning item from the supplied event,
* @param {object} event - The event used to create the planning item
Expand All @@ -248,54 +292,19 @@ const createPlanningFromEvent = (
event: IEventItem,
planningDate: Moment = null,
agendas: Array<string> = []
) => (
(dispatch) => (
dispatch(planning.api.save({}, {
event_item: event._id,
slugline: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'slugline',
'slugline',
event.slugline
),
planning_date: planningDate || event._sortDate || event.dates.start,
internal_note: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'internal_note',
'internal_note',
event.internal_note
),
name: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'name',
'name',
event.name
),
place: event.place,
subject: event.subject,
anpa_category: event.anpa_category,
description_text: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'definition_short',
'description_text',
event.definition_short
),
ednote: stringUtils.convertStringFieldForProfileFieldType(
'event',
'planning',
'ednote',
'ednote',
event.ednote
),
agendas: agendas,
language: event.language,
}))
)
);
) => {
const newPlanningItem = convertEventToPlanningItem(event);

if (planningDate != null) {
newPlanningItem.planning_date = planningDate;
}

newPlanningItem.agendas = newPlanningItem.agendas.concat(agendas);

return (dispatch) => (
dispatch(planning.api.save({}, newPlanningItem))
);
};

/**
* Action dispatcher that fetches all planning items for the
Expand Down
83 changes: 8 additions & 75 deletions client/actions/assignments/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import {get, cloneDeep, has, pick} from 'lodash';

import {appConfig} from 'appConfig';
import {IAssignmentItem} from '../../interfaces';
import {planningApi} from '../../superdeskApi';

import * as selectors from '../../selectors';
import * as actions from '../';
import {ASSIGNMENTS, ALL_DESKS, SORT_DIRECTION} from '../../constants';
import planningUtils from '../../utils/planning';
import {lockUtils, getErrorMessage, isExistingItem, gettext} from '../../utils';
import {getErrorMessage, isExistingItem, gettext} from '../../utils';
import planning from '../planning';
import {assignmentsViewRequiresArchiveItems} from '../../components/Assignments/AssignmentItem/fields';

Expand Down Expand Up @@ -240,24 +241,6 @@ const fetchAssignmentById = (id, force = false, recieve = true) => (
}
);

/**
* Action dispatcher to query the API for all Assignments that are currently locked
* @return Array of locked Assignments
*/
const queryLockedAssignments = () => (
(dispatch, getState, {api}) => (
api('assignments').query({
source: JSON.stringify(
{query: {constant_score: {filter: {exists: {field: 'lock_session'}}}}}
),
})
.then(
(data) => Promise.resolve(data._items),
(error) => Promise.reject(error)
)
)
);

/**
* Action to receive the list of Assignments and store them in the store
* Also loads all the associated contacts (if any)
Expand Down Expand Up @@ -300,7 +283,7 @@ const save = (original, assignmentUpdates) => (
return promise.then((originalItem) => {
let updates;

if (original.lock_action === 'reassign') {
if (original.lock_action === ASSIGNMENTS.ITEM_ACTIONS.REASSIGN.lock_action) {
updates = pick(assignmentUpdates, 'assigned_to');
updates.assigned_to = pick(
assignmentUpdates.assigned_to,
Expand Down Expand Up @@ -394,53 +377,6 @@ const revert = (item) => (
)
);

/**
* Action to lock an assignment
* @param {IAssignmentItem} assignment - Assignment to be unlocked
* @param {String} action - The action to assign to the lock
* @return Promise
*/
const lock = (assignment: IAssignmentItem, action: string = 'edit') => (
(dispatch, getState, {api, notify}) => {
if (lockUtils.isItemLockedInThisSession(
assignment,
selectors.general.session(getState()),
selectors.locks.getLockedItems(getState())
)) {
return Promise.resolve(assignment);
}

return api('assignments_lock', assignment).save({}, {lock_action: action})
.then(
(lockedItem: IAssignmentItem) => lockedItem,
(error) => {
const msg = get(error, 'data._message') || 'Could not lock the assignment.';

notify.error(msg);
if (error) throw error;
});
}
);

/**
* Action to unlock an assignment
* @param {IAssignmentItem} assignment - Assignment to be unlocked
* @return Promise
*/
const unlock = (assignment: IAssignmentItem) => (
(dispatch, getState, {api, notify}) => (
api('assignments_unlock', assignment).save({})
.then(
(unlockedItem: IAssignmentItem) => unlockedItem,
(error) => {
const msg = get(error, 'data._message') || 'Could not unlock the assignment.';

notify.error(msg);
throw error;
})
)
);

/**
* Fetch history of an assignment
* @param {object} assignment - The Assignment to load history for
Expand Down Expand Up @@ -605,21 +541,21 @@ const removeAssignment = (assignment) => (
)
);

const unlink = (assignment) => (
(dispatch, getState, {api, notify}) => (
function unlink(assignment: IAssignmentItem) {
return (dispatch, getState, {api, notify}) => (
api('assignments_unlink').save({}, {
assignment_id: assignment._id,
item_id: get(assignment, 'item_ids[0]'),
})
.then(() => {
notify.success(gettext('Assignment reverted.'));
return dispatch(self.unlock(assignment));
return planningApi.locks.unlockItem(assignment);
}, (error) => {
notify.error(get(error, 'data._message') || gettext('Could not unlock the assignment.'));
throw error;
})
)
);
);
}

// eslint-disable-next-line consistent-this
const self = {
Expand All @@ -631,9 +567,6 @@ const self = {
createFromTemplateAndShow,
complete,
revert,
lock,
unlock,
queryLockedAssignments,
loadPlanningAndEvent,
loadArchiveItems,
loadArchiveItem,
Expand Down
35 changes: 24 additions & 11 deletions client/actions/assignments/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {get, cloneDeep} from 'lodash';

import {IWebsocketMessageData} from '../../interfaces';

import {planningApi} from '../../superdeskApi';
import {ASSIGNMENTS, WORKSPACE, MODALS} from '../../constants';
import {lockUtils, assignmentUtils, gettext, isExistingItem} from '../../utils';

import * as selectors from '../../selectors';
import assignments from './index';
import main from '../main';
import {get, cloneDeep} from 'lodash';
import planning from '../planning';
import {ASSIGNMENTS, WORKSPACE, MODALS} from '../../constants';
import {lockUtils, assignmentUtils, gettext, isExistingItem} from '../../utils';
import {hideModal, showModal} from '../index';
import * as actions from '../../actions';

Expand Down Expand Up @@ -149,6 +154,12 @@ const onAssignmentUpdated = (_e, data) => (
lock_time: null,
};

planningApi.locks.setItemAsUnlocked({
item: data.item,
etag: data.etag,
from_ingest: false,
type: 'assignment',
});
dispatch({
type: ASSIGNMENTS.ACTIONS.UNLOCK_ASSIGNMENT,
payload: {assignment: item},
Expand Down Expand Up @@ -185,9 +196,10 @@ const _updatePlannigRelatedToAssignment = (data) => (
}
);

const onAssignmentLocked = (_e, data) => (
(dispatch) => {
function onAssignmentLocked(_e, data: IWebsocketMessageData['ITEM_LOCKED']) {
return (dispatch) => {
if (get(data, 'item')) {
planningApi.locks.setItemAsLocked(data);
return dispatch(assignments.api.fetchAssignmentById(data.item, false))
.then((assignmentInStore) => {
let item = {
Expand All @@ -209,8 +221,8 @@ const onAssignmentLocked = (_e, data) => (
}

return Promise.resolve();
}
);
};
}

/**
* WS Action when a Planning item gets unlocked
Expand All @@ -220,9 +232,10 @@ const onAssignmentLocked = (_e, data) => (
* @param {object} _e - Event object
* @param {object} data - Planning and User IDs
*/
const onAssignmentUnlocked = (_e, data) => (
(dispatch, getState) => {
function onAssignmentUnlocked(_e, data: IWebsocketMessageData['ITEM_UNLOCKED']) {
return (dispatch, getState) => {
if (get(data, 'item')) {
planningApi.locks.setItemAsUnlocked(data);
return dispatch(assignments.api.fetchAssignmentById(data.item, false))
.then((assignmentInStore) => {
const locks = selectors.locks.getLockedItems(getState());
Expand Down Expand Up @@ -265,8 +278,8 @@ const onAssignmentUnlocked = (_e, data) => (
return Promise.resolve();
});
}
}
);
};
}

/**
* WS Action when an Assignment is deleted
Expand Down
Loading

0 comments on commit 22f9466

Please sign in to comment.