From 6e17b7c17b6d5d6ae0a4b67b59ac9d8ba2dad191 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Thu, 10 Sep 2020 17:12:43 -0500 Subject: [PATCH] Updated GroupCategory functionality with Groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated: - GroupCategory functionality with Groups --- app/controllers/api/v1/groups_controller.rb | 4 ++- .../gabsocial/actions/group_editor.js | 4 +-- .../components/panel/group_info_panel.js | 26 ++++++++++++++++--- .../gabsocial/features/group_create.js | 2 +- .../gabsocial/reducers/group_editor.js | 2 +- app/models/group.rb | 6 ++++- ...2_remove_group_categories_id_from_group.rb | 5 ++++ ...foreign_key_to_group_for_group_category.rb | 6 +++++ ...foreign_key_to_group_for_group_category.rb | 5 ++++ db/schema.rb | 6 ++--- 10 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20200908210102_remove_group_categories_id_from_group.rb create mode 100644 db/migrate/20200908210103_add_foreign_key_to_group_for_group_category.rb create mode 100644 db/migrate/20200908210104_validate_add_foreign_key_to_group_for_group_category.rb diff --git a/app/controllers/api/v1/groups_controller.rb b/app/controllers/api/v1/groups_controller.rb index bffb8918..f113efb8 100644 --- a/app/controllers/api/v1/groups_controller.rb +++ b/app/controllers/api/v1/groups_controller.rb @@ -89,6 +89,8 @@ class Api::V1::GroupsController < Api::BaseController end def group_params - params.permit(:title, :cover_image, :description, :is_private, :tags, :is_visible, :group_categories_id, :slug) + thep = params.permit(:title, :password, :cover_image, :description, :is_private, :tags, :is_visible, :group_category_id, :slug) + thep[:tags] = thep[:tags].split(",") unless thep[:tags].nil? + thep end end diff --git a/app/javascript/gabsocial/actions/group_editor.js b/app/javascript/gabsocial/actions/group_editor.js index a4bb98dd..ab4d306b 100644 --- a/app/javascript/gabsocial/actions/group_editor.js +++ b/app/javascript/gabsocial/actions/group_editor.js @@ -62,7 +62,7 @@ const create = (options, routerHistory) => (dispatch, getState) => { formData.append('title', options.title) formData.append('description', options.description) formData.append('tags', options.tags) - formData.append('group_categories_id', options.category) + formData.append('group_category_id', options.category) formData.append('is_private', options.isPrivate) formData.append('is_visible', options.isVisible) @@ -105,7 +105,7 @@ const update = (groupId, options, routerHistory) => (dispatch, getState) => { formData.append('title', options.title) formData.append('description', options.description) formData.append('tags', options.tags) - formData.append('group_categories_id', options.category) + formData.append('group_category_id', options.category) formData.append('is_private', options.isPrivate) formData.append('is_visible', options.isVisible) formData.append('slug', options.slug) diff --git a/app/javascript/gabsocial/components/panel/group_info_panel.js b/app/javascript/gabsocial/components/panel/group_info_panel.js index 312c299c..4ab161c1 100644 --- a/app/javascript/gabsocial/components/panel/group_info_panel.js +++ b/app/javascript/gabsocial/components/panel/group_info_panel.js @@ -1,11 +1,13 @@ import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' +import { NavLink } from 'react-router-dom' import { defineMessages, injectIntl } from 'react-intl' import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePropTypes from 'react-immutable-proptypes' import moment from 'moment-mini' import { shortNumberFormat } from '../../utils/numbers' +import slugify from '../../utils/slugify' import PanelLayout from './panel_layout' import Button from '../button' import Divider from '../divider' @@ -39,6 +41,7 @@ class GroupInfoPanel extends ImmutablePureComponent { const isPrivate = !!group ? group.get('is_private') : false const isVisible = !!group ? group.get('is_visible') : false const tags = !!group ? group.get('tags') : [] + const groupCategory = !!group ? group.getIn(['group_category', 'text'], null) : null const descriptionHTML = !!group ? { __html: group.get('description_html') } : {} if (noPanel) { @@ -143,11 +146,26 @@ class GroupInfoPanel extends ImmutablePureComponent { - + { + !!groupCategory && + + - - General - + + + + + } diff --git a/app/javascript/gabsocial/features/group_create.js b/app/javascript/gabsocial/features/group_create.js index 88e1a2f7..dc76ae26 100644 --- a/app/javascript/gabsocial/features/group_create.js +++ b/app/javascript/gabsocial/features/group_create.js @@ -134,7 +134,7 @@ class GroupCreate extends ImmutablePureComponent { const memberCount = group ? group.get('member_count') : 0 const hasGroupSlug = group ? !!group.get('slug') : false - let categoriesOptions = [] + let categoriesOptions = [{'title':'',value:''}] if (categories) { for (let i = 0; i < categories.count(); i++) { const c = categories.get(i) diff --git a/app/javascript/gabsocial/reducers/group_editor.js b/app/javascript/gabsocial/reducers/group_editor.js index 3d4c2430..008d3555 100644 --- a/app/javascript/gabsocial/reducers/group_editor.js +++ b/app/javascript/gabsocial/reducers/group_editor.js @@ -53,7 +53,7 @@ export default function groupEditorReducer(state = initialState, action) { map.set('isPrivate', action.group.get('is_private')) map.set('isVisible', action.group.get('is_visible')) map.set('id', action.group.get('slug')) - map.set('category', action.group.get('category')) + map.set('category', action.group.getIn(['group_category', 'id'], null)) map.set('isSubmitting', false) }) case GROUP_EDITOR_TITLE_CHANGE: diff --git a/app/models/group.rb b/app/models/group.rb index 1673ac7e..1f666109 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -20,11 +20,13 @@ # is_private :boolean default(FALSE) # is_visible :boolean default(FALSE) # tags :string default([]), is an Array -# group_categories_id :bigint(8) # password :string +# group_category_id :integer # class Group < ApplicationRecord + self.ignored_columns = ["group_categories_id"] + include Paginable include GroupInteractions include GroupCoverImage @@ -45,6 +47,8 @@ class Group < ApplicationRecord has_many :group_removed_accounts, inverse_of: :group, dependent: :destroy has_many :removed_accounts, source: :account, through: :group_removed_accounts + belongs_to :group_categories, optional: true, foreign_key: 'group_category_id' + validates :title, presence: true validates :description, presence: true diff --git a/db/migrate/20200908210102_remove_group_categories_id_from_group.rb b/db/migrate/20200908210102_remove_group_categories_id_from_group.rb new file mode 100644 index 00000000..af3514b2 --- /dev/null +++ b/db/migrate/20200908210102_remove_group_categories_id_from_group.rb @@ -0,0 +1,5 @@ +class RemoveGroupCategoriesIdFromGroup < ActiveRecord::Migration[5.2] + def change + safety_assured { remove_column :groups, :group_categories_id } + end +end diff --git a/db/migrate/20200908210103_add_foreign_key_to_group_for_group_category.rb b/db/migrate/20200908210103_add_foreign_key_to_group_for_group_category.rb new file mode 100644 index 00000000..1dce5ffd --- /dev/null +++ b/db/migrate/20200908210103_add_foreign_key_to_group_for_group_category.rb @@ -0,0 +1,6 @@ +class AddForeignKeyToGroupForGroupCategory < ActiveRecord::Migration[5.2] + def change + add_column :groups, :group_category_id, :integer + add_foreign_key :groups, :group_categories, on_delete: :nullify, validate: false + end +end diff --git a/db/migrate/20200908210104_validate_add_foreign_key_to_group_for_group_category.rb b/db/migrate/20200908210104_validate_add_foreign_key_to_group_for_group_category.rb new file mode 100644 index 00000000..a5c6dae4 --- /dev/null +++ b/db/migrate/20200908210104_validate_add_foreign_key_to_group_for_group_category.rb @@ -0,0 +1,5 @@ +class ValidateAddForeignKeyToGroupForGroupCategory < ActiveRecord::Migration[5.2] + def change + validate_foreign_key :groups, :group_categories + end +end diff --git a/db/schema.rb b/db/schema.rb index 4281b33d..6fa418c8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_09_01_165533) do +ActiveRecord::Schema.define(version: 2020_09_08_210104) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" @@ -391,10 +391,9 @@ ActiveRecord::Schema.define(version: 2020_09_01_165533) do t.boolean "is_private", default: false t.boolean "is_visible", default: false t.string "tags", default: [], array: true - t.bigint "group_categories_id" t.string "password" + t.integer "group_category_id" t.index ["account_id"], name: "index_groups_on_account_id" - t.index ["group_categories_id"], name: "index_groups_on_group_categories_id" t.index ["slug"], name: "index_groups_on_slug", unique: true end @@ -959,6 +958,7 @@ ActiveRecord::Schema.define(version: 2020_09_01_165533) do add_foreign_key "group_pinned_statuses", "statuses", on_delete: :cascade add_foreign_key "group_removed_accounts", "accounts", on_delete: :cascade add_foreign_key "group_removed_accounts", "groups", on_delete: :cascade + add_foreign_key "groups", "group_categories", on_delete: :nullify add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade add_foreign_key "invites", "users", on_delete: :cascade