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
alphagov/publisher
https://github.com/alphagov/publisher
app/workers/downtime_scheduler.rb
Ruby
mit
48
main
1,014
class DowntimeScheduler include Sidekiq::Worker def self.schedule_publish_and_expiry(downtime) return if downtime.nil? # publish the downtime message at midnight the night before display_date = downtime.display_start_time perform_now_or_later(downtime.id.to_s, display_date) # remove the downt...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/traits/recordable_actions.rb
Ruby
mit
48
main
1,538
require "action" module RecordableActions extend ActiveSupport::Concern included do has_many :actions, dependent: :destroy def latest_status_action(type = nil) if type actions.where(request_type: type).order(created_at: :desc).first else actions.where(request_type: Action::STAT...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/decorators/user_search_edition_decorator.rb
Ruby
mit
48
main
2,900
# Decorator class around editions, to provide user history methods class UserSearchEditionDecorator def initialize(edition, user) @edition = edition @user = user end def method_missing(method_name, ...) @edition.send(method_name, ...) end def respond_to_missing?(method_name, *) @edition.resp...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/user_search_controller.rb
Ruby
mit
48
main
1,582
require "edition" class UserSearchController < ApplicationController respond_to :html include ColumnSortable def index @user_filter = params[:user_filter] || current_user.uid @user = params[:user_filter] ? User.where(uid: @user_filter).first : current_user raise ActionController::RoutingError, "Not ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/sitemap_controller.rb
Ruby
mit
48
main
248
class SitemapController < ApplicationController skip_before_action :verify_authenticity_token skip_before_action :authenticate_user! def index @paths = Edition.published.flat_map(&:paths) respond_to { |format| format.xml } end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/downtimes_controller.rb
Ruby
mit
48
main
3,676
class DowntimesController < ApplicationController before_action :require_govuk_editor before_action :load_edition, except: [:index] layout "design_system" def index @transactions = Edition.where(editionable_type: "TransactionEdition", state: "published").order(%i[title]) end def new @downtime = D...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/homepage_controller.rb
Ruby
mit
48
main
4,307
class HomepageController < ApplicationController layout "design_system" before_action :fetch_latest_popular_link before_action :require_homepage_editor_permissions include GDS::SSO::ControllerMethods def show render "homepage/popular_links/show" end def create @latest_popular_links = @latest_po...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/reports_controller.rb
Ruby
mit
48
main
1,319
class ReportsController < ApplicationController layout "design_system" include ActionView::Helpers::TagHelper before_action :authenticate_user! def index; end def progress redirect_to Report.new("editorial_progress").url, allow_other_host: true end def organisation_content redirect_to Report....
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/publications_controller.rb
Ruby
mit
48
main
654
class PublicationsController < InheritedResources::Base def show edition = Edition.find_or_create_from_panopticon_data(params[:id], current_user) if edition.persisted? UpdateWorker.perform_async(edition.id.to_s) redirect_with_return_to(edition) else render_new_form(edition) end en...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/legacy_notes_controller.rb
Ruby
mit
48
main
991
class LegacyNotesController < InheritedResources::Base belongs_to :edition before_action :require_editor_permissions include PathsHelper def create comment = params[:note][:comment] type = params[:note][:type] || Action::NOTE if comment.blank? && type == Action::IMPORTANT_NOTE resolve_impor...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/application_controller.rb
Ruby
mit
48
main
2,737
class ApplicationController < ActionController::Base protect_from_forgery with: :exception layout "legacy_application" include GDS::SSO::ControllerMethods before_action :authenticate_user! rescue_from ActiveRecord::RecordNotFound, with: :record_not_found rescue_from Notifications::Client::BadRequestError...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/editions_controller.rb
Ruby
mit
48
main
24,059
class EditionsController < InheritedResources::Base include TabbedNavHelper layout "design_system" defaults resource_class: Edition, collection_name: "editions", instance_name: "resource" before_action :setup_view_paths, except: %i[index] before_action except: %i[index] do require_user_accessibility_to_...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/legacy_artefacts_controller.rb
Ruby
mit
48
main
1,762
class LegacyArtefactsController < ApplicationController before_action :require_editor_permission def new @artefact = Artefact.new(content_id: SecureRandom.uuid) end def create @artefact = Artefact.new if @artefact.update_as(current_user, creatable_params) redirect_to publication_path(@artefa...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/artefacts_controller.rb
Ruby
mit
48
main
2,553
class ArtefactsController < ApplicationController layout "design_system" before_action :require_govuk_editor def new @artefact = Artefact.new end def content_details if params.dig(:artefact, :kind).blank? @artefact = Artefact.new @artefact.errors.add(:kind, "Select a content type") ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/filtered_editions_controller.rb
Ruby
mit
48
main
2,044
class FilteredEditionsController < ApplicationController layout "design_system" def my_content @presenter = FilteredEditionsPresenter.new( current_user, states_filter: Edition.state_names.excluding(:archived, :published), assigned_to_filter: current_user.id, ) end def fact_check ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/legacy_editions_controller.rb
Ruby
mit
48
main
12,601
require "edition_duplicator" require "edition_progressor" class LegacyEditionsController < InheritedResources::Base actions :create, :update, :destroy defaults resource_class: Edition, collection_name: "editions", instance_name: "resource" before_action :setup_view_paths, except: %i[index new create] before_ac...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/notes_controller.rb
Ruby
mit
48
main
1,098
class NotesController < InheritedResources::Base belongs_to :edition before_action :require_editor_permissions include PathsHelper def create comment = params[:note][:comment] type = params[:note][:type] || Action::NOTE if comment.blank? && type == Action::IMPORTANT_NOTE resolve_important_n...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/column_sortable.rb
Ruby
mit
48
main
393
module ColumnSortable def self.included(base) # Expose sort_column and sort_direction for template access base.helper_method :sort_column, :sort_direction end private def sort_column Edition.column_names.include?(params[:sort]) ? params[:sort] : "updated_at" end def sort_direction %w[asc de...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/link_check_reports_controller.rb
Ruby
mit
48
main
793
class LinkCheckReportsController < ApplicationController before_action :find_edition def create service = LinkCheckReportCreator.new( edition: @edition, ) @report = service.call respond_to do |format| format.js { render "link_check_reports/create" } format.html { redirect_to edi...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/content_item_controller.rb
Ruby
mit
48
main
468
class ContentItemController < ApplicationController def by_content_id artefact = Artefact.find_by(content_id: params[:content_id]) if artefact redirect_to find_content_path(search_text: artefact.latest_edition.slug) else redirect_with_error end rescue StandardError redirect_with_err...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/guide_parts_controller.rb
Ruby
mit
48
main
4,609
# frozen_string_literal: true class GuidePartsController < InheritedResources::Base belongs_to :edition layout "design_system" defaults resource_class: Part, collection_name: "parts", instance_name: "part" before_action do @edition = parent end before_action :setup_view_paths before_action do r...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/link_checker_api_controller.rb
Ruby
mit
48
main
1,231
class LinkCheckerApiController < ApplicationController skip_before_action :verify_authenticity_token skip_before_action :authenticate_user! before_action :verify_signature rescue_from ActiveRecord::RecordNotFound, with: :render_no_content def callback if link_check_report LinkCheckReportUpdater.ne...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/tagging_controller.rb
Ruby
mit
48
main
8,088
# frozen_string_literal: true class TaggingController < InheritedResources::Base layout "design_system" defaults resource_class: Edition, collection_name: "editions", instance_name: "resource" before_action :setup_view_paths before_action :require_editor_permissions SERVICE_REQUEST_ERROR_MESSAGE = "Due to...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/publishing_api_proxy_controller.rb
Ruby
mit
48
main
307
class PublishingApiProxyController < ApplicationController def lookup_by_base_path content_id = Services.publishing_api.lookup_content_id(base_path: params[:base_path]) if content_id.present? render json: { content_id: } else render json: {}, status: :not_found end end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/controllers/api/fact_check_response_controller.rb
Ruby
mit
48
main
1,480
module Api class FactCheckResponseController < Api::BaseController def process_response # Temporarily locking this down to local running and Integration environment while FCM is in development unless Rails.env.local? || Rails.env.test? || ENV["GOVUK_ENVIRONMENT"] == "integration" return render...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/validators/slug_validator.rb
Ruby
mit
48
main
3,297
class SlugValidator < ActiveModel::EachValidator # implement the method called during validation def validate_each(record, attribute, value) validators = [ DonePageValidator, HelpPageValidator, FinderEmailSignupValidator, ManualPageValidator, DefaultValidator, ].map { |klass| k...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/validators/link_validator.rb
Ruby
mit
48
main
1,485
class LinkValidator < ActiveModel::Validator def validate(record) record.class::GOVSPEAK_FIELDS.each do |govspeak_field_name| govspeak_field_value = record.read_attribute(govspeak_field_name) next if govspeak_field_value.blank? messages = errors(govspeak_field_value) messages.each do |mes...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/validators/reviewer_validator.rb
Ruby
mit
48
main
556
class ReviewerValidator < ActiveModel::Validator def validate(record) if record.reviewer validate_reviewer_in_review(record) validate_reviewer_not_assignee(record) end end private def validate_reviewer_in_review(record) unless record.in_review? record.errors.add(:reviewer, "can onl...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/validators/safe_html.rb
Ruby
mit
48
main
1,377
require "govspeak" require "plek" class SafeHtml < ActiveModel::Validator ALLOWED_IMAGE_HOSTS = [ # URLs for the local environment URI.parse(Plek.website_root).host, # eg www.gov.uk URI.parse(Plek.asset_root).host, # eg assets.publishing.service.gov.uk # Hardcode production URLs so that content co...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/mailers/event_mailer.rb
Ruby
mit
48
main
3,537
class EventMailer < ApplicationMailer include PathsHelper helper(PathsHelper) helper(WorkingDaysHelper) def any_action(action, recipient_email) @action = action @preview_url = preview_edition_path(@action.edition) subject = "[PUBLISHER] #{describe_action(@action)}" view_mail(template_id, to: r...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/contracts/fact_check_response_contract.rb
Ruby
mit
48
main
410
class FactCheckResponseContract < Dry::Validation::Contract json do required(:edition_id).filled(:string) required(:responder_name).filled(:string) required(:accepted).filled(:bool) optional(:comment).filled(:string) end rule(:comment, :accepted) do if !values[:accepted] && values[:comment].n...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/simple_smart_answer_edition.rb
Ruby
mit
48
main
4,545
class SimpleSmartAnswerEdition < ApplicationRecord include Editionable validates :start_button_text, presence: true has_many :nodes, class_name: "SimpleSmartAnswerEdition::Node", dependent: :destroy accepts_nested_attributes_for :nodes, allow_destroy: true delegate :title, to: :edition GOVSPEAK_FIELDS ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/scotland_availability.rb
Ruby
mit
48
main
247
require "devolved_administration_availability" class ScotlandAvailability < DevolvedAdministrationAvailability belongs_to :local_transaction_edition, class_name: "LocalTransactionEdition", inverse_of: :scotland_availability, optional: false end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/local_service.rb
Ruby
mit
48
main
545
require "csv" require_dependency "safe_html" class LocalService < ApplicationRecord validates :lgsl_code, :providing_tier, presence: true validates :lgsl_code, uniqueness: true validate :eligible_providing_tier def self.find_by_lgsl_code(lgsl_code) LocalService.where(lgsl_code:).first end def eligibl...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/parted.rb
Ruby
mit
48
main
1,260
require_dependency "part" module Parted def self.included(klass) class_to_sym = klass.to_s.underscore.to_sym klass.has_many :parts, inverse_of: class_to_sym, dependent: :destroy klass.accepts_nested_attributes_for :parts, allow_destroy: true klass.after_validation :merge_embedded_parts_errors end ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/artefact.rb
Ruby
mit
48
main
7,260
require "plek" require "artefact_action" # Require this when running outside Rails require_dependency "safe_html" class Artefact < ApplicationRecord strip_attributes only: :redirect_url scope :not_archived, -> { where.not(state: %w[archived]) } FORMATS_BY_DEFAULT_OWNING_APP = { "publisher" => %w[answer ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/transaction_edition.rb
Ruby
mit
48
main
505
require "edition" class TransactionEdition < ApplicationRecord include Editionable strip_attributes only: :link GOVSPEAK_FIELDS = %i[introduction more_information alternate_methods need_to_know].freeze validates :start_button_text, presence: true def indexable_content "#{Govspeak::Document.new(introd...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/editionable.rb
Ruby
mit
48
main
806
module Editionable extend ActiveSupport::Concern included do has_one :edition, as: :editionable validates_with SafeHtml, unless: :popular_links_edition? validates_with LinkValidator, on: :update, unless: :archiving_or_popular_links? delegate :major_change, :change_note, :overview, :latest_status_...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/user.rb
Ruby
mit
48
main
2,478
require "digest/md5" require "cgi" require "gds-sso/user" require_dependency "safe_html" class User < ApplicationRecord include GDS::SSO::User has_many :artefact_actions, class_name: "ArtefactAction" scope :alphabetized, -> { order(name: :asc) } scope :enabled, -> { where("disabled IS NULL OR disabled = ?", ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/northern_ireland_availability.rb
Ruby
mit
48
main
263
require "devolved_administration_availability" class NorthernIrelandAvailability < DevolvedAdministrationAvailability belongs_to :local_transaction_edition, class_name: "LocalTransactionEdition", inverse_of: :northern_ireland_availability, optional: false end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/link_check_report.rb
Ruby
mit
48
main
626
class LinkCheckReport < ApplicationRecord belongs_to :edition has_many :links, dependent: :destroy accepts_nested_attributes_for :links # rubocop/disable Rails/UniqueValidationWithoutIndex validates :batch_id, presence: true, uniqueness: true # rubocop/enable Rails/UniqueValidationWithoutIndex # valid...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/workflow.rb
Ruby
mit
48
main
7,203
require "state_machines-activerecord" module Workflow class CannotDeletePublishedPublication < RuntimeError; end extend ActiveSupport::Concern included do validate :not_editing_published_item before_destroy :check_can_delete_and_notify after_destroy :notify_siblings_of_published_edition before_...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/part.rb
Ruby
mit
48
main
1,054
require_dependency "safe_html" class Part < ApplicationRecord belongs_to :guide_edition, optional: true belongs_to :programme_edition, optional: true scope :in_order, -> { order(:order) } GOVSPEAK_FIELDS = [:body].freeze validates :title, presence: { message: ->(obj, _) { "Enter a title#{obj.send(:validat...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/artefact_external_link.rb
Ruby
mit
48
main
241
class ArtefactExternalLink < ApplicationRecord strip_attributes only: :url belongs_to :artefact validates :title, presence: true validates :url, presence: true, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]) } end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/host_content_update_event.rb
Ruby
mit
48
main
1,579
class HostContentUpdateEvent < Data.define(:author, :created_at, :content_id, :content_title, :document_type) Author = Data.define(:name, :email) def self.all_for_artefact(artefact) events = Services.publishing_api.get_events_for_content_id(artefact.content_id, { action: "HostContentUpdateJob", }) ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/downtime.rb
Ruby
mit
48
main
733
class Downtime < ApplicationRecord belongs_to :artefact, optional: true validate :start_time_precedes_end_time validate :end_time_is_in_future validates :message, :start_time, :end_time, :artefact, presence: true def self.for(artefact) where(artefact_id: artefact.id).first end def publicise? Ti...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/action.rb
Ruby
mit
48
main
2,037
require_dependency "safe_html" class Action < ApplicationRecord STATUS_ACTIONS = [ CREATE = "create".freeze, REQUEST_REVIEW = "request_review".freeze, APPROVE_REVIEW = "approve_review".freeze, APPROVE_FACT_CHECK = "approve_fact_check".freeze, ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/artefact_action.rb
Ruby
mit
48
main
482
class ArtefactAction < ApplicationRecord belongs_to :artefact belongs_to :user, optional: true # Not validating presence of a user just yet, since there may be some # circumstances where we can't reliably determine the user. As an example # of this, requests made through the API are not yet tied to a user. I...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/edition.rb
Ruby
mit
48
main
16,307
require_dependency "workflow" require "digest" class Edition < ApplicationRecord include Workflow include RecordableActions include BaseHelper def self.delegated_types %w[AnswerEdition GuideEdition TransactionEdition HelpPageEdition SimpleSmartAnswerEdition CompletedTransactionEdition LocalTransactionEdi...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/devolved_administration_availability.rb
Ruby
mit
48
main
766
class DevolvedAdministrationAvailability < ApplicationRecord validates :authority_type, inclusion: { in: %w[local_authority_service devolved_administration_service unavailable] } validates :alternative_url, presence: { message: "Enter the URL of the devolved administration website page" }, if: -> { devolved_adminis...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/report.rb
Ruby
mit
48
main
672
require "aws-sdk-s3" class Report def initialize(report_name) @bucket_name = ENV["REPORTS_S3_BUCKET_NAME"] @s3 = Aws::S3::Client.new @report_name = report_name end def filename "#{@report_name}.csv" end def upload_to_s3(body) @s3.put_object( bucket: @bucket_name, key: filen...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/local_transaction_edition.rb
Ruby
mit
48
main
2,771
require "local_service" class LocalTransactionEdition < ApplicationRecord include Editionable has_one :scotland_availability, inverse_of: :local_transaction_edition, class_name: "ScotlandAvailability", dependent: :destroy has_one :wales_availability, inverse_of: :local_transaction_edition, class_name: "WalesAva...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/wales_availability.rb
Ruby
mit
48
main
242
require "devolved_administration_availability" class WalesAvailability < DevolvedAdministrationAvailability belongs_to :local_transaction_edition, class_name: "LocalTransactionEdition", inverse_of: :wales_availability, optional: false end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/popular_links_edition.rb
Ruby
mit
48
main
2,168
class PopularLinksEdition < ApplicationRecord include Editionable validate :six_link_items_present validate :all_valid_urls_and_titles_are_present def six_link_items_present errors.add(:link_items, "6 links are required") if link_items.count != 6 end def all_valid_urls_and_titles_are_present link...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/guide_edition.rb
Ruby
mit
48
main
298
require "parted" class GuideEdition < ApplicationRecord include Editionable include Parted strip_attributes only: :video_url GOVSPEAK_FIELDS = [].freeze def has_video? video_url.present? end def safe_to_preview? super && parts.any? && parts.first.slug.present? end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/healthcheck/scheduled_publishing.rb
Ruby
mit
48
main
715
module Healthcheck class ScheduledPublishing def name :schedule_queue end def status queue_size_matches_edition_count? ? :ok : :warning end def details { queue_size:, edition_count:, } end def message "#{edition_count} scheduled edition(s); ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/edition/tab.rb
Ruby
mit
48
main
690
class Edition class Tab TABS = %w[edit tagging metadata history admin related_external_links unpublish].freeze attr_accessor :name def initialize(name = nil) @name = name end def self.all @all ||= TABS.map { |name| Tab.new(name) } end def self.[](name) Tab.new(name) ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/simple_smart_answer_edition/node.rb
Ruby
mit
48
main
1,015
class SimpleSmartAnswerEdition class Node < ApplicationRecord belongs_to :simple_smart_answer_edition, class_name: "SimpleSmartAnswerEdition" has_many :options, dependent: :destroy, class_name: "SimpleSmartAnswerEdition::Node::Option" accepts_nested_attributes_for :options, allow_destroy: true defau...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/simple_smart_answer_edition/node/option.rb
Ruby
mit
48
main
1,182
require "edition" class SimpleSmartAnswerEdition class Node class Option < ApplicationRecord belongs_to :node, class_name: "SimpleSmartAnswerEdition::Node" default_scope -> { order(order: :asc) } validate :validate_label_is_present validate :validate_node_is_selected validates :sl...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/models/host_content_update_event/action.rb
Ruby
mit
48
main
1,027
class HostContentUpdateEvent class Action CONTENT_BLOCK_UPDATE = "content_block_update".freeze attr_reader :host_content_update_event def initialize(host_content_update_event) @host_content_update_event = host_content_update_event end def request_type CONTENT_BLOCK_UPDATE end ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/services.rb
Ruby
mit
48
main
666
require "gds_api/publishing_api" module Services def self.publishing_api @publishing_api ||= GdsApi::PublishingApi.new( Plek.find("publishing-api"), bearer_token: ENV.fetch("PUBLISHING_API_BEARER_TOKEN", "example"), ) end def self.signon_api @signon_api ||= GdsApi::SignonApi.new( P...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/edition_progressor.rb
Ruby
mit
48
main
2,648
class EditionProgressor EMAIL_REGEX = /\A[\w\d]+[^@]*@[\w\d]+[^@]*\.[\w\d]+[^@]*\z/ attr_accessor :edition, :actor, :activity, :status_message # existing_edition: The existing edition to be duplicated # actor: The WorkflowActor (usually a user) to perform the action def initialize(edition, actor)...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/local_service_cleaner.rb
Ruby
mit
48
main
1,258
class LocalServiceCleaner def initialize(input_data = LocalServiceImporter.fetch_data) @input_data = input_data end def run LocalService.all.find_each do |local_service| Rails.logger.debug "Looking at #{local_service.lgsl_code} -" if in_csv? local_service Rails.logger.debug " in csv" ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/fact_check_config.rb
Ruby
mit
48
main
1,213
class FactCheckConfig attr_reader :subject_prefix, :reply_to_id def initialize(reply_to_address, subject_prefix = "", reply_to_id = nil) if reply_to_address.blank? raise ArgumentError, "Expected reply_to_address not to be nil" end @reply_to_address = reply_to_address @reply_to_id = reply_to_...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/edition_duplicator.rb
Ruby
mit
48
main
1,188
class EditionDuplicator attr_accessor :existing_edition, :actor, :new_edition # existing_edition: The existing edition to be duplicated # actor: The WorkflowActor (usually a user) to perform the action def initialize(existing_edition, actor) self.existing_edition = existing_edition self.acto...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/fact_check_message_processor.rb
Ruby
mit
48
main
1,955
require "govspeak/html_sanitizer" require "html2text" class FactCheckMessageProcessor attr_accessor :message def initialize(message) self.message = message end def body_as_utf8 if message.parts.any? character_set = @message.text_part.content_type_parameters["charset"] messy_notes = @messa...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/state_count_reporter.rb
Ruby
mit
48
main
401
class StateCountReporter def initialize(model_class, states, statsd) @model_class = model_class @states = states @statsd = statsd end def report @statsd.batch do |batch| @states.each do |state| batch.gauge("state.#{state}", state_count(state)) end end nil end priva...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/fact_check_email_handler.rb
Ruby
mit
48
main
3,555
require "fact_check_message_processor" require_relative "fact_check_mail" require "google/apis/gmail_v1" require "googleauth" # A class to pull messages from an email account and send relevant ones # to a processor. # # It presumes that the mail class has already been configured in an # initializer and is typically ca...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/local_service_importer.rb
Ruby
mit
48
main
1,540
require "csv" class LocalServiceImporter def self.run fh = fetch_data begin new(fh).run ensure fh.close end end def self.fetch_data File.open("data/local_services.csv", "r:Windows-1252:UTF-8") end def initialize(filehandle) @filehandle = filehandle end def run C...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/fact_check_mail.rb
Ruby
mit
48
main
1,253
# Hide the implementation detail of usual methods # that could be part of the Message class class FactCheckMail def initialize(message) @message = message end def recipients [@message.to, @message.cc, @message.bcc].compact.flatten end def out_of_office? subject_is_out_of_office? || out_of_office...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/csv_parser.rb
Ruby
mit
48
main
295
require "csv" class CSVParser def initialize(file) @file = file end def parse contents = @file.read if contents.empty? raise "can't parse an empty file" end CSV.new(contents, headers: true).to_a.map do |row| row.to_hash.symbolize_keys end end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/presentation_toggles.rb
Ruby
mit
48
main
2,297
module PresentationToggles extend ActiveSupport::Concern included do validates :promotion_choice_url, presence: { message: "Enter a promotion URL" }, if: :promotes_something? validates :promotion_choice, inclusion: { in: %w[none organ_donor bring_id_to_vote mot_reminder electric_vehicle] } end def pro...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/tagging/link_set.rb
Ruby
mit
48
main
662
module Tagging class LinkSet attr_reader :links, :expanded_links, :version def self.find(content_id, locale) link_set = Services.publishing_api.get_expanded_links( content_id, locale:, generate: true, ) new(link_set.to_h) rescue GdsApi::HTTPNotFound new({})...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/tagging/linkables.rb
Ruby
mit
48
main
2,143
# Linkables # # Note that the functionality to fetch tags from the publishing-api and # transform them into a structure for a dropdown in a form is duplicated # across apps like content-tagger and Whitehall. # Example: https://github.com/alphagov/content-tagger/blob/master/lib/linkables.rb # Once we've migrated all app...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/tagging/legacy_tagging_update_form.rb
Ruby
mit
48
main
2,016
module Tagging class LegacyTaggingUpdateForm include ActiveModel::Model attr_accessor :content_id, :previous_version, :organisations, :mainstream_browse_pages, :ordered_related_items, :parent validate :ordered_related_items_paths_exist def self.build_from_publishing_api(content_id, locale) lin...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/tagging/tagging_update_form.rb
Ruby
mit
48
main
2,964
module Tagging class TaggingUpdateForm include ActiveModel::Model attr_accessor :content_id, :previous_version, :organisations, :mainstream_browse_pages, :ordered_related_items, :parent, :ordered_related_items_destroy validate :ordered_related_items_paths_exist def self.build_from_publishing_api(con...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors.rb
Ruby
mit
48
main
984
Dir[File.join(File.dirname(__FILE__), "action_processors", "*.rb")].sort.each { |f| require f } module GovukContentModels module ActionProcessors REQUEST_TYPE_TO_PROCESSOR = { assign: "AssignProcessor", create: "CreateEditionProcessor", request_review: "RequestReviewProcessor", approve_re...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/resend_fact_check_processor.rb
Ruby
mit
48
main
812
module GovukContentModels module ActionProcessors class ResendFactCheckProcessor < BaseProcessor def process return false unless edition.latest_status_action.is_fact_check_request? if Flipflop.enabled?(:fact_check_manager_api) FactCheckManagerApiService.resend_fact_check_emails(@e...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/request_amendments_processor.rb
Ruby
mit
48
main
253
module GovukContentModels module ActionProcessors class RequestAmendmentsProcessor < BaseProcessor def process? if edition.in_review? requester_different? else true end end end end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/schedule_for_publishing_processor.rb
Ruby
mit
48
main
356
module GovukContentModels module ActionProcessors class ScheduleForPublishingProcessor < BaseProcessor def process publish_at = action_attributes.delete(:publish_at).to_time.utc action_attributes[:request_details] = { scheduled_time: publish_at } edition.schedule_for_publishing(publ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/base_processor.rb
Ruby
mit
48
main
1,560
module GovukContentModels module ActionProcessors class BaseProcessor attr_accessor :actor, :edition, :action_attributes, :event_attributes def initialize(actor, edition, action_attributes = {}, event_attributes = {}) @actor = actor @edition = edition @action_attributes = acti...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/skip_review_processor.rb
Ruby
mit
48
main
331
module GovukContentModels module ActionProcessors class SkipReviewProcessor < BaseProcessor def process? actor.skip_review? and !requester_different? end private def notify_about_event(new_action) super EventNotifierService.skip_review(new_action) end end...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/receive_fact_check_processor.rb
Ruby
mit
48
main
1,042
module GovukContentModels module ActionProcessors class ReceiveFactCheckProcessor < BaseProcessor # Always records the action. def process # Using action_attributes to keep this block limited to API calls as a temporary measure # Safe assumption that the old script-triggered flow is av...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/assign_processor.rb
Ruby
mit
48
main
246
module GovukContentModels module ActionProcessors class AssignProcessor < BaseProcessor def process edition.assign_attributes(assigned_to_id: action_attributes[:recipient_id]) edition.save! end end end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/send_fact_check_processor.rb
Ruby
mit
48
main
831
module GovukContentModels module ActionProcessors class SendFactCheckProcessor < BaseProcessor def process return false if action_attributes[:email_addresses].blank? if Flipflop.enabled?(:fact_check_manager_api) && FactCheckManagerApiService.request_fact_check(@edition, @actor, action_attri...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/create_edition_processor.rb
Ruby
mit
48
main
1,156
module GovukContentModels module ActionProcessors class CreateEditionProcessor < BaseProcessor def action_name Action::CREATE end def process? actor.govuk_editor? end # Return value is used in caller chain to show errors def process editionable_class_a...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/govuk_content_models/action_processors/new_version_processor.rb
Ruby
mit
48
main
578
module GovukContentModels module ActionProcessors class NewVersionProcessor < BaseProcessor def process? edition.published? end def process convert_to = event_attributes[:convert_to] @edition = if !convert_to.nil? edition.build_clone(convert_to.to_s....
github
alphagov/publisher
https://github.com/alphagov/publisher
app/lib/gds_api/fact_check_manager.rb
Ruby
mit
48
main
3,342
require "gds_api/base" class GdsApi::FactCheckManager < GdsApi::Base # Post details to open a new fact check request # # Keyword Arguments: # @param [string] source_app identifier for the application sending the request # @param [uuid] source_id The unique ID for the content # @option [string] source_title...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/schema.rb
Ruby
mit
48
main
13,399
# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # This file is the source Rails uses to define your schema when running `bin/rai...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/seeds.rb
Ruby
mit
48
main
434
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name =>...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/seeds/user.rb
Ruby
mit
48
main
334
if User.where(name: "Test user").blank? gds_organisation_id = "af07d5a5-df63-4ddc-9383-6a666845ebe9" user_id = SecureRandom.uuid User.create!( name: "Test user", email: "test@example.com", uid: user_id, permissions: %w[signin govuk_editor skip_review], organisation_content_id: gds_organisatio...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250711143410_create_campaign_edition.rb
Ruby
mit
48
main
327
class CreateCampaignEdition < ActiveRecord::Migration[7.1] def change create_table :campaign_editions do |t| t.string :body t.string :organisation_formatted_name t.string :organisation_url t.string :organisation_brand_colour t.string :organisation_crest t.timestamps end e...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250310153331_create_variant.rb
Ruby
mit
48
main
341
class CreateVariant < ActiveRecord::Migration[7.1] def change create_table :variants do |t| t.text :mongo_id t.integer :order t.string :title t.string :slug t.string :introduction t.string :link t.string :more_information t.string :alternate_methods t.timestam...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250402100000_create_simple_smart_answer_edition_node.rb
Ruby
mit
48
main
398
class CreateSimpleSmartAnswerEditionNode < ActiveRecord::Migration[7.1] def change create_table :simple_smart_answer_edition_nodes do |t| t.string :slug t.string :title t.text :body t.integer :order t.string :kind t.text :mongo_id t.references :simple_smart_answer_edition...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250827080300_add_new_fields_to_local_transactions.rb
Ruby
mit
48
main
292
class AddNewFieldsToLocalTransactions < ActiveRecord::Migration[7.1] def change add_column :local_transaction_editions, :cta_text, :string add_column :local_transaction_editions, :before_results, :string add_column :local_transaction_editions, :after_results, :string end end
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250227112626_create_edition.rb
Ruby
mit
48
main
1,271
class CreateEdition < ActiveRecord::Migration[7.1] def change enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto') create_table :editions, id: :uuid, default: -> { "gen_random_uuid()" } do |t| t.string :panopticon_id t.integer :version_number, default: 1 t.integer :sibling_in_pr...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250319150752_create_simple_smart_answer_edition.rb
Ruby
mit
48
main
249
class CreateSimpleSmartAnswerEdition < ActiveRecord::Migration[7.1] def change create_table :simple_smart_answer_editions do |t| t.string :body t.string :start_button_text, default: "Start now" t.timestamps end end end
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250308224908_create_link_check_report.rb
Ruby
mit
48
main
317
class CreateLinkCheckReport < ActiveRecord::Migration[7.1] def change create_table :link_check_reports do |t| t.text :mongo_id t.integer :batch_id t.string :status t.datetime :completed_at t.references :edition, foreign_key: true, type: :uuid t.timestamps end end end
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250307142445_create_action.rb
Ruby
mit
48
main
618
class CreateAction < ActiveRecord::Migration[7.1] def change create_table :actions do |t| t.integer :approver_id t.datetime :approved t.string :comment t.boolean :comment_sanitized, default: false t.string :request_type t.jsonb :request_details, default: {} t.string :emai...
github
alphagov/publisher
https://github.com/alphagov/publisher
db/migrate/20250308225023_create_link.rb
Ruby
mit
48
main
452
class CreateLink < ActiveRecord::Migration[7.1] def change create_table :links do |t| t.text :mongo_id t.string :uri t.string :status t.datetime :checked_at t.text :check_warnings, array: true, default: [] t.text :check_errors, array: true, default: [] t.string :problem_s...