source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/first_run.rb
Ruby
mit
4,291
main
385
class FirstRun ACCOUNT_NAME = "Campfire" FIRST_ROOM_NAME = "All Talk" def self.create!(user_params) account = Account.create!(name: ACCOUNT_NAME) room = Rooms::Open.new(name: FIRST_ROOM_NAME) administrator = room.creator = User.new(user_params.merge(role: :administrator)) room.save! room...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/purchaser.rb
Ruby
mit
4,291
main
337
class Purchaser def initialize load_configuration end def registered? @purchased_by.present? end def name @purchased_by["name"] if registered? end private def load_configuration path = Rails.root.join("config/purchased_by.yml") @purchased_by = YAML.load_file(path) if path.ex...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/sound.rb
Ruby
mit
4,291
main
3,874
class Sound class Image < Struct.new(:asset_path, :width, :height) def initialize(name:, width:, height:) super "sounds/#{name}", width, height end end def self.find_by_name(name) INDEX[name] end def self.names INDEX.keys.sort end attr_reader :name, :asset_path, :image, :text d...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/ban.rb
Ruby
mit
4,291
main
485
class Ban < ApplicationRecord belongs_to :user validate :ip_address_is_public def self.banned?(ip_address) exists?(ip_address: ip_address) end private def ip_address_is_public ip = IPAddr.new(ip_address) if ip.loopback? || ip.private? || ip.link_local? errors.add(:ip_address, "...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/room.rb
Ruby
mit
4,291
main
1,806
class Room < ApplicationRecord has_many :memberships, dependent: :delete_all do def grant_to(users) room = proxy_association.owner Membership.insert_all(Array(users).collect { |user| { room_id: room.id, user_id: user.id, involvement: room.default_involvement } }) end def revoke_from(users) ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/message.rb
Ruby
mit
4,291
main
1,168
class Message < ApplicationRecord include Attachment, Broadcasts, Mentionee, Pagination, Searchable belongs_to :room, touch: true belongs_to :creator, class_name: "User", default: -> { Current.user } has_many :boosts, dependent: :destroy has_rich_text :body before_create -> { self.client_message_id ||= ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/search.rb
Ruby
mit
4,291
main
365
class Search < ApplicationRecord belongs_to :user after_create :trim_recent_searches scope :ordered, -> { order(updated_at: :desc) } class << self def record(query) find_or_create_by(query: query).touch end end private def trim_recent_searches user.searches.excluding(user.searche...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/message/mentionee.rb
Ruby
mit
4,291
main
278
module Message::Mentionee extend ActiveSupport::Concern def mentionees room.users.where(id: mentioned_users.map(&:id)) end private def mentioned_users if body.body body.body.attachables.grep(User).uniq else [] end end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/message/pagination.rb
Ruby
mit
4,291
main
844
module Message::Pagination extend ActiveSupport::Concern PAGE_SIZE = 40 included do scope :last_page, -> { ordered.last(PAGE_SIZE) } scope :first_page, -> { ordered.first(PAGE_SIZE) } scope :before, ->(message) { where("created_at < ?", message.created_at) } scope :after, ->(message) { where("c...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/message/searchable.rb
Ruby
mit
4,291
main
892
module Message::Searchable extend ActiveSupport::Concern included do after_create_commit :create_in_index after_update_commit :update_in_index after_destroy_commit :remove_from_index scope :search, ->(query) { joins("join message_search_index idx on messages.id = idx.rowid").where("idx.body matc...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/message/broadcasts.rb
Ruby
mit
4,291
main
269
module Message::Broadcasts def broadcast_create broadcast_append_to room, :messages, target: [ room, :messages ] ActionCable.server.broadcast("unread_rooms", { roomId: room.id }) end def broadcast_remove broadcast_remove_to room, :messages end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/message/attachment.rb
Ruby
mit
4,291
main
892
module Message::Attachment extend ActiveSupport::Concern THUMBNAIL_MAX_WIDTH = 1200 THUMBNAIL_MAX_HEIGHT = 800 included do has_one_attached :attachment do |attachable| attachable.variant :thumb, resize_to_limit: [ THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT ] end end module ClassMethods d...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/account/joinable.rb
Ruby
mit
4,291
main
316
module Account::Joinable extend ActiveSupport::Concern included do before_create { self.join_code = generate_join_code } end def reset_join_code update! join_code: generate_join_code end private def generate_join_code SecureRandom.alphanumeric(12).scan(/.{4}/).join("-") end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/opengraph/fetch.rb
Ruby
mit
4,291
main
2,452
require "net/http" require "restricted_http/private_network_guard" class Opengraph::Fetch ALLOWED_DOCUMENT_CONTENT_TYPE = "text/html" MAX_BODY_SIZE = 5.megabytes MAX_REDIRECTS = 10 class TooManyRedirectsError < StandardError; end class RedirectDeniedError < StandardError; end def fetch_document(url, ip: ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/opengraph/metadata.rb
Ruby
mit
4,291
main
686
class Opengraph::Metadata include ActiveModel::Model include ActiveModel::Validations::Callbacks include ActionView::Helpers::SanitizeHelper include Fetching ATTRIBUTES = %i[ title url image description ] attr_accessor *ATTRIBUTES before_validation :sanitize_fields validates_presence_of :title, :url...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/opengraph/location.rb
Ruby
mit
4,291
main
1,475
require "restricted_http/private_network_guard" class Opengraph::Location include ActiveModel::Validations attr_accessor :url, :parsed_url validate :validate_url, :validate_url_is_public def initialize(url) @url = url end def read_html fetch_html if valid? && !url.match(FILES_AND_MEDIA_URL_REGE...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/opengraph/document.rb
Ruby
mit
4,291
main
818
require "nokogiri" class Opengraph::Document attr_accessor :html def initialize(html) @html = Nokogiri::HTML(html) end def opengraph_attributes @opengraph_attributes ||= extract_opengraph_attributes end private def extract_opengraph_attributes opengraph_tags = html.xpath("//*/meta[star...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/opengraph/metadata/fetching.rb
Ruby
mit
4,291
main
2,481
module Opengraph::Metadata::Fetching extend ActiveSupport::Concern module ClassMethods def from_url(url) document = fetch_document(url) attributes = document.opengraph_attributes new attributes.merge(url: valid_canonical_url(attributes[:url], url), image: valid_image_content_type(attributes[:...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/user/bot.rb
Ruby
mit
4,291
main
1,432
module User::Bot extend ActiveSupport::Concern included do scope :active_bots, -> { active.where(role: :bot) } scope :without_bots, -> { where.not(role: :bot) } has_one :webhook, dependent: :delete end module ClassMethods def create_bot!(attributes) bot_token = generate_bot_token w...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/user/mentionable.rb
Ruby
mit
4,291
main
269
module User::Mentionable include ActionText::Attachable def to_attachable_partial_path "users/mention" end def to_trix_content_attachment_partial_path "users/mention" end def attachable_plain_text_representation(caption) "@#{name}" end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/user/transferable.rb
Ruby
mit
4,291
main
315
module User::Transferable extend ActiveSupport::Concern TRANSFER_LINK_EXPIRY_DURATION = 4.hours class_methods do def find_by_transfer_id(id) find_signed(id, purpose: :transfer) end end def transfer_id signed_id(purpose: :transfer, expires_in: TRANSFER_LINK_EXPIRY_DURATION) end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/user/bannable.rb
Ruby
mit
4,291
main
745
module User::Bannable extend ActiveSupport::Concern def ban transaction do create_bans_from_sessions apply_ban banned! end end def unban transaction do bans.delete_all active! end end def remove_banned_content_later RemoveBannedContentJob.perform_later(se...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/user/avatar.rb
Ruby
mit
4,291
main
271
module User::Avatar extend ActiveSupport::Concern included do has_one_attached :avatar end class_methods do def from_avatar_token(sid) find_signed!(sid, purpose: :avatar) end end def avatar_token signed_id(purpose: :avatar) end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/user/role.rb
Ruby
mit
4,291
main
234
module User::Role extend ActiveSupport::Concern included do enum :role, %i[ member administrator bot ] end def can_administer?(record = nil) administrator? || self == record&.creator || record&.new_record? end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/room/message_pusher.rb
Ruby
mit
4,291
main
1,829
class Room::MessagePusher attr_reader :room, :message def initialize(room:, message:) @room, @message = room, message end def push build_payload.tap do |payload| push_to_users_involved_in_everything(payload) push_to_users_involved_in_mentions(payload) end end private def build...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/membership/connectable.rb
Ruby
mit
4,291
main
1,253
module Membership::Connectable extend ActiveSupport::Concern CONNECTION_TTL = 60.seconds included do scope :connected, -> { where(connected_at: CONNECTION_TTL.ago..) } scope :disconnected, -> { where(connected_at: [ nil, ...CONNECTION_TTL.ago ]) } end class_methods do def disconnect_all ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/push/subscription.rb
Ruby
mit
4,291
main
246
class Push::Subscription < ApplicationRecord belongs_to :user def notification(**params) WebPush::Notification.new(**params, badge: user.memberships.unread.count, endpoint: endpoint, p256dh_key: p256dh_key, auth_key: auth_key) end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/rooms/open.rb
Ruby
mit
4,291
main
341
# Rooms open to all users on the account. When a new user is added to the account, they're automatically granted membership. class Rooms::Open < Room after_save_commit :grant_access_to_all_users private def grant_access_to_all_users memberships.grant_to(User.active) if type_previously_changed?(to: "Rooms...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/models/rooms/direct.rb
Ruby
mit
4,291
main
720
# Rooms for direct message chats between users. These act as a singleton, so a single set of users will # always refer to the same direct room. class Rooms::Direct < Room class << self def find_or_create_for(users) find_for(users) || create_for({}, users: users) end private # FIXME: Find a mo...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/first_runs_controller.rb
Ruby
mit
4,291
main
533
class FirstRunsController < ApplicationController allow_unauthenticated_access before_action :prevent_repeats def show @user = User.new end def create user = FirstRun.create!(user_params) start_new_session_for user redirect_to root_url rescue ActiveRecord::RecordNotUnique redirect_to...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/pwa_controller.rb
Ruby
mit
4,291
main
313
class PwaController < ApplicationController allow_unauthenticated_access skip_forgery_protection # We need a stable URL at the root, so we can't use the regular asset path here. def service_worker end # Need ERB interpolation for paths, so can't use asset path here either. def manifest end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/application_controller.rb
Ruby
mit
4,291
main
263
class ApplicationController < ActionController::Base include AllowBrowser, Authentication, Authorization, BlockBannedRequests, SetCurrentRequest, SetPlatform, TrackedRoomVisit, VersionHeaders include Turbo::Streams::Broadcasts, Turbo::Streams::StreamName end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/messages_controller.rb
Ruby
mit
4,291
main
2,013
class MessagesController < ApplicationController include ActiveStorage::SetCurrent, RoomScoped before_action :set_room, except: :create before_action :set_message, only: %i[ show edit update destroy ] before_action :ensure_can_administer, only: %i[ edit update destroy ] layout false, only: :index def ind...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/users_controller.rb
Ruby
mit
4,291
main
777
class UsersController < ApplicationController require_unauthenticated_access only: %i[ new create ] before_action :set_user, only: :show before_action :verify_join_code, only: %i[ new create ] def new @user = User.new end def create @user = User.create!(user_params) start_new_session_for @use...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/rooms_controller.rb
Ruby
mit
4,291
main
1,427
class RoomsController < ApplicationController before_action :set_room, only: %i[ show destroy ] before_action :ensure_can_administer, only: %i[ destroy ] before_action :remember_last_room_visited, only: :show def index redirect_to room_url(Current.user.rooms.last) end def show @messages = find_mes...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/searches_controller.rb
Ruby
mit
4,291
main
677
class SearchesController < ApplicationController before_action :set_messages def index @query = query if query.present? @recent_searches = Current.user.searches.ordered @return_to_room = last_room_visited end def create Current.user.searches.record(query) redirect_to searches_url(q: query)...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/accounts_controller.rb
Ruby
mit
4,291
main
760
class AccountsController < ApplicationController before_action :ensure_can_administer, only: :update before_action :set_account def edit users = account_users.ordered.without_bots @administrators, @members = users.partition(&:administrator?) set_page_and_extract_portion_from users, per_page: 500 en...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/unfurl_links_controller.rb
Ruby
mit
4,291
main
289
class UnfurlLinksController < ApplicationController def create opengraph = Opengraph::Metadata.from_url(url_param) if opengraph.valid? render json: opengraph else head :no_content end end private def url_param params.require(:url) end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/sessions_controller.rb
Ruby
mit
4,291
main
1,064
class SessionsController < ApplicationController allow_unauthenticated_access only: %i[ new create ] rate_limit to: 10, within: 3.minutes, only: :create, with: -> { render_rejection :too_many_requests } before_action :ensure_user_exists, only: :new def new end def create if user = User.active.authent...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/qr_code_controller.rb
Ruby
mit
4,291
main
331
class QrCodeController < ApplicationController allow_unauthenticated_access def show url = Base64.urlsafe_decode64(params[:id]) qr_code = RQRCode::QRCode.new(url).as_svg(viewbox: true, fill: :white, color: :black) expires_in 1.year, public: true render plain: qr_code, content_type: "image/svg+xml"...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/users/push_subscriptions_controller.rb
Ruby
mit
4,291
main
729
class Users::PushSubscriptionsController < ApplicationController before_action :set_push_subscriptions def index end def create if subscription = @push_subscriptions.find_by(push_subscription_params) subscription.touch else @push_subscriptions.create! push_subscription_params.merge(user_ag...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/users/sidebars_controller.rb
Ruby
mit
4,291
main
991
class Users::SidebarsController < ApplicationController DIRECT_PLACEHOLDERS = 20 def show all_memberships = Current.user.memberships.visible.with_ordered_room @direct_memberships = extract_direct_memberships(all_memberships) @other_memberships = all_memberships.without(@direct_memberships) @d...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/users/bans_controller.rb
Ruby
mit
4,291
main
314
class Users::BansController < ApplicationController before_action :ensure_can_administer before_action :set_user def create @user.ban redirect_to @user end def destroy @user.unban redirect_to @user end private def set_user @user = User.find(params[:user_id]) end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/users/avatars_controller.rb
Ruby
mit
4,291
main
1,159
class Users::AvatarsController < ApplicationController include ActiveStorage::Streaming rescue_from(ActiveSupport::MessageVerifier::InvalidSignature) { head :not_found } def show @user = User.from_avatar_token(params[:user_id]) if stale?(etag: @user) expires_in 30.minutes, public: true, stale_whi...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/users/profiles_controller.rb
Ruby
mit
4,291
main
645
class Users::ProfilesController < ApplicationController before_action :set_user def show @direct_memberships, @shared_memberships = Current.user.memberships.with_ordered_room.partition { |m| m.room.direct? } end def update @user.update user_params redirect_to user_profile_url, notice: update...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/users/push_subscriptions/test_notifications_controller.rb
Ruby
mit
4,291
main
457
class Users::PushSubscriptions::TestNotificationsController < ApplicationController before_action :set_push_subscription def create @push_subscription.notification(title: "Campfire Test", body: Random.uuid, path: user_push_subscriptions_url).deliver redirect_to user_push_subscriptions_url end private ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/autocompletable/users_controller.rb
Ruby
mit
4,291
main
469
class Autocompletable::UsersController < ApplicationController def index set_page_and_extract_portion_from find_autocompletable_users.with_attached_avatar.ordered, per_page: 20 end private def find_autocompletable_users params[:query].present? ? users_scope.active.filtered_by(params[:query]) : user...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/authentication.rb
Ruby
mit
4,291
main
2,689
module Authentication extend ActiveSupport::Concern include SessionLookup included do before_action :require_authentication before_action :deny_bots helper_method :signed_in? protect_from_forgery with: :exception, unless: -> { authenticated_by.bot_key? } end class_methods do def allow_u...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/room_scoped.rb
Ruby
mit
4,291
main
251
module RoomScoped extend ActiveSupport::Concern included do before_action :set_room end private def set_room @membership = Current.user.memberships.find_by!(room_id: params[:room_id]) @room = @membership.room end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/version_headers.rb
Ruby
mit
4,291
main
312
module VersionHeaders extend ActiveSupport::Concern included do before_action :set_version_headers end private def set_version_headers response.headers["X-Version"] = Rails.application.config.app_version response.headers["X-Rev"] = Rails.application.config.git_revision end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/set_current_request.rb
Ruby
mit
4,291
main
261
module SetCurrentRequest extend ActiveSupport::Concern included do before_action do Current.request = request end end def default_url_options { host: Current.request_host, protocol: Current.request_protocol }.compact_blank end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/block_banned_requests.rb
Ruby
mit
4,291
main
319
module BlockBannedRequests extend ActiveSupport::Concern included do before_action :reject_banned_ip, unless: :safe_request? end private def reject_banned_ip head :too_many_requests if Ban.banned?(request.remote_ip) end def safe_request? request.get? || request.head? end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/set_platform.rb
Ruby
mit
4,291
main
204
module SetPlatform extend ActiveSupport::Concern included do helper_method :platform end private def platform @platform ||= ApplicationPlatform.new(request.user_agent) end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/allow_browser.rb
Ruby
mit
4,291
main
259
module AllowBrowser extend ActiveSupport::Concern VERSIONS = { safari: 17.2, chrome: 120, firefox: 121, opera: 104, ie: false } included do allow_browser versions: VERSIONS, block: -> { render template: "sessions/incompatible_browser" } end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/concerns/tracked_room_visit.rb
Ruby
mit
4,291
main
380
module TrackedRoomVisit extend ActiveSupport::Concern included do helper_method :last_room_visited end def remember_last_room_visited cookies.permanent[:last_room] = @room.id end def last_room_visited Current.user.rooms.find_by(id: cookies[:last_room]) || default_room end private def...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/rooms/closeds_controller.rb
Ruby
mit
4,291
main
2,043
class Rooms::ClosedsController < RoomsController before_action :set_room, only: %i[ show edit update ] before_action :ensure_can_administer, only: %i[ update ] before_action :remember_last_room_visited, only: :show before_action :force_room_type, only: %i[ edit update ] before_action :ensure_permission_to_cre...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/rooms/directs_controller.rb
Ruby
mit
4,291
main
820
class Rooms::DirectsController < RoomsController before_action :set_room, only: %i[ edit destroy ] def new @room = Rooms::Direct.new end def create room = Rooms::Direct.find_or_create_for(selected_users) broadcast_create_room(room) redirect_to room_url(room) end def edit end private ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/rooms/refreshes_controller.rb
Ruby
mit
4,291
main
453
class Rooms::RefreshesController < ApplicationController include RoomScoped before_action :set_last_updated_at def show @new_messages = @room.messages.with_creator.page_created_since(@last_updated_at) @updated_messages = @room.messages.without(@new_messages).with_creator.page_updated_since(@last_updated...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/rooms/opens_controller.rb
Ruby
mit
4,291
main
1,348
class Rooms::OpensController < RoomsController before_action :set_room, only: %i[ show edit update ] before_action :ensure_can_administer, only: %i[ update ] before_action :remember_last_room_visited, only: :show before_action :force_room_type, only: %i[ edit update ] before_action :ensure_permission_to_creat...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/rooms/involvements_controller.rb
Ruby
mit
4,291
main
761
class Rooms::InvolvementsController < ApplicationController include RoomScoped def show @involvement = @membership.involvement end def update @membership.update! involvement: params[:involvement] broadcast_visibility_changes redirect_to room_involvement_url(@room) end private def bro...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/messages/by_bots_controller.rb
Ruby
mit
4,291
main
471
class Messages::ByBotsController < MessagesController allow_bot_access only: :create def create super head :created, location: message_url(@message) end private def message_params if params[:attachment] params.permit(:attachment) else reading(request.body) { |body| { bo...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/messages/boosts_controller.rb
Ruby
mit
4,291
main
907
class Messages::BoostsController < ApplicationController before_action :set_message def index end def new end def create @boost = @message.boosts.create!(boost_params) broadcast_create redirect_to message_boosts_url(@message) end def destroy @boost = Current.user.boosts.find(params[...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/sessions/transfers_controller.rb
Ruby
mit
4,291
main
308
class Sessions::TransfersController < ApplicationController allow_unauthenticated_access def show end def update if user = User.active.find_by_transfer_id(params[:id]) start_new_session_for user redirect_to post_authenticating_url else head :bad_request end end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/accounts/logos_controller.rb
Ruby
mit
4,291
main
1,390
class Accounts::LogosController < ApplicationController include ActiveStorage::Streaming, ActionView::Helpers::AssetUrlHelper allow_unauthenticated_access only: :show before_action :ensure_can_administer, only: :destroy def show if stale?(etag: Current.account) expires_in 5.minutes, public: true, st...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/accounts/users_controller.rb
Ruby
mit
4,291
main
627
class Accounts::UsersController < ApplicationController before_action :ensure_can_administer, :set_user, only: %i[ update destroy ] def index set_page_and_extract_portion_from User.active.ordered.without_bots, per_page: 500 end def update @user.update(role_params) redirect_to edit_account_url en...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/accounts/custom_styles_controller.rb
Ruby
mit
4,291
main
415
class Accounts::CustomStylesController < ApplicationController before_action :ensure_can_administer, :set_account def edit end def update @account.update!(account_params) redirect_to edit_account_custom_styles_url, notice: "✓" end private def set_account @account = Current.account e...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/accounts/bots_controller.rb
Ruby
mit
4,291
main
699
class Accounts::BotsController < ApplicationController before_action :ensure_can_administer before_action :set_bot, only: %i[ edit update destroy ] def index @bots = User.active_bots.ordered end def new @bot = User.active_bots.new end def create User.create_bot! bot_params redirect_to a...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
app/controllers/accounts/bots/keys_controller.rb
Ruby
mit
4,291
main
214
class Accounts::Bots::KeysController < ApplicationController before_action :ensure_can_administer def update User.active_bots.find(params[:bot_id]).reset_bot_key redirect_to account_bots_url end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/importmap.rb
Ruby
mit
4,291
main
827
pin "application" pin "@hotwired/stimulus", to: "stimulus.min.js" pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" pin "@hotwired/turbo-rails", to: "turbo.js" pin "@rails/actioncable", to: "actioncable.esm.js" pin "@rails/request.js", to: "@rails--request.js" # @0.0.8 pin "trix", to: "trix.esm.min.js" # @2....
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/application.rb
Ruby
mit
4,291
main
641
require_relative "boot" require "rails/all" Bundler.require(*Rails.groups) module Campfire class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 8.2 # Please, add to the `ignore` list any other `lib` subdirectories that ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/ci.rb
Ruby
mit
4,291
main
810
# Run using bin/ci CI.run do step "Setup", "bin/setup --skip-server" step "Style: Ruby", "bin/rubocop" step "Style: GitHub Actions (actionlint)", "actionlint" step "Style: GitHub Actions (zizmor)", "zizmor ." step "Security: Gem audit", "bin/bundler-audit" step "Security: Importmap vulnerability audit", ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/puma.rb
Ruby
mit
4,291
main
2,103
require File.expand_path("../config/environment", File.dirname(__FILE__)) # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified fo...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/routes.rb
Ruby
mit
4,291
main
2,348
Rails.application.routes.draw do root "welcome#show" resource :first_run resource :session do scope module: "sessions" do resources :transfers, only: %i[ show update ] end end resource :account do scope module: "accounts" do resources :users resources :bots do scope m...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/environments/production.rb
Ruby
mit
4,291
main
3,665
require "active_support/core_ext/integer/time" require "active_support/core_ext/numeric/bytes" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.enable_reloading = false # Eager load code on boot ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/environments/test.rb
Ruby
mit
4,291
main
2,432
require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data the...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/environments/development.rb
Ruby
mit
4,291
main
2,949
require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Make code changes take effect immediately without server restart. config.enable_reloading = true # Do not eager load code on boot. config.eager...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/environments/performance.rb
Ruby
mit
4,291
main
1,505
require_relative "production" Rails.application.configure do config.assume_ssl = false config.force_ssl = false config.action_cable.disable_request_forgery_protection = true config.after_initialize do if defined?(Rails::Server) && User.none? Account.create!(name: "Campfire") password_digest ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/initializers/filter_parameter_logging.rb
Ruby
mit
4,291
main
443
# Be sure to restart your server when you modify this file. # Configure parameters to be filtered from the log file. Use this to limit dissemination of # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported # notations and behaviors. Rails.application.config.filter_parameters += [ ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/initializers/content_security_policy.rb
Ruby
mit
4,291
main
1,044
# Be sure to restart your server when you modify this file. # Define an application-wide content security policy. # See the Securing Rails Applications Guide for more information: # https://guides.rubyonrails.org/security.html#content-security-policy-header # Rails.application.configure do # config.content_security...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/initializers/vapid.rb
Ruby
mit
4,291
main
270
Rails.application.configure do config.x.vapid.private_key = ENV.fetch("VAPID_PRIVATE_KEY", Rails.application.credentials.dig(:vapid, :private_key)) config.x.vapid.public_key = ENV.fetch("VAPID_PUBLIC_KEY", Rails.application.credentials.dig(:vapid, :public_key)) end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/initializers/web_push.rb
Ruby
mit
4,291
main
1,247
require "web-push" require "web_push/pool" require "web_push/notification" Rails.application.configure do config.x.web_push_pool = WebPush::Pool.new( invalid_subscription_handler: ->(subscription_id) do Rails.application.executor.wrap do Rails.logger.info "Destroying push subscription: #{subscripti...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/initializers/inflections.rb
Ruby
mit
4,291
main
640
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflec...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
config/initializers/sentry.rb
Ruby
mit
4,291
main
278
if Rails.env.production? && ENV["SKIP_TELEMETRY"].blank? Sentry.init do |config| config.dsn = ENV["SENTRY_DSN"] config.breadcrumbs_logger = [ :active_support_logger, :http_logger ] config.send_default_pii = false config.release = ENV["GIT_REVISION"] end end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/application_system_test_case.rb
Ruby
mit
4,291
main
214
require "test_helper" WebMock.disable! class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] include SystemTestHelper end
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/test_helper.rb
Ruby
mit
4,291
main
866
ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" require "rails/test_help" require "minitest/unit" require "mocha/minitest" require "webmock/minitest" require "turbo/broadcastable/test_helper" WebMock.enable! class ActiveSupport::TestCase include ActiveJob::TestHelper parallelize(workers: :n...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/system/sending_messages_test.rb
Ruby
mit
4,291
main
1,573
require "application_system_test_case" class SendingMessagesTest < ApplicationSystemTestCase setup do sign_in "jz@37signals.com" join_room rooms(:designers) end test "sending messages between two users" do using_session("Kevin") do sign_in "kevin@37signals.com" join_room rooms(:designers...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/system/unread_rooms_test.rb
Ruby
mit
4,291
main
594
require "application_system_test_case" class UnreadRoomsTest < ApplicationSystemTestCase setup do sign_in "jz@37signals.com" end test "sending messages between two users" do designers_room = rooms(:designers) hq_room = rooms(:hq) join_room hq_room assert_room_read hq_room using_session...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/system/boosting_messages_test.rb
Ruby
mit
4,291
main
2,446
require "application_system_test_case" class BoostingMessagesTest < ApplicationSystemTestCase setup do sign_in "kevin@37signals.com" join_room rooms(:designers) end test "boosting a message" do within_message messages(:third) do reveal_message_actions fill_in_boost_input "Good morning" ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/unfurl_links_controller_test.rb
Ruby
mit
4,291
main
2,300
require "test_helper" class UnfurlLinksControllerTest < ActionDispatch::IntegrationTest setup do sign_in :david end test "create" do stub_successful_request post unfurl_link_url, params: { url: "https://www.example.com" } assert_response :success json_response = JSON.parse(response.body) ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/qr_code_controller_test.rb
Ruby
mit
4,291
main
431
require "test_helper" class QrCodeControllerTest < ActionDispatch::IntegrationTest test "show renders a QR code as a cacheable SVG image" do id = Base64.urlsafe_encode64("http://example.com") get qr_code_path(id) assert_response :success assert_includes response.content_type, "image/svg+xml" a...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/accounts_controller_test.rb
Ruby
mit
4,291
main
1,946
require "test_helper" class AccountsControllerTest < ActionDispatch::IntegrationTest setup do sign_in :david end test "edit" do get edit_account_url assert_response :ok end test "edit groups administrators separately from members with a divider" do get edit_account_url assert_response ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/welcome_controller_test.rb
Ruby
mit
4,291
main
486
require "test_helper" class WelcomeControllerTest < ActionDispatch::IntegrationTest setup do sign_in :david end test "redirects to the first created visible room the user has access to" do get root_url assert_redirected_to room_url(users(:david).rooms.original) end test "redirects to the last ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/first_runs_controller_test.rb
Ruby
mit
4,291
main
1,638
require "test_helper" class FirstRunsControllerTest < ActionDispatch::IntegrationTest setup do Account.destroy_all User.destroy_all Room.destroy_all end test "new is permitted when no other users exit" do get first_run_url assert_response :success end test "new is not permitted when acc...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/messages_controller_test.rb
Ruby
mit
4,291
main
5,127
require "test_helper" class MessagesControllerTest < ActionDispatch::IntegrationTest setup do host! "once.campfire.test" sign_in :david @room = rooms(:watercooler) @messages = @room.messages.ordered.to_a end test "index returns the last page by default" do get room_messages_url(@room) ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/users_controller_test.rb
Ruby
mit
4,291
main
1,367
require "test_helper" class UsersControllerTest < ActionDispatch::IntegrationTest setup do @join_code = accounts(:signal).join_code end test "show" do sign_in :david get user_url(users(:david)) assert_response :ok end test "new" do get join_url(@join_code) assert_response :success ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/sessions_controller_test.rb
Ruby
mit
4,291
main
2,149
require "test_helper" class SessionsControllerTest < ActionDispatch::IntegrationTest ALLOWED_BROWSER = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15" DISALLOWED_BROWSER = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/searches_controller_test.rb
Ruby
mit
4,291
main
1,191
require "test_helper" class SearchesControllerTest < ActionDispatch::IntegrationTest setup do sign_in :david @message = rooms(:designers).messages.create! body: "Hello world!", client_message_id: "search", creator: users(:david) end test "index initial view" do get searches_url assert_response ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/rooms_controller_test.rb
Ruby
mit
4,291
main
1,102
require "test_helper" class RoomsControllerTest < ActionDispatch::IntegrationTest setup do sign_in :david end test "index redirects to the user's last room" do get rooms_url assert_redirected_to room_url(users(:david).rooms.last) end test "show" do get room_url(users(:david).rooms.last) ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/concerns/block_banned_requests_test.rb
Ruby
mit
4,291
main
943
require "test_helper" class BlockBannedRequestsTest < ActionDispatch::IntegrationTest setup do sign_in :david @room = rooms(:watercooler) Ban.create!(user: users(:kevin), ip_address: "203.0.113.1") end test "POST requests from banned IPs are blocked with 429" do post room_messages_url(@room), ...
github
basecamp/once-campfire
https://github.com/basecamp/once-campfire
test/controllers/rooms/refreshes_controller_test.rb
Ruby
mit
4,291
main
984
require "test_helper" class Rooms::RefreshesControllerTest < ActionDispatch::IntegrationTest setup do sign_in :david end test "refresh includes new messages since the last known" do travel_to 1.day.ago do @old_message = rooms(:hq).messages.create!(creator: users(:jason), body: "Old message", clien...