From ecf25e548f47943592d4136888ce96f9b8b1d012 Mon Sep 17 00:00:00 2001 From: Vaughan Fergusson <47308807+nzvorn@users.noreply.github.com> Date: Thu, 22 Jul 2021 11:23:37 +1200 Subject: [PATCH] Experimenting with auth and permissions to get to V3 for schools --- components/Act/ActAboutPanel.js | 3 +- components/Act/ActCard.js | 3 +- components/Act/ActListSection.js | 17 ++-- components/Footer/Footer.js | 9 -- components/Header/Header.js | 5 +- components/Header/HeaderMenu.js | 63 ++++++-------- components/Op/OpOrderby.js | 10 +-- components/Op/OpQuestionPanel.js | 83 +------------------ components/Person/PersonRole.js | 11 +-- lang/en.json | 2 +- pages/act/actlistpage.js | 4 +- pages/search/searchpage.js | 54 +++++++----- server/api/activity/activity.ability.js | 1 + server/api/member/member.ability.js | 1 + server/api/opportunity/opportunity.ability.js | 2 +- .../api/organisation/organisation.ability.js | 3 +- server/api/tag/tag.ability.js | 1 + server/middleware/ability/getAbility.js | 1 + .../middleware/authorize/authorizeRequest.js | 4 +- 19 files changed, 97 insertions(+), 180 deletions(-) diff --git a/components/Act/ActAboutPanel.js b/components/Act/ActAboutPanel.js index 7dbffbfb3..51ab19db9 100644 --- a/components/Act/ActAboutPanel.js +++ b/components/Act/ActAboutPanel.js @@ -69,11 +69,12 @@ export function ActAboutPanel ({ act }) { const isAnon = me.role.includes(Role.ANON) const vp = me.role.includes(Role.VOLUNTEER) || isAnon const bp = me.role.includes(Role.BASIC) || isAnon + const op = me.role.includes(Role.OPPORTUNITY_PROVIDER) || isAnon return ( - {bp && } + {op && } {vp && } diff --git a/components/Act/ActCard.js b/components/Act/ActCard.js index 7fdcc9406..d17682b98 100644 --- a/components/Act/ActCard.js +++ b/components/Act/ActCard.js @@ -28,8 +28,7 @@ const ActCard = ({ act, onPress, ...props }) => {

{act.subtitle}

    -
  • -
  • +
diff --git a/components/Act/ActListSection.js b/components/Act/ActListSection.js index b3fc8bb90..5201e7c5e 100644 --- a/components/Act/ActListSection.js +++ b/components/Act/ActListSection.js @@ -46,9 +46,9 @@ export const ActListSection = () => { const getActivities = async () => { const q = { status: 'active' } const query = { } - if (me.topicGroups && me.topicGroups.length) { - q.tags = { $in: me.topicGroups } - } + //if (me.topicGroups && me.topicGroups.length) { + // q.tags = { $in: me.topicGroups } + //} if (selectedOrg) { q.offerOrg = selectedOrg } @@ -57,6 +57,7 @@ export const ActListSection = () => { query.search = search } await dispatch(reduxApi.actions.activities.get(query)) + } getActivities() }, [search, selectedOrg]) @@ -106,15 +107,7 @@ export const ActListSection = () => { )} /> - Cant find what you want? - - Suggest an activity here - - + diff --git a/components/Footer/Footer.js b/components/Footer/Footer.js index 3250a6d2e..42267f7cc 100644 --- a/components/Footer/Footer.js +++ b/components/Footer/Footer.js @@ -138,15 +138,6 @@ const Footer = () => ( Join the build - Suggest a Topic - - System Status - - { } let state = isAuthenticated ? MenuShowState.AUTH : MenuShowState.ANON - if (me.role.includes(Role.BASIC)) state = MenuShowState.BASIC + if (me.role.includes(Role.AUTH)) state = MenuShowState.AUTH if (me.role.includes(Role.VOLUNTEER)) state = MenuShowState.VOLUNTEER - if (me.role.includes(Role.VOLUNTEER) && me.role.includes(Role.BASIC)) state = MenuShowState.BOTH + if (me.role.includes(Role.ORG_ADMIN)) state = MenuShowState.ORG_ADMIN + if (me.role.includes(Role.ACTIVITY_PROVIDER)) state = MenuShowState.ACTIVITY_PROVIDER if (me.role.includes(Role.ADMIN) || me.role.includes(Role.SUPPORT)) state = MenuShowState.ADMIN return ( diff --git a/components/Header/HeaderMenu.js b/components/Header/HeaderMenu.js index f5d849bca..2c64604fa 100644 --- a/components/Header/HeaderMenu.js +++ b/components/Header/HeaderMenu.js @@ -6,77 +6,68 @@ export const MenuShowState = { AUTH: 'auth', BASIC: 'basic', // option shows for signed in people VOLUNTEER: 'volunteer', // option shows for signed in volunteer - BOTH: 'both', // option shows for both ask and offer + OPPORTUNITY_PROVIDER: 'opportunityProvider', + ORG_ADMIN: 'orgAdmin', ADMIN: 'admin' // option shows for signed in admin } -const { ANON, AUTH, BASIC, VOLUNTEER, BOTH, ADMIN } = MenuShowState +const { ANON, AUTH, BASIC, VOLUNTEER, OPPORTUNITY_PROVIDER, ACTIVITY_PROVIDER, RESOURCE_PROVIDER, ORG_ADMIN, ADMIN } = MenuShowState const menuItems = [ + { - key: 'home', - show: [AUTH, BASIC, VOLUNTEER, BOTH, ADMIN], - href: '/home', + key: 'dashboard', + show: [AUTH, BASIC, VOLUNTEER, OPPORTUNITY_PROVIDER, ACTIVITY_PROVIDER, RESOURCE_PROVIDER, ORG_ADMIN, ADMIN], + href: '/', text: }, { - key: 'acts_ask', - show: [BASIC, BOTH, ADMIN], - href: '/a/ask', + key: 'org', + show: [VOLUNTEER, BASIC, OPPORTUNITY_PROVIDER, ACTIVITY_PROVIDER, RESOURCE_PROVIDER, ORG_ADMIN, ADMIN], + href: '/org', text: }, { - key: 'acts_offer', - show: [VOLUNTEER, BOTH, ADMIN], - href: '/a/offer', + key: 'acts_ask', + show: [OPPORTUNITY_PROVIDER, ACTIVITY_PROVIDER, ORG_ADMIN, ADMIN], + href: '/a/ask', text: }, + { - key: 'habout', - show: [AUTH, ANON], - href: 'https://blog.voluntarily.nz', + key: 'acts_offer', + show: [VOLUNTEER, BASIC, AUTH, ADMIN], + href: '/search', text: }, + { key: 'admin', text: 'Admin', href: '/admin', show: [ADMIN] }, - { - key: 'orgs', - text: 'Groups', - href: '/orgs', - show: [ADMIN] - - }, { key: 'people', text: 'People', href: '/people', show: [ADMIN] }, - { - key: 'help', - show: [ANON, AUTH, BASIC, VOLUNTEER, BOTH, ADMIN], - text: 'Support πŸ™‹πŸ½β€β™€οΈ', - href: 'https://support.voluntarily.nz/hc/en-nz' - }, { key: 'hsignin', show: [ANON], @@ -89,7 +80,7 @@ const menuItems = [ }, { key: 'hsignoff', - show: [AUTH, BASIC, VOLUNTEER, BOTH, ADMIN], + show: [AUTH, VOLUNTEER, BASIC, OPPORTUNITY_PROVIDER, ACTIVITY_PROVIDER, RESOURCE_PROVIDER, ORG_ADMIN, ADMIN], href: '/auth/sign-off', text: { const style = { - width: 150, + width: 250, float: 'right', position: 'relative', marginTop: -60 } return ( - diff --git a/components/Op/OpQuestionPanel.js b/components/Op/OpQuestionPanel.js index d81865714..c5de4d843 100644 --- a/components/Op/OpQuestionPanel.js +++ b/components/Op/OpQuestionPanel.js @@ -201,88 +201,7 @@ export function OpQuestionPanel ({ op }) { - - -

- 29 Jan 2019 -
- 11:59PM -

-
- -

Can I get free parking at the school?

- - -

Legitimate Name

- - -
-
-
- - -

- 29 Jan 2019 -
- 11:59PM -

-
- -

- Yeah, text me at 027 123 4567 when you get close to the school -

- - -

Legitimate teacher

- -
-
-
- - -

- 29 Jan 2019 -
- 11:59PM -

-
- -

Can I get free parking at the school?

- - -

Legitimate Name

- - -
-
-
- - -

- 29 Jan 2019 -
- 11:59PM -

-
- -

- Yeah, text me at 027 123 4567 when you get close to the school -

- - -

Legitimate teacher

- -
-
-
+ diff --git a/components/Person/PersonRole.js b/components/Person/PersonRole.js index 160ba29a4..620930e31 100644 --- a/components/Person/PersonRole.js +++ b/components/Person/PersonRole.js @@ -7,8 +7,8 @@ export const PersonRole = ({ role }) => { const roleOptions = { admin: , orgAdmin: , - // opportunityProvider: , - basic: , + opportunityProvider: , + basic: , volunteer: , activityProvider: , resourceProvider: , @@ -22,11 +22,12 @@ const roleIcons = { admin: '🌟', orgAdmin: '⭐', support: 'πŸ’', + opportunityProvider: '🀝', activityProvider: 'πŸ§‘β€πŸ’»', resourceProvider: 'πŸ§‘β€πŸ’»', - volunteer: 'πŸ€™', // 🀝, - basic: 'πŸ™‹' - // opportunityProvider: '🀝' + volunteer: 'πŸ€™', + basic: 'πŸ€™' + } export const PersonRoleIcon = ({ role }) => { diff --git a/lang/en.json b/lang/en.json index 0b7f708e3..446203b6d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -46,7 +46,7 @@ "ActiveOpsSection.empty.title": "Let’s find cool ways to volunteer", "ActiveOpsSection.title": "Upcoming Activities", "activityProvider": "Activity Provider", - "ActListPage.Ask.Title": "Volunteers are offering to help with", + "ActListPage.Ask.Title": "Ideas for asking for volunteers", "ActListPage.Offer.Title": "People are asking for help with", "actLock": "Lock Editable Fields", "ActOpsPanel.button.showAll": "See all", diff --git a/pages/act/actlistpage.js b/pages/act/actlistpage.js index cbae70e24..ce1a8997c 100644 --- a/pages/act/actlistpage.js +++ b/pages/act/actlistpage.js @@ -13,7 +13,7 @@ const { ASK, OFFER } = OpportunityType const ActListTitleMessages = defineMessages({ [ASK]: { id: 'ActListPage.Ask.Title', - defaultMessage: 'Volunteers are offering to help with', + defaultMessage: 'Ideas for attracting volunteers', description: 'Title of ask for help page' }, [OFFER]: { @@ -26,7 +26,7 @@ const ActListTitleMessages = defineMessages({ const ActListSubTitleMessages = defineMessages({ [ASK]: { id: 'act.list.ask.subtitle', - defaultMessage: 'Find activities volunteers are offering to help you with', + defaultMessage: 'Find activities volunteers can help you with', description: 'Sub Title of page listing activities people are asking help with' }, [OFFER]: { diff --git a/pages/search/searchpage.js b/pages/search/searchpage.js index b975ea281..4a397582a 100644 --- a/pages/search/searchpage.js +++ b/pages/search/searchpage.js @@ -17,6 +17,7 @@ import publicPage from '../../hocs/publicPage' import reduxApi, { withLocations } from '../../lib/redux/reduxApi' import DatePickerComponent, { formatDateBaseOn } from './DatePickerComponent' import OpOrderby from '../../components/Op/OpOrderby' +import { Input } from 'antd' // const TitleString = {NumberResults} + "results for " + {SearchQuery} const { Item } = Menu @@ -36,6 +37,14 @@ const DATE_FILTER_NAME = 'date' const TYPE_FILTER_NAME = 'type' const opTypeValue = ['All', 'Offer', 'Ask'] +const SearchContainer = styled.div` + background: #ffffff; + box-shadow: 2px 2px 12px 0 rgba(117, 117, 117, 0.5); + border-radius: 8px; + padding: 1rem; + margin-bottom: 2rem; +` + function filterVisibilityName (filterName) { return `${filterName}FilterVisible` } @@ -48,12 +57,12 @@ export class SearchPage extends Component { state = { search: null, datePickerType: DatePickerType.IndividualDate, - showDatePickerModal: false, + showDatePickerModal: true, filter: { date: [] }, - locationFilterVisible: false, - typeFilterVisible: false, + locationFilterVisible: true, + typeFilterVisible: true, opOrderBy: 'date' } @@ -97,10 +106,6 @@ export class SearchPage extends Component { } handleSearch = search => { - if (!search) { - return false - } - Router.push({ pathname: '/search', query: { @@ -163,6 +168,9 @@ export class SearchPage extends Component { ) + + const searchTitle = 'Search results' + return (
Voluntarily - Search Results + + + } /> + - - - + {/* TODO: VP-445 modify date picker to use filter container (like with location). This will help reduce the complexity of this page component */} + + + diff --git a/server/api/activity/activity.ability.js b/server/api/activity/activity.ability.js index 2daea8e3a..1775926f0 100644 --- a/server/api/activity/activity.ability.js +++ b/server/api/activity/activity.ability.js @@ -101,6 +101,7 @@ const ruleBuilder = session => { [Role.BASIC]: anonRules, [Role.VOLUNTEER]: anonRules, [Role.ACTIVITY_PROVIDER]: activityProviderAbilities, + [Role.OPPORTUNITY_PROVIDER]: activityProviderAbilities, [Role.ORG_ADMIN]: orgAdminAbilities, [Role.ADMIN]: adminAbilities } diff --git a/server/api/member/member.ability.js b/server/api/member/member.ability.js index faa5fdac0..45987ccce 100644 --- a/server/api/member/member.ability.js +++ b/server/api/member/member.ability.js @@ -64,6 +64,7 @@ const ruleBuilder = async (session) => { [Role.ANON]: anonRules, [Role.BASIC]: basicRules, [Role.VOLUNTEER]: basicRules, + [Role.ACTIVITY_PROVIDER]: basicRules, [Role.OPPORTUNITY_PROVIDER]: basicRules, [Role.ORG_ADMIN]: orgAdminRules, [Role.ADMIN]: adminRules diff --git a/server/api/opportunity/opportunity.ability.js b/server/api/opportunity/opportunity.ability.js index fab6dad1b..a1c17b122 100644 --- a/server/api/opportunity/opportunity.ability.js +++ b/server/api/opportunity/opportunity.ability.js @@ -94,7 +94,7 @@ const ruleBuilder = session => { return { [Role.ANON]: anonAbilities, [Role.BASIC]: anonAbilities, - [Role.VOLUNTEER]: opAbilities, + [Role.VOLUNTEER]: anonAbilities, [Role.OPPORTUNITY_PROVIDER]: opAbilities, [Role.SUPPORT]: supportAbilities, [Role.ADMIN]: adminAbilities, diff --git a/server/api/organisation/organisation.ability.js b/server/api/organisation/organisation.ability.js index 3770274c7..fe3cf53c7 100644 --- a/server/api/organisation/organisation.ability.js +++ b/server/api/organisation/organisation.ability.js @@ -42,8 +42,9 @@ const ruleBuilder = (session) => { return { [Role.ANON]: defaultAbilities, - [Role.ACTIVITY_PROVIDER]: defaultAbilities, + [Role.BASIC]: defaultAbilities, [Role.VOLUNTEER]: defaultAbilities, + [Role.ACTIVITY_PROVIDER]: defaultAbilities, [Role.OPPORTUNITY_PROVIDER]: defaultAbilities, [Role.SUPPORT]: defaultAbilities, // ORG_ADMIN roles are further trimmed in each Controller Action diff --git a/server/api/tag/tag.ability.js b/server/api/tag/tag.ability.js index 28d17a73e..f2e603fa4 100644 --- a/server/api/tag/tag.ability.js +++ b/server/api/tag/tag.ability.js @@ -32,6 +32,7 @@ const ruleBuilder = (session) => { [Role.ANON]: basicAbilities, [Role.VOLUNTEER]: basicAbilities, [Role.BASIC]: basicAbilities, + [Role.ACTIVITY_PROVIDER]: basicAbilities, [Role.OPPORTUNITY_PROVIDER]: basicAbilities, [Role.SUPPORT]: adminAbilities, [Role.ADMIN]: adminAbilities diff --git a/server/middleware/ability/getAbility.js b/server/middleware/ability/getAbility.js index dbfb50097..a753a0290 100644 --- a/server/middleware/ability/getAbility.js +++ b/server/middleware/ability/getAbility.js @@ -30,6 +30,7 @@ module.exports = options => async (req, res, next) => { for (const role of userRoles) { if (rules[role] == null) continue if (role) { + console.log(`Role ${role}`) allRules = allRules.concat(rules[role]) } if (role === 'admin') break diff --git a/server/middleware/authorize/authorizeRequest.js b/server/middleware/authorize/authorizeRequest.js index bc6310ac2..8811ff8cb 100644 --- a/server/middleware/authorize/authorizeRequest.js +++ b/server/middleware/authorize/authorizeRequest.js @@ -18,11 +18,11 @@ const defaultConvertRequestToAction = (req) => { const authorizeActions = (subject, convertRequestToAction = defaultConvertRequestToAction) => (req, res, next) => { const action = convertRequestToAction(req) const authorized = req.ability.can(action, subject) - // console.log('authorizeActions', subject, action, authorized) + console.log('authorizeActions', subject, action, authorized) if (authorized) { next() } else { - // console.log(`Auth cannot ${action} ${subject}`) + console.log(`Auth cannot ${action} ${subject}`) res.status(403).json({ error: `Auth cannot ${action} ${subject}` }) } }