Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pledge Only Users #176

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
855f9a4
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Sep 24, 2024
33a9a7a
layout users in table
cj13579 Sep 27, 2024
a17f974
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Oct 2, 2024
0111b1f
Move an item to bottom of the list (#141)
cj13579 Sep 28, 2024
2473973
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Sep 28, 2024
a32f938
Set location of PouchDB log file with environment variable. (#93)
bsiddans Sep 28, 2024
95472f0
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Sep 28, 2024
f914b99
The Dockerfile didn't wok for me, here's a fix (#145)
jskiddie Oct 1, 2024
be76412
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Oct 1, 2024
c73b3e9
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Oct 2, 2024
0dc2502
Merge branch 'Wingysam:master' into 129-admins-table
cj13579 Oct 2, 2024
fe03827
Ability to create pledge only users
cj13579 Oct 10, 2024
cc185ca
add localization
cj13579 Oct 11, 2024
dcfd0b1
Merge branch 'Wingysam:master' into master
cj13579 Nov 22, 2024
0657aff
Merge branch 'Wingysam:master' into master
cj13579 Dec 31, 2024
24929e8
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Dec 31, 2024
c12ceee
Merge branch 'master' into pledge-only-users
cj13579 Dec 31, 2024
a114113
Merge branch '129-admins-table' into pledge-only-users
cj13579 Dec 31, 2024
3f362e5
Return when user object is updated
cj13579 Dec 31, 2024
08a4a99
Option to disable guest suggestions
cj13579 Dec 31, 2024
d99ad9b
Update if condition to enable self-adding
cj13579 Dec 31, 2024
f7e5b26
Add global suggestions disabled support
cj13579 Dec 31, 2024
916f053
Dev convenience
cj13579 Dec 31, 2024
f0ed668
small refactor
cj13579 Dec 31, 2024
9ebe3bf
Merge branch 'master' into pledge-only-users
cj13579 Jan 24, 2025
477153c
tidy up item adding
cj13579 Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ MARKDOWN=false
# OIDC_TOKEN_URL=https://oauth2.googleapis.com/token
# OIDC_ISSUER=https://accounts.google.com
# OIDC_PROVIDER_NAME=Google

# Set to false to disable pledge only users from being able to suggest items to another user's list
PLEDGE_SUGGEST=true

# Set to false to disable all users from being able to suggest items to another users's list
SUGGESTIONS_ENABLED=true
```

## Default Profile Pictures
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node built/manager.js",
"dev": "nodemon --watch src -e ts,js --exec 'npm run build && node built/index.js'",
"dev": "nodemon --watch src -e ts,js,pug --exec 'npm run build && node built/index.js'",
"postinstall": "node postinstall.cjs",
"build": "tsc",
"release": "docker buildx build . --platform linux/amd64,linux/arm64 -t wingysam/christmas-community -t wingysam/christmas-community:$(./node_modules/node-jq/bin/jq -r .version < package.json) --push"
Expand Down
4 changes: 3 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const config = {
oidcProviderName: process.env.OIDC_PROVIDER_NAME || 'Google',
oidcEnabled: false,
rootUrl: appendSlash(process.env.ROOT_URL ?? process.env.ROOT_PATH ?? '/'),
base: '' // automatically set below
base: '', // automatically set below
pledgeSuggest: (process.env.PLEDGE_SUGGEST === 'true'),
suggestionsEnabled: (process.env.SUGGESTIONS_ENABLED === 'true')
}

if (config.guestPassword) config.wishlist.public = false
Expand Down
13 changes: 12 additions & 1 deletion src/languages/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const strings = {
ADMIN_SETTINGS_USERS_ADD_HEADER: 'Add user',
ADMIN_SETTINGS_USERS_ADD_PLACEHOLDER: 'john',
ADMIN_SETTINGS_USERS_ADD_USERNAME: 'Username',
ADMIN_SETTINGS_USERS_ADD_PLEDGE_ONLY: 'Pledge only user?',
ADMIN_SETTINGS_USERS_ADD_ERROR_USERNAME_EMPTY: 'Username cannot be empty.',
ADMIN_SETTINGS_USERS_EDIT_DELETE_FAIL_ADMIN: 'Failed to remove: user is admin.',
ADMIN_SETTINGS_USERS_EDIT_DELETE_SUCCESS: name => `Successfully removed user ${name}`,
Expand All @@ -29,9 +30,16 @@ export const strings = {
ADMIN_SETTINGS_USERS_EDIT_PROMOTE_SUCCESS: name => `${name} is now an admin.`,
ADMIN_SETTINGS_USERS_EDIT_RENAMED_USER: 'Renamed user!',
ADMIN_SETTINGS_USERS_EDIT_SAME_NAME: 'Username is same as new username.',
ADMIN_USER_EDIT_PLEDGE_ONLY: 'Pledge only',
ADMIN_USER_EDIT_PLEDGE_ONLY_BUTTON: 'Change pledge only',
ADMIN_SETTINGS_USERS_EDIT: 'Edit',
ADMIN_SETTINGS_USERS_HEADER: 'Users',
ADMIN_SETTINGS_VERSION_INFO: 'Version Info',
ADMIN_SETTINGS_TABLE_USERNAME: 'Username',
ADMIN_SETTINGS_TABLE_ADMIN_USER: 'Admin',
ADMIN_SETTINGS_TABLE_PLEDGE_ONLY: 'Pledge only',
ADMIN_SETTINGS_TABLE_WISHLIST_COUNT: 'Wishlist items',
ADMIN_SETTINGS_TABLE_EDIT: 'Edit',
ADMIN_USER_EDIT_ACCOUNT_UNCONFIRMED: "This account hasn't been confirmed.",
ADMIN_USER_EDIT_ADMIN_ISADMIN: name => `${name} is an admin.`,
ADMIN_USER_EDIT_ADMIN_NOTADMIN: name => `${name} is not an admin.`,
Expand Down Expand Up @@ -208,7 +216,10 @@ export const strings = {
WISHLIST_URL_LABEL: `Item URL or Name (<a href="${_CC.config.base}supported-sites">Supported Sites</a>)`,
WISHLIST_URL_PLACEHOLDER: 'https://www.amazon.com/dp/B00ZV9RDKK',
WISHLIST_URL_REQUIRED: 'Item URL or Name is required',
WISHLIST_SUGGESTIONS_DISABLED: 'Item suggestions are disabled.',
WISHLISTS_COUNTS_SELF: name => `${name}: ???/???`,
WISHLISTS_COUNTS: (name, pledged, total) => `${name}: ${pledged}/${total}`,
WISHLISTS_TITLE: `${_CC.config.siteTitle} - Wishlists`
WISHLISTS_TITLE: `${_CC.config.siteTitle} - Wishlists`,
YES: 'Yes',
NO: 'No'
} as const
21 changes: 21 additions & 0 deletions src/routes/adminSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ export default function ({ db, ensurePfp }) {
})
}

const pledgeOnlyValue = req.body.newPledgeOnlyUser
const pledgeOnly = pledgeOnlyValue === 'on'

await db.put({
_id: username,
admin: false,
wishlist: [],
pledgeOnly: pledgeOnly,

signupToken: nanoid(SECRET_TOKEN_LENGTH),
expiry: new Date().getTime() + SECRET_TOKEN_LIFETIME
Expand Down Expand Up @@ -139,6 +143,23 @@ export default function ({ db, ensurePfp }) {
}
})

router.post('/edit/pledgeOnly/:userToChange', verifyAuth(), async (req, res) => {

const newPledgeValue = req.body.editPledgeOnlyUser
const newPledge = newPledgeValue === 'on'

const userDoc = await db.get(req.params.userToChange)
userDoc.pledgeOnly = newPledge
try {
await db.put(userDoc)
await _CC.wishlistManager.clearCache()
return res.redirect(`/admin-settings/edit/${req.params.userToChange}`)
} catch (error) {
req.flash('error', error.message)
return res.redirect(`/admin-settings/edit/${req.params.userToChange}`)
}
})

router.post('/edit/impersonate/:userToEdit', verifyAuth(), async (req, res) => {
if (!req.user.admin) return res.redirect('/')
req.login({ _id: req.params.userToEdit }, err => {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default function ({ db, ensurePfp }) {
password: adminPasswordHash,
admin: true,
wishlist: [],
oauthConnections: {}
oauthConnections: {},
pledgeOnly: false
})
resolve()
})
Expand Down
5 changes: 5 additions & 0 deletions src/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ img.logo-image {

.print-gift:last-child {
margin-bottom: 0;
}

a.disabled {
pointer-events: none;
cursor: default;
}
9 changes: 9 additions & 0 deletions src/views/admin-user-edit.pug
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ block content
.field
.control
input.button.is-primary(type='submit' value=lang('ADMIN_USER_EDIT_CHANGE_USERNAME'))
.column.is-narrow
h2= lang('ADMIN_USER_EDIT_PLEDGE_ONLY')
form(action=`${_CC.config.base}admin-settings/edit/pledgeOnly/${user._id}`, method='POST')
.field
.control
input(type='checkbox', name='editPledgeOnlyUser', checked=user.pledgeOnly)
.field
.control
input.input.button(type='submit', value=lang('ADMIN_USER_EDIT_PLEDGE_ONLY_BUTTON'), style='margin-top: 1em;')
.column.is-narrow
h2= lang('ADMIN_USER_EDIT_ADMIN')
//- Yes, ternary exists, but I think the code is cleaner with a more "naive" style :)
Expand Down
31 changes: 24 additions & 7 deletions src/views/adminSettings.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ extends layout.pug

block content
h2= lang('ADMIN_SETTINGS_USERS_HEADER')
each user in users
span.is-size-6.inline= user.id
a(href=`${_CC.config.base}admin-settings/edit/${user.id}`)
span.is-size-7.icon.has-text-info
i.fas.fa-edit
span.is-sr-only
= lang('ADMIN_SETTINGS_USERS_EDIT')
table.table
thead
th=lang('ADMIN_SETTINGS_TABLE_USERNAME')
th=lang('ADMIN_SETTINGS_TABLE_ADMIN_USER')
th=lang('ADMIN_SETTINGS_TABLE_PLEDGE_ONLY')
th=lang('ADMIN_SETTINGS_TABLE_WISHLIST_COUNT')
th=lang('ADMIN_SETTINGS_TABLE_EDIT')
tbody
each user in users
tr(id=user.id)
td=user.id
td=user.doc.admin ? lang('YES') : lang('NO')
td=user.doc.pledgeOnly ? lang('YES') : lang('NO')
td=Object.keys(user.doc.wishlist).length
td
a(href=`${_CC.config.base}admin-settings/edit/${user.id}`)
span.is-size-7.icon.has-text-info
i.fas.fa-edit
span.is-sr-only
= lang('ADMIN_SETTINGS_USERS_EDIT')
br
h3= lang('ADMIN_SETTINGS_USERS_ADD_HEADER')
form(action=`${_CC.config.base}admin-settings/add`, method='POST')
Expand All @@ -19,6 +32,10 @@ block content
input.input(type='text', name='newUserUsername', placeholder=lang('ADMIN_SETTINGS_USERS_ADD_PLACEHOLDER'))
span.icon.is-small.is-left
i.fas.fa-user
.field
label.label= lang('ADMIN_SETTINGS_USERS_ADD_PLEDGE_ONLY')
.control.has-icons-left
input(type='checkbox', name='newPledgeOnlyUser')
.field
.control
input.button.is-primary(type='submit' value=lang('ADMIN_SETTINGS_USERS_ADD_BUTTON'))
Expand Down
3 changes: 2 additions & 1 deletion src/views/includes/navbar.pug
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ nav.navbar.is-fixed-top(role='navigation', aria-label='main navigation',style='b
.navbar-item.has-dropdown.is-hoverable
a.navbar-link= req.user._id
.navbar-dropdown
+navBarLink(`${_CC.config.base}wishlist/${req.user._id}`, lang('NAVBAR_WISHLIST'))
if !req.user.pledgeOnly
+navBarLink(`${_CC.config.base}wishlist/${req.user._id}`, lang('NAVBAR_WISHLIST'))
+navBarLink(`${_CC.config.base}profile`, lang('NAVBAR_PROFILE'))
if req.user.admin
+navBarLink(`${_CC.config.base}admin-settings`, lang('NAVBAR_ADMIN'))
Expand Down
31 changes: 16 additions & 15 deletions src/views/profile.pug
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ block content
button.button.is-primary(type='submit')
span.icon
i.fas.fa-save
h2= lang('PROFILE_SHARED_INFORMATION')
form(action=`${_CC.config.base}profile/info`, method='POST')
.columns.is-multiline.is-mobile
.column.is-narrow
+sharedInfoProp('shoeSize', 'PROFILE_SHOE_SIZE')
+sharedInfoProp('ringSize', 'PROFILE_RING_SIZE')
+sharedInfoProp('dressSize', 'PROFILE_DRESS_SIZE')
.column.is-narrow
+sharedInfoProp('sweaterSize', 'PROFILE_SWEATER_SIZE')
+sharedInfoProp('shirtSize', 'PROFILE_SHIRT_SIZE')
+sharedInfoProp('pantsSize', 'PROFILE_PANTS_SIZE')
.column.is-narrow
+sharedInfoProp('coatSize', 'PROFILE_COAT_SIZE')
+sharedInfoProp('hatSize', 'PROFILE_HAT_SIZE')
+sharedInfoProp('phoneModel', 'PROFILE_PHONE_MODEL')
if !req.user.pledgeOnly
h2= lang('PROFILE_SHARED_INFORMATION')
form(action=`${_CC.config.base}profile/info`, method='POST')
.columns.is-multiline.is-mobile
.column.is-narrow
+sharedInfoProp('shoeSize', 'PROFILE_SHOE_SIZE')
+sharedInfoProp('ringSize', 'PROFILE_RING_SIZE')
+sharedInfoProp('dressSize', 'PROFILE_DRESS_SIZE')
.column.is-narrow
+sharedInfoProp('sweaterSize', 'PROFILE_SWEATER_SIZE')
+sharedInfoProp('shirtSize', 'PROFILE_SHIRT_SIZE')
+sharedInfoProp('pantsSize', 'PROFILE_PANTS_SIZE')
.column.is-narrow
+sharedInfoProp('coatSize', 'PROFILE_COAT_SIZE')
+sharedInfoProp('hatSize', 'PROFILE_HAT_SIZE')
+sharedInfoProp('phoneModel', 'PROFILE_PHONE_MODEL')

h2= lang('PROFILE_SECURITY')
a.button.is-primary(href=`${_CC.config.base}profile/password`)
Expand Down
53 changes: 30 additions & 23 deletions src/views/wishlist.pug
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ block title
span= lang('WISHLIST_TITLE', name)
.level-right
.level-item
if ((!global._CC.config.pledgeSuggest && req.user.pledgeOnly) || !global._CC.config.suggestionsEnabled)
span= " "
else
a(href="#addWishlistItem").button.button.is-primary.is-rounded
span.icon
i.fas.fa-plus
Expand Down Expand Up @@ -262,30 +265,34 @@ block content
.field.inline
.control.inline
input.inline.button(type='submit' value=lang('WISHLIST_MOVE_ITEM_BOTTOM'))
form(method='POST')#addWishlistItem
.field
label.label!=lang('WISHLIST_URL_LABEL')
.control.has-icons-left
input.input(
type='text',
name='itemUrlOrName',
placeholder=lang('WISHLIST_URL_PLACEHOLDER')
)
span.icon.is-small.is-left
i.fas.fa-gift
.field
label.label= lang('WISHLIST_NOTE')
.control
textarea.textarea(
name='note',
placeholder=lang('WISHLIST_OPTIONAL')
)
.field.is-grouped
.control
input.button(type='submit' value=(req.user._id === req.params.user ? lang('WISHLIST_ADD') : lang('WISHLIST_PLEDGE_ITEM')))
if req.user._id !== req.params.user

if ((!global._CC.config.pledgeSuggest && req.user.pledgeOnly) || !global._CC.config.suggestionsEnabled)
.notification.is-info= lang('WISHLIST_SUGGESTIONS_DISABLED')
else
form(method='POST')#addWishlistItem
.field
label.label!=lang('WISHLIST_URL_LABEL')
.control.has-icons-left
input.input(
type='text',
name='itemUrlOrName',
placeholder=lang('WISHLIST_URL_PLACEHOLDER')
)
span.icon.is-small.is-left
i.fas.fa-gift
.field
label.label= lang('WISHLIST_NOTE')
.control
textarea.textarea(
name='note',
placeholder=lang('WISHLIST_OPTIONAL')
)
.field.is-grouped
.control
input.inline.button(type='submit', value=lang('WISHLIST_SUGGEST'), name='suggest')
input.button(type='submit' value=(req.user._id === req.params.user ? lang('WISHLIST_ADD') : lang('WISHLIST_PLEDGE_ITEM')))
if req.user._id !== req.params.user
.control
input.inline.button(type='submit', value=lang('WISHLIST_SUGGEST'), name='suggest')
script(src=`${_CC.config.base}js/wishlist.js`)

block print
Expand Down
4 changes: 2 additions & 2 deletions src/views/wishlists.pug
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ block content
div!= _CC.config.customHtml.wishlists

ul.noStyle.noLeftMargin
if req.user._id !== '_CCUNKNOWN'
if req.user._id !== '_CCUNKNOWN' && !req.user.pledgeOnly
li
.box
a(href=`${_CC.config.base}wishlist/${req.user._id}`, style='color: #4a4a4a;')
Expand All @@ -67,7 +67,7 @@ block content
progress.progress(value=1, max=1)
+wishlistDetails(req.user.wishlist, req.user._id)
each user in users
if req.user._id !== user.id
if req.user._id !== user.id && !user.doc.pledgeOnly
li
.box
a(href=`${_CC.config.base}wishlist/${user.id}`, style='color: #4a4a4a;')
Expand Down