diff --git a/app/scripts/views/EventsShow.js b/app/scripts/views/EventsShow.js index 26dca55a..5247b472 100644 --- a/app/scripts/views/EventsShow.js +++ b/app/scripts/views/EventsShow.js @@ -13,6 +13,7 @@ class EventsShow extends Component { static propTypes = { fetchResource: PropTypes.func.isRequired, isActive: PropTypes.bool.isRequired, + isAdmin: PropTypes.bool.isRequired, isError: PropTypes.bool.isRequired, isLoading: PropTypes.bool.isRequired, isVisitor: PropTypes.bool.isRequired, @@ -219,6 +220,63 @@ class EventsShow extends Component { ) } + renderResources() { + if (this.props.isLoading) { + return null + } + + if (!this.props.resourceData.isOwnerMe && !this.props.isAdmin) { + return null + } + + if (this.props.resourceData.resources.length === 0) { + return null + } + + return ( +
+
+ + + { translate('views.events.resourcesTitle') } + + + + + + + + + + + + + {this.props.resourceData.resources.map((resource, index) => { + return ( + + + + + + + ) + })} + +
+ # + + { translate('views.events.resourcesTableItem') } + + { translate('views.events.resourcesTableDescription') } + + { translate('views.events.resourcesTableOwner') } +
{index + 1}{resource.title}{resource.description} + +
+
+ ) + } + renderContent() { if (this.props.isLoading) { return

{ translate('common.loading') }

@@ -239,6 +297,7 @@ class EventsShow extends Component { { this.renderTicketUrl() } { this.renderWebsiteUrl() } { this.renderAdditionalInfo() } + { this.renderResources() } ) } @@ -278,13 +337,14 @@ function mapStateToProps(state, ownProps) { const resourceSlug = ownProps.match.params.slug const resource = cachedResource('events', resourceSlug) const { isLoading, isError, object: resourceData } = resource - const { isVisitor, isActive } = state.user + const { isVisitor, isActive, isAdmin } = state.user return { isActive, isError, isLoading, isVisitor, + isAdmin, resourceData, resourceSlug, } diff --git a/common/locales/views.en.js b/common/locales/views.en.js index 3d438fca..85659491 100644 --- a/common/locales/views.en.js +++ b/common/locales/views.en.js @@ -49,6 +49,10 @@ export default { tagSelectorTitle: 'Filter by tags', datePickerTitle: 'Filter by date', titlePlaceholder: 'Event', + resourcesTitle: 'Resources', + resourcesTableItem: 'Item', + resourcesTableDescription: 'Description', + resourcesTableOwner: 'Owner', }, inbox: { backToConversations: 'Back to inbox', diff --git a/server/controllers/base.js b/server/controllers/base.js index afb85106..4c17f626 100644 --- a/server/controllers/base.js +++ b/server/controllers/base.js @@ -25,7 +25,7 @@ export function prepareAnimalResponse(animal, isAnonymous = true) { name, } - if (!isAnonymous) { + if (!isAnonymous && animal.user) { const { user } = animal data.userId = user.id @@ -39,8 +39,22 @@ export function prepareAnimalResponseAll(animals, isAnonymous) { return animals.map(animal => prepareAnimalResponse(animal, isAnonymous)) } +function filterAnimal(obj, isAnonymous) { + if (obj && typeof obj === 'object') { + Object.keys(obj).forEach(key => { + if (key === 'animal') { + obj.animal = prepareAnimalResponse(obj.animal, isAnonymous) + } else { + obj[key] = filterAnimal(obj[key], isAnonymous) + } + }) + } + + return obj +} + export function prepareResponse(data, req, isAnonymous) { - const response = 'toJSON' in data ? data.toJSON() : data + let response = 'toJSON' in data ? data.toJSON() : data // Set owner flag for frontend ui if (typeof req.isOwnerMe !== 'undefined') { @@ -50,9 +64,7 @@ export function prepareResponse(data, req, isAnonymous) { } // Remove userId from animal to stay anonymous - if (response.animal) { - response.animal = prepareAnimalResponse(response.animal, isAnonymous) - } + response = filterAnimal(response, isAnonymous) // Convert markdown to html response.descriptionHtml = marked(response.description) diff --git a/server/controllers/event.js b/server/controllers/event.js index fa69d3e9..b019fc08 100644 --- a/server/controllers/event.js +++ b/server/controllers/event.js @@ -61,7 +61,8 @@ const belongsToManyResources = { attributes: { exclude: ['createdAt', 'updatedAt'] }, include: [{ association: ResourceBelongsToAnimal, - attributes: ['name', 'id'], + attributes: ['name', 'id', 'userId'], + include: AnimalBelongsToUser, }], }