From 5a37a7090e06535f655b956d16c416f0f117a66d Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Thu, 17 Dec 2020 01:34:00 -0500 Subject: [PATCH] Progress accounts approved, video player testing, bookmark collections --- app/controllers/api/base_controller.rb | 4 + app/controllers/api/v1/accounts_controller.rb | 9 + .../bookmarks_controller.rb | 11 +- .../api/v1/bookmark_collections_controller.rb | 20 +- .../auth/registrations_controller.rb | 10 + app/controllers/manifests_controller.rb | 2 +- app/helpers/application_helper.rb | 13 ++ app/javascript/gabsocial/actions/albums.js | 17 +- app/javascript/gabsocial/actions/bookmarks.js | 17 +- .../modal/bookmark_collection_edit_modal.js | 29 +++ .../components/modal/edit_profile_modal.js | 2 + .../navigation_bar/profile_navigation_bar.js | 2 +- .../gabsocial/components/panel/shop_panel.js | 3 +- ...conversation_expiration_options_popover.js | 3 +- .../compose_post_destination_popover.js | 2 +- .../components/popover/popover_root.js | 3 + .../popover/status_options_popover.js | 119 ++++++++-- .../components/popover/user_info_popover.js | 37 ++- .../gabsocial/components/status_list.js | 4 + .../gabsocial/components/textarea.js | 3 + .../timeline_injections/shop_injection.js | 1 + .../gabsocial/components/user_stat.js | 7 +- app/javascript/gabsocial/components/video.js | 210 ++++-------------- app/javascript/gabsocial/constants.js | 2 + .../features/bookmark_collection_create.js | 20 +- .../features/bookmark_collection_edit.js | 100 +++++++++ .../features/bookmark_collections.js | 26 ++- .../gabsocial/features/bookmarked_statuses.js | 48 +++- .../components/compose_form_submit_button.js | 2 +- app/javascript/gabsocial/features/deck.js | 2 +- .../gabsocial/features/introduction.js | 1 + .../components/chat_message_compose_form.js | 39 +++- app/javascript/gabsocial/features/ui/ui.js | 6 +- .../features/ui/util/async_components.js | 3 + app/javascript/gabsocial/reducers/albums.js | 41 ++-- .../reducers/bookmark_collections.js | 33 +-- app/javascript/gabsocial/reducers/index.js | 3 + .../gabsocial/reducers/status_lists.js | 43 ++-- .../gabsocial/reducers/user_lists.js | 1 - app/models/account.rb | 4 +- app/models/chat_conversation_account.rb | 2 +- app/models/concerns/account_associations.rb | 9 +- app/models/concerns/account_interactions.rb | 6 - app/models/status_bookmark_collection.rb | 5 +- app/models/user.rb | 10 +- app/policies/group_policy.rb | 2 +- .../status_bookmark_collection_serializer.rb | 10 + app/serializers/rest/status_serializer.rb | 6 +- app/services/app_sign_up_service.rb | 7 + app/services/backup_service.rb | 8 + app/services/post_status_service.rb | 2 +- app/services/suspend_account_service.rb | 2 - app/validators/follow_limit_validator.rb | 1 + config/locales/simple_form.ar.yml | 2 +- config/locales/simple_form.ca.yml | 2 +- config/locales/simple_form.co.yml | 2 +- config/locales/simple_form.cs.yml | 2 +- config/locales/simple_form.cy.yml | 2 +- config/locales/simple_form.da.yml | 2 +- config/locales/simple_form.de.yml | 2 +- config/locales/simple_form.el.yml | 2 +- config/locales/simple_form.en.yml | 2 +- config/locales/simple_form.en_GB.yml | 2 +- config/locales/simple_form.eo.yml | 2 +- config/locales/simple_form.es.yml | 2 +- config/locales/simple_form.eu.yml | 2 +- config/locales/simple_form.fi.yml | 2 +- config/locales/simple_form.fr.yml | 2 +- config/locales/simple_form.gl.yml | 2 +- config/locales/simple_form.it.yml | 2 +- config/locales/simple_form.ja.yml | 2 +- config/locales/simple_form.nl.yml | 2 +- config/locales/simple_form.oc.yml | 2 +- config/locales/simple_form.pl.yml | 2 +- config/locales/simple_form.pt-BR.yml | 2 +- config/locales/simple_form.pt.yml | 2 +- config/locales/simple_form.ro.yml | 2 +- config/locales/simple_form.ru.yml | 2 +- config/locales/simple_form.sl.yml | 2 +- config/locales/simple_form.sq.yml | 2 +- config/locales/simple_form.sr.yml | 2 +- config/locales/simple_form.sv.yml | 2 +- config/locales/simple_form.th.yml | 2 +- config/locales/simple_form.zh-CN.yml | 2 +- config/locales/simple_form.zh-HK.yml | 2 +- config/routes.rb | 19 +- ...20201217003945_add_missing_foreign_keys.rb | 18 ++ db/schema.rb | 10 +- 88 files changed, 688 insertions(+), 395 deletions(-) rename app/controllers/api/v1/{ => bookmark_collections}/bookmarks_controller.rb (66%) create mode 100644 app/javascript/gabsocial/components/modal/bookmark_collection_edit_modal.js create mode 100644 app/javascript/gabsocial/features/bookmark_collection_edit.js create mode 100644 app/serializers/rest/status_bookmark_collection_serializer.rb create mode 100644 db/migrate/20201217003945_add_missing_foreign_keys.rb diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 00c6b356..647fa856 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -80,6 +80,10 @@ class Api::BaseController < ApplicationController # : todo : when figure out email/catpcha, put this back # elsif !current_user.confirmed? # render json: { error: 'Your login is missing a confirmed e-mail address' }, status: 403 + elsif current_user.account.is_flagged_as_spam? + render json: { error: 'Your account has been flagged as spam. Please contact support@gab.com if you believe this is an error.' }, status: 403 + elsif !current_user.approved? + render json: { error: 'Your login is currently pending approval' }, status: 403 else set_user_activity end diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 09ae8701..ab4bbeb6 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -10,6 +10,7 @@ class Api::V1::AccountsController < Api::BaseController before_action :require_user!, except: [:show, :create] before_action :set_account, except: [:create] before_action :check_account_suspension, only: [:show] + before_action :check_enabled_registrations, only: [:create] def show render json: @account, serializer: REST::AccountSerializer @@ -75,4 +76,12 @@ class Api::V1::AccountsController < Api::BaseController def account_params params.permit(:username, :email, :password, :agreement, :locale) end + + def check_enabled_registrations + forbidden if single_user_mode? || !allowed_registrations? + end + + def allowed_registrations? + Setting.registrations_mode != 'none' + end end diff --git a/app/controllers/api/v1/bookmarks_controller.rb b/app/controllers/api/v1/bookmark_collections/bookmarks_controller.rb similarity index 66% rename from app/controllers/api/v1/bookmarks_controller.rb rename to app/controllers/api/v1/bookmark_collections/bookmarks_controller.rb index f6aed818..6f56912e 100644 --- a/app/controllers/api/v1/bookmarks_controller.rb +++ b/app/controllers/api/v1/bookmark_collections/bookmarks_controller.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -class Api::V1::BookmarksController < Api::BaseController +class Api::V1::BookmarkCollections::BookmarksController < Api::BaseController before_action -> { doorkeeper_authorize! :read, :'read:bookmarks' } before_action :require_user! after_action :insert_pagination_headers def index - @statuses = [] if current_account.is_pro @statuses = load_statuses + render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id) + else + render json: { error: 'You need to be a GabPRO member to access this' }, status: 422 end - render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id) end private @@ -42,11 +43,11 @@ class Api::V1::BookmarksController < Api::BaseController end def next_path - api_v1_bookmarks_url pagination_params(max_id: pagination_max_id) if records_continue? + api_v1_bookmark_collection_bookmarks_url pagination_params(max_id: pagination_max_id) if records_continue? end def prev_path - api_v1_bookmarks_url pagination_params(since_id: pagination_since_id) unless results.empty? + api_v1_bookmark_collection_bookmarks_url pagination_params(since_id: pagination_since_id) unless results.empty? end def pagination_max_id diff --git a/app/controllers/api/v1/bookmark_collections_controller.rb b/app/controllers/api/v1/bookmark_collections_controller.rb index ea1f77a6..4be0ec47 100644 --- a/app/controllers/api/v1/bookmark_collections_controller.rb +++ b/app/controllers/api/v1/bookmark_collections_controller.rb @@ -3,24 +3,24 @@ class Api::V1::BookmarkCollectionsController < Api::BaseController before_action :require_user! before_action :set_bookmark_collections, only: :index - before_action :set_bookmark_collection, only: [:show, :update, :destroy] + before_action :set_bookmark_collection, only: [:show, :update, :destroy, :update_status] def index - render json: @bookmark_collections, each_serializer: REST::BookmarkCollectionSerializer + render json: @bookmark_collections, each_serializer: REST::StatusBookmarkCollectionSerializer end def create - @bookmark_collection = "" #current_account.custom_filters.create!(resource_params) - render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer + @bookmark_collection = current_account.status_bookmark_collections.create!(resource_params) + render json: @bookmark_collection, serializer: REST::StatusBookmarkCollectionSerializer end def show - render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer + render json: @bookmark_collection, serializer: REST::StatusBookmarkCollectionSerializer end def update @bookmark_collection.update!(resource_params) - render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer + render json: @bookmark_collection, serializer: REST::StatusBookmarkCollectionSerializer end def destroy @@ -28,14 +28,18 @@ class Api::V1::BookmarkCollectionsController < Api::BaseController render_empty_success end + def update_status + # + end + private def set_bookmark_collections - @bookmark_collections = "" #current_account.custom_filters + @bookmark_collections = current_account.status_bookmark_collections end def set_bookmark_collection - @bookmark_collection = "" # current_account.custom_filters.find(params[:id]) + @bookmark_collection = current_account.status_bookmark_collections.find(params[:id]) end def resource_params diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 6f1d41b1..1c51b4f0 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -4,6 +4,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController layout :determine_layout before_action :set_challenge, only: [:new] + before_action :check_enabled_registrations, only: [:new, :create] before_action :configure_sign_up_params, only: [:create] before_action :set_sessions, only: [:edit, :update] before_action :set_instance_presenter, only: [:new, :create, :update] @@ -90,4 +91,13 @@ class Auth::RegistrationsController < Devise::RegistrationsController def set_cache_headers response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate' end + + def check_enabled_registrations + redirect_to root_path if single_user_mode? || !allowed_registrations? + end + + def allowed_registrations? + Setting.registrations_mode != 'none' + end + end diff --git a/app/controllers/manifests_controller.rb b/app/controllers/manifests_controller.rb index 09985129..238469a5 100644 --- a/app/controllers/manifests_controller.rb +++ b/app/controllers/manifests_controller.rb @@ -3,7 +3,7 @@ class ManifestsController < EmptyController def show - render json: InstancePresenter.new, serializer: ManifestSerializer + render json: {} #InstancePresenter.new, serializer: ManifestSerializer end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 86a5a0d4..d9b2b692 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -104,4 +104,17 @@ module ApplicationHelper # : todo : return 'white' end + + def open_registrations? + Setting.registrations_mode == 'open' + end + + def approved_registrations? + Setting.registrations_mode == 'approved' + end + + def closed_registrations? + Setting.registrations_mode == 'none' + end + end diff --git a/app/javascript/gabsocial/actions/albums.js b/app/javascript/gabsocial/actions/albums.js index ab0c0141..478a7f98 100644 --- a/app/javascript/gabsocial/actions/albums.js +++ b/app/javascript/gabsocial/actions/albums.js @@ -1 +1,16 @@ -// \ No newline at end of file +import api, { getLinks } from '../api' +import { me } from '../initial_state' + +// + +export const ALBUMS_FETCH_REQUEST = 'ALBUMS_FETCH_REQUEST' +export const ALBUMS_FETCH_SUCCESS = 'ALBUMS_FETCH_SUCCESS' +export const ALBUMS_FETCH_FAIL = 'ALBUMS_FETCH_FAIL' + +export const ALBUMS_CREATE_REQUEST = 'ALBUMS_CREATE_REQUEST' +export const ALBUMS_CREATE_SUCCESS = 'ALBUMS_CREATE_SUCCESS' +export const ALBUMS_CREATE_FAIL = 'ALBUMS_CREATE_FAIL' + +export const ALBUMS_REMOVE_REQUEST = 'ALBUMS_REMOVE_REQUEST' +export const ALBUMS_REMOVE_SUCCESS = 'ALBUMS_REMOVE_SUCCESS' +export const ALBUMS_REMOVE_FAIL = 'ALBUMS_REMOVE_FAIL' \ No newline at end of file diff --git a/app/javascript/gabsocial/actions/bookmarks.js b/app/javascript/gabsocial/actions/bookmarks.js index e04dd817..99cc9a48 100644 --- a/app/javascript/gabsocial/actions/bookmarks.js +++ b/app/javascript/gabsocial/actions/bookmarks.js @@ -40,13 +40,13 @@ export const UPDATE_BOOKMARK_COLLECTION_STATUS_SUCCESS = 'UPDATE_BOOKMARK_COLLEC export const fetchBookmarkedStatuses = (bookmarkCollectionId) => (dispatch, getState) => { if (!me) return - if (getState().getIn(['status_lists', 'bookmarks', 'isLoading'])) { + if (getState().getIn(['status_lists', 'bookmarks', bookmarkCollectionId, 'isLoading'])) { return } dispatch(fetchBookmarkedStatusesRequest(bookmarkCollectionId)) - api(getState).get('/api/v1/bookmarks').then((response) => { + api(getState).get(`/api/v1/bookmark_collections/${bookmarkCollectionId}/bookmarks`).then((response) => { const next = getLinks(response).refs.find(link => link.rel === 'next') dispatch(importFetchedStatuses(response.data)) dispatch(fetchBookmarkedStatusesSuccess(response.data, bookmarkCollectionId, next ? next.uri : null)) @@ -57,6 +57,7 @@ export const fetchBookmarkedStatuses = (bookmarkCollectionId) => (dispatch, getS const fetchBookmarkedStatusesRequest = (bookmarkCollectionId) => ({ type: BOOKMARKED_STATUSES_FETCH_REQUEST, + bookmarkCollectionId, }) const fetchBookmarkedStatusesSuccess = (statuses, bookmarkCollectionId, next) => ({ @@ -98,10 +99,12 @@ export const expandBookmarkedStatuses = (bookmarkCollectionId) => (dispatch, get const expandBookmarkedStatusesRequest = (bookmarkCollectionId) => ({ type: BOOKMARKED_STATUSES_EXPAND_REQUEST, + bookmarkCollectionId, }) const expandBookmarkedStatusesSuccess = (statuses, bookmarkCollectionId, next) => ({ type: BOOKMARKED_STATUSES_EXPAND_SUCCESS, + bookmarkCollectionId, statuses, next, }) @@ -213,7 +216,7 @@ export const updateBookmarkCollection = (bookmarkCollectionId, title) => (dispat dispatch(updateBookmarkCollectionRequest()) - api(getState).post('/api/v1/bookmark_collections', { title }).then((response) => { + api(getState).put('/api/v1/bookmark_collections', { title }).then((response) => { dispatch(updateBookmarkCollectionSuccess(response.data)) }).catch((error) => { dispatch(updateBookmarkCollectionFail(error)) @@ -243,8 +246,9 @@ export const updateBookmarkCollectionStatus = (statusId, bookmarkCollectionId) = dispatch(updateBookmarkCollectionStatusRequest()) - api(getState).post('/api/v1/bookmark_collections', { title }).then((response) => { - dispatch(updateBookmarkCollectionStatusSuccess(response.data)) + api(getState).post(`/api/v1/bookmark_collections/${bookmarkCollectionId}/update_status`, { statusId }).then((response) => { + dispatch(importFetchedStatuses([response.data])) + dispatch(updateBookmarkCollectionStatusSuccess()) }).catch((error) => { dispatch(updateBookmarkCollectionStatusFail(error)) }) @@ -254,9 +258,8 @@ const updateBookmarkCollectionStatusRequest = () => ({ type: UPDATE_BOOKMARK_COLLECTION_STATUS_REQUEST, }) -const updateBookmarkCollectionStatusSuccess = (bookmarkCollection) => ({ +const updateBookmarkCollectionStatusSuccess = () => ({ type: UPDATE_BOOKMARK_COLLECTION_STATUS_SUCCESS, - bookmarkCollection, }) const updateBookmarkCollectionStatusFail = (error) => ({ diff --git a/app/javascript/gabsocial/components/modal/bookmark_collection_edit_modal.js b/app/javascript/gabsocial/components/modal/bookmark_collection_edit_modal.js new file mode 100644 index 00000000..7d5afbf6 --- /dev/null +++ b/app/javascript/gabsocial/components/modal/bookmark_collection_edit_modal.js @@ -0,0 +1,29 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { defineMessages, injectIntl } from 'react-intl' +import ModalLayout from './modal_layout' +import BookmarkCollectionEdit from '../../features/bookmark_collection_edit' + +class BookmarkCollectionEditModal extends React.PureComponent { + + render() { + const { onClose } = this.props + + return ( + + + + ) + } + +} + +BookmarkCollectionEditModal.propTypes = { + onClose: PropTypes.func.isRequired, +} + +export default BookmarkCollectionEditModal \ No newline at end of file diff --git a/app/javascript/gabsocial/components/modal/edit_profile_modal.js b/app/javascript/gabsocial/components/modal/edit_profile_modal.js index c2993d7c..90b55644 100644 --- a/app/javascript/gabsocial/components/modal/edit_profile_modal.js +++ b/app/javascript/gabsocial/components/modal/edit_profile_modal.js @@ -164,6 +164,7 @@ class EditProfileModal extends ImmutablePureComponent { diff --git a/app/javascript/gabsocial/components/navigation_bar/profile_navigation_bar.js b/app/javascript/gabsocial/components/navigation_bar/profile_navigation_bar.js index 6f11db5e..ff5990ad 100644 --- a/app/javascript/gabsocial/components/navigation_bar/profile_navigation_bar.js +++ b/app/javascript/gabsocial/components/navigation_bar/profile_navigation_bar.js @@ -33,7 +33,7 @@ class ProfileNavigationBar extends React.PureComponent { - - } { !paused && true && } -