Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tibetsprague committed Nov 13, 2022
2 parents c1535d8 + a94f687 commit f26eda6
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 39 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [5.0.2] - 2022-11-13

### Added
- New allow_in_public flag on groups that determines whether the group appears in the Group Explorer and whether posts from that group are allowed in the public stream. This flag is turned off for new groups by default while we figure out our strategy for deciding whether it should be on or off for any given group.
- Every new group has a #general topic added to it as a default topic. This will be more important/useful when topic based chat rooms are released soon!

### Fixed
- Update `hylo-shared` to fix bug in Mention HTMl generation
- Autolinking (links being turned into clickable links) in Group descriptions is turned back on
- Can set group settings when creating a group via API. This fixes an issue where the group's locationDisplayPrecision was not being set correctly.

## [5.0.1] - 2022-10-24

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/CommentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
// TODO: fix
const { groupId, userId } = res.locals.tokenData

const replyText = postId => TextHelpers.markdown(req.param(`post-${postId}`))
const replyText = postId => TextHelpers.markdown(req.param(`post-${postId}`, { disableAutolinking: true }))

const postIds = flow(
Object.keys,
Expand Down
13 changes: 8 additions & 5 deletions api/controllers/PostController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ const PostController = {
}
}))
.then(stop => stop || createPost(userId, attributes)
.tap(() => Analytics.track({
userId,
event: 'Add Post by Email Form',
properties: {group: group.get('name')}
}))
.then(post => {
Analytics.track({
userId,
event: 'Add Post by Email Form',
properties: {group: group.get('name')}
})
return post
})
.then(post => res.redirect(Frontend.Route.post(post, group))))
.catch(res.serverError)
},
Expand Down
10 changes: 8 additions & 2 deletions api/graphql/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const groupFilter = userId => relation => {
// non authenticated queries can only see public groups
if (!userId) {
q.where('groups.visibility', Group.Visibility.PUBLIC)
// Only show groups that are allowed to be show in public
q.andWhere('allow_in_public', true)
} else {
// the effect of using `where` like this is to wrap everything within its
// callback in parentheses -- this is necessary to keep `or` from "leaking"
Expand All @@ -38,7 +40,7 @@ export const groupFilter = userId => relation => {

// Can see groups you are a member of...
q2.whereIn('groups.id', selectIdsForMember)
// + their parent group
// + their parent groups
q2.orWhereIn('groups.id', parentGroupIds)
// + child groups that are not hidden, except moderators of a group can see its hidden children
q2.orWhere(q3 => {
Expand All @@ -49,7 +51,11 @@ export const groupFilter = userId => relation => {
q3.orWhereIn('groups.id', childrenOfModeratedGroupIds)
})
// + all public groups
q2.orWhere('groups.visibility', Group.Visibility.PUBLIC)
q2.orWhere(q5 => {
q5.where('groups.visibility', Group.Visibility.PUBLIC)
// Only show groups that are allowed to be show in public
q5.andWhere('allow_in_public', true)
})
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion api/models/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ module.exports = bookshelf.Model.extend(Object.assign({
})

const finalText = cutoff ? lines.slice(0, cutoff).join('\n') : text
return opts.useMarkdown ? TextHelpers.markdown(finalText || '') : finalText
return opts.useMarkdown ? TextHelpers.markdown(finalText || '', { disableAutolinking: true }) : finalText
},

notifyAboutMessage,
Expand Down
23 changes: 18 additions & 5 deletions api/models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ module.exports = bookshelf.Model.extend(merge({
return updatedMemberships.concat(newMemberships)
},

createDefaultTopics: async function (group_id, user_id, transacting) {
return Tag.where({ name: 'general' }).fetch({ transacting })
.then(generalTag => {
return GroupTag.create({ updated_at: new Date(), group_id, tag_id: generalTag.get('id'), user_id, is_default: true }, { transacting })
})
},

createInitialWidgets: async function (transacting) {
// In the future this will have to look up the template of whatever group is being created and add widgets based on that
const initialWidgets = await Widget.query(q => q.whereIn('id', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 19, 20, 21])).fetchAll({ transacting })
Expand Down Expand Up @@ -527,11 +534,11 @@ module.exports = bookshelf.Model.extend(merge({
throw new GraphQLYogaError("A group with that URL slug already exists")
}

var attrs = defaults(
let attrs = defaults(
pick(data,
'about_video_uri', 'accessibility', 'avatar_url', 'description', 'slug', 'category',
'access_code', 'banner_url', 'location_id', 'location', 'group_data_type', 'moderator_descriptor',
'moderator_descriptor_plural', 'name', 'type', 'type_descriptor', 'type_descriptor_plural', 'visibility'
'moderator_descriptor_plural', 'name', 'settings', 'type', 'type_descriptor', 'type_descriptor_plural', 'visibility'
),
{
'accessibility': Group.Accessibility.RESTRICTED,
Expand All @@ -542,9 +549,13 @@ module.exports = bookshelf.Model.extend(merge({
}
)

// XXX: temporary, by default show all farms in public. These can only be created via API right now
if (attrs.type === 'farm') {
attrs.allow_in_public = true
}

// eslint-disable-next-line camelcase
const access_code = attrs.access_code || await Group.getNewAccessCode()

const group = new Group(merge(attrs, {
access_code,
created_at: new Date(),
Expand All @@ -553,7 +564,7 @@ module.exports = bookshelf.Model.extend(merge({
}))

const memberships = await bookshelf.transaction(async trx => {
await group.save(null, {transacting: trx})
await group.save(null, { transacting: trx })

if (data.group_extensions) {
for (const extData of data.group_extensions) {
Expand All @@ -570,9 +581,11 @@ module.exports = bookshelf.Model.extend(merge({
await group.createStarterPosts(trx)

await group.createInitialWidgets(trx)

await group.createDefaultTopics(group.id, userId, trx)

const members = await group.addMembers([userId],
{role: GroupMembership.Role.MODERATOR}, { transacting: trx })
{ role: GroupMembership.Role.MODERATOR }, { transacting: trx })

// Have to add/request add to parent group after moderator has been added to the group
if (data.parent_ids) {
Expand Down
29 changes: 18 additions & 11 deletions api/models/post/createPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ import setupPostAttrs from './setupPostAttrs'
import updateChildren from './updateChildren'
import { groupRoom, pushToSockets } from '../../services/Websockets'

export default function createPost (userId, params) {
export default async function createPost (userId, params) {
if (params.isPublic) {
// Don't allow creating a public post unless at least one of the post's groups has allow_in_public set to true
const groups = await Group.query(q => q.whereIn('id', params.group_ids)).fetchAll()
const allowedToMakePublic = groups.find(g => g.get('allow_in_public'))
if (!allowedToMakePublic) params.isPublic = false
}

return setupPostAttrs(userId, merge(Post.newPostAttrs(), params))
.then(attrs => bookshelf.transaction(transacting =>
Post.create(attrs, { transacting })
.tap(post => afterCreatingPost(post, merge(
pick(params, 'group_ids', 'imageUrl', 'videoUrl', 'docs', 'topicNames', 'memberIds', 'eventInviteeIds', 'imageUrls', 'fileUrls', 'announcement', 'location', 'location_id'),
{children: params.requests, transacting}
)))).then(function(inserts) {
return inserts
}).catch(function(error) {
throw error
})
.then(attrs => bookshelf.transaction(transacting =>
Post.create(attrs, { transacting })
.tap(post => afterCreatingPost(post, merge(
pick(params, 'group_ids', 'imageUrl', 'videoUrl', 'docs', 'topicNames', 'memberIds', 'eventInviteeIds', 'imageUrls', 'fileUrls', 'announcement', 'location', 'location_id'),
{children: params.requests, transacting}
)))).then(function(inserts) {
return inserts
}).catch(function(error) {
throw error
})
)
}

Expand Down
1 change: 0 additions & 1 deletion api/models/post/setupPostAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getOr } from 'lodash/fp'
export default function setupPostAttrs (userId, params) {
const attrs = merge({
user_id: userId,
visibility: params.public ? Post.Visibility.PUBLIC_READABLE : Post.Visibility.DEFAULT,
link_preview_id: params.link_preview_id || getOr(null, 'id', params.linkPreview),
parent_post_id: params.parent_post_id,
updated_at: new Date(),
Expand Down
2 changes: 1 addition & 1 deletion api/services/InvitationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module.exports = {
if (tag) {
opts.tagId = tag.id
} else {
opts.message = TextHelpers.markdown(message)
opts.message = TextHelpers.markdown(message, { disableAutolinking: true })
opts.moderator = isModerator
opts.subject = subject
}
Expand Down
11 changes: 11 additions & 0 deletions migrations/20221110125837_show-in-public-flag-to-groups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = function (knex) {
return knex.schema.table('groups', table => {
table.boolean('allow_in_public').defaultTo(false)
})
}

exports.down = function (knex) {
return knex.schema.table('groups', table => {
table.dropColumn('allow_in_public')
})
}
10 changes: 9 additions & 1 deletion migrations/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ CREATE TABLE public.groups (
type_descriptor_plural character varying(255) DEFAULT NULL::character varying,
moderator_descriptor character varying(255) DEFAULT NULL::character varying,
moderator_descriptor_plural character varying(255) DEFAULT NULL::character varying,
about_video_uri character varying(255)
about_video_uri character varying(255),
allow_in_public boolean DEFAULT false
);


Expand Down Expand Up @@ -1664,6 +1665,7 @@ CREATE TABLE public.posts (
is_public boolean DEFAULT false,
donations_link character varying(255),
project_management_link character varying(255),
reactions_summary jsonb,
link_preview_featured boolean DEFAULT false
);

Expand Down Expand Up @@ -5046,6 +5048,12 @@ ALTER TABLE ONLY public.users
ADD CONSTRAINT users_stripe_account_id_foreign FOREIGN KEY (stripe_account_id) REFERENCES public.stripe_accounts(id);


--
-- Data seeding
--

insert into tags (name) values ('general') ON CONFLICT DO NOTHING

--
-- PostgreSQL database dump complete
--
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Tibet Sprague <tibet@hylo.com>",
"license": "GNU AFFERO GENERAL PUBLIC LICENSE v3",
"private": true,
"version": "5.0.1",
"version": "5.0.2",
"repository": {
"type": "git",
"url": "git://github.com/Hylozoic/hylo-node.git"
Expand Down Expand Up @@ -102,7 +102,7 @@
"hast-util-to-string": "^1.0.1",
"hastscript": "^3.1.0",
"he": "^1.2.0",
"hylo-shared": "5.0.0",
"hylo-shared": "5.1.0",
"image-size": "^0.3.5",
"insane": "^2.6.2",
"jade": "^1.11.0",
Expand Down
1 change: 1 addition & 0 deletions test/unit/models/GroupExtension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('GroupExtension', function () {
slug: 'comm1',
group_data_type: 1
}
await Tag.findOrCreate('general')
user = await new User({ name: 'username', email: 'john@foo.com', active: true }).save()
await Group.create(user.id, data)
savedGroup = await Group.find('comm1')
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7036,15 +7036,15 @@ https-proxy-agent@^5.0.0, https-proxy-agent@^5.0.1:
agent-base "6"
debug "4"

hylo-shared@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/hylo-shared/-/hylo-shared-5.0.0.tgz#7cc76a87d092947b9c78aafb270e059d29866e41"
integrity sha512-72wTvmE1VfZEZ6Hk6jdrmXz4ocF66Y6FkHFDjqRwO9KYe5FSRwOY9tImperx12sB8GZY+Ss1R8sn0JF8IhOyyA==
hylo-shared@5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/hylo-shared/-/hylo-shared-5.1.0.tgz#e4cdb43a2d65926d195bb70e6a24b874efc03f52"
integrity sha512-YWXEs8F/Sw6yazUi6Nii8JMoLa9P5HfnUJ8B+JcyZNs3EaDbf04FVZdi1bFYMgzcl+uNNx9ebRWY+2mJPGRqoQ==
dependencies:
coordinate-parser "^1.0.7"
html-to-text "^8.1.0"
lodash "~4.17.21"
marked "^4.0.12"
marked "^4.2.1"
pretty-date "^0.2.0"
querystring "^0.2.1"
trunc-html "^1.1.2"
Expand Down Expand Up @@ -8645,10 +8645,10 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

marked@^4.0.12:
version "4.1.1"
resolved "https://registry.yarnpkg.com/marked/-/marked-4.1.1.tgz#2f709a4462abf65a283f2453dc1c42ab177d302e"
integrity sha512-0cNMnTcUJPxbA6uWmCmjWz4NJRe/0Xfk2NhXCUHjew9qJzFN20krFnsUe7QynwqOwa5m1fZ4UDg0ycKFVC0ccw==
marked@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/marked/-/marked-4.2.1.tgz#eaa32594e45b4e58c02e4d118531fd04345de3b4"
integrity sha512-VK1/jNtwqDLvPktNpL0Fdg3qoeUZhmRsuiIjPEy/lHwXW4ouLoZfO4XoWd4ClDt+hupV1VLpkZhEovjU0W/kqA==

math-interval-parser@^2.0.1:
version "2.0.1"
Expand Down

0 comments on commit f26eda6

Please sign in to comment.