Skip to content

Commit

Permalink
Hide anonymous joins from the user's profile
Browse files Browse the repository at this point in the history
  • Loading branch information
tomitheninja committed Aug 25, 2021
1 parent 3fae575 commit 4507127
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion migrations/20200328131352_initial_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function up(knex: Knex): Promise<void> {
.inTable('groups')
.index()

table.boolean('isAnon')
table.boolean('isAnon').defaultTo(0)
})
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/groups/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class Group extends Model {
createdAt: Date
maxAttendees: number

/**
* See {@link User.isAnon}
*/
isAnon: boolean

$beforeInsert(): void {
this.createdAt = new Date()
}
Expand Down
14 changes: 10 additions & 4 deletions src/components/users/user.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ import { getUser, updateRole, updateUser } from './user.service'

const router = Router()

router.get('/:id', isAuthenticated, checkIdParam, getUser, (req, res) =>
router.get('/:id', isAuthenticated, checkIdParam, getUser, (req, res) => {
const u = req.userToShow
const viewsSelf = u.id == (req.user as User).id
const isAdmin = (req.user as User).role !== RoleType.USER

const groups = viewsSelf || isAdmin ? u.groups : u.groups.filter(g => !g.isAnon)

res.render('user/show', {
userToShow: req.userToShow,
userToShow: { ...req.userToShow, groups },
ROLES: ROLES
})
)
})

router.patch('/:id/role',
requireRoles(RoleType.ADMIN),
check('role')
.isString()
.custom((input) => {
.custom((input) => {
return [...ROLES.keys()]
.some((element) => element == input)
})
Expand Down

0 comments on commit 4507127

Please sign in to comment.