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/signon
https://github.com/alphagov/signon
test/lib/tasks/sync_kubernetes_secrets_test.rb
Ruby
mit
97
main
2,816
require "test_helper" class KubernetesTaskTest < ActiveSupport::TestCase setup do Signon::Application.load_tasks if Rake::Task.tasks.empty? @client = mock("kubernetes-client") Kubernetes::Client.stubs(:new).returns(@client) end context "#sync_token_secrets" do should "create all token secrets f...
github
alphagov/signon
https://github.com/alphagov/signon
test/service_consumers/pact_helper.rb
Ruby
mit
97
main
1,989
ENV["RAILS_ENV"] = "test" ENV["PACT_DO_NOT_TRACK"] = "true" require "active_support" require "webmock" require "pact/provider/rspec" require "factory_bot_rails" module CustomGeneratorArgs def self.generate(_opts = {}) "SOME_BEARER_TOKEN" end end WebMock.disable! Pact.configure do |config| config.reports_di...
github
alphagov/signon
https://github.com/alphagov/signon
test/jobs/reauth_enforcer_test.rb
Ruby
mit
97
main
1,320
require "test_helper" class ReauthEnforcerTest < ActiveSupport::TestCase context "perform" do should "request an app for reauthorising a user" do app = create(:application, supports_push_updates: true) uid = "01aac80d-0bbf-4667-9892-3b304654f3de" mock_client = mock("sso_push_client") moc...
github
alphagov/signon
https://github.com/alphagov/signon
test/jobs/permission_updater_test.rb
Ruby
mit
97
main
3,927
require "test_helper" class PermissionUpdaterTest < ActiveSupport::TestCase def users_url(application) url = URI.parse(application.redirect_uri) "https://#{url.host}/auth/gds/api/users/#{CGI.escape(@user.uid)}" end setup do @user = create(:user) @application = create(:application, redirect_uri: ...
github
alphagov/signon
https://github.com/alphagov/signon
test/jobs/push_user_updates_job_test.rb
Ruby
mit
97
main
870
require "test_helper" class PushUserUpdatesJobTest < ActiveSupport::TestCase include ActiveJob::TestHelper class TestJob < PushUserUpdatesJob end context "perform_on" do should "perform_async updates on user's used applications" do user = create(:user) foo_app, _bar_app = *create_list(:applic...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_test.rb
Ruby
mit
97
main
44,873
require "test_helper" require "bcrypt" class UserTest < ActiveSupport::TestCase include ActiveJob::TestHelper def setup GovukEnvironment.stubs(:current).returns("production") @user = create(:user) end context "#authorisations" do should "return access tokens for user" do token = create(:ac...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_update_permission_builder_test.rb
Ruby
mit
97
main
1,893
require "test_helper" class UserUpdatePermissionBuilderTest < ActiveSupport::TestCase def setup application = create(:application) create(:supported_permission, application:, name: "perm-1") @user = create(:user, with_permissions: { application => %w[perm-1] }) @existing_permission_id = @user.support...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/legacy_users_filter_test.rb
Ruby
mit
97
main
2,321
require "test_helper" class LegacyUsersFilterTest < ActiveSupport::TestCase context "#redirect?" do should "return true if there are any legacy filter params" do filter = LegacyUsersFilter.new({ status: User::USER_STATUS_ACTIVE }) assert filter.redirect? end should "return false if there ar...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/noisy_batch_invitation_test.rb
Ruby
mit
97
main
2,327
require "test_helper" class NoisyBatchInvitationTest < ActionMailer::TestCase context "make_noise" do setup do user = create(:user, name: "Bob Loblaw") @batch_invitation = create(:batch_invitation, user:) create(:batch_invitation_user, batch_invitation: @batch_invitation) @email = NoisyBa...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/supported_permission_test.rb
Ruby
mit
97
main
4,359
require "test_helper" class SupportedPermissionTest < ActiveSupport::TestCase test "name of signin permission cannot be changed" do application = create(:application) assert_raises ActiveRecord::RecordInvalid do application.signin_permission.update!(name: "sign-in") end end test "name of perm...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_mailer_test.rb
Ruby
mit
97
main
5,495
require "test_helper" class UserMailerTest < ActionMailer::TestCase def assert_body_includes(search_string, email = @email) assert_includes email.body, search_string end def assert_not_body_includes(search, email = @email) assert_not_includes email.body, search end def assert_support_present_in_tex...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_mailer_content_test.rb
Ruby
mit
97
main
1,488
require "test_helper" class UserMailerContentTest < ActionMailer::TestCase # Use sparingly to apply exemptions to the below due to awkward setups # that work but do not fit the below patterns exemptions = [ "app/views/user_mailer/suspension_reminder.html.erb", "app/views/user_mailer/suspension_notificatio...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_export_presenter_test.rb
Ruby
mit
97
main
2,111
require "test_helper" class UserExportPresenterTest < ActiveSupport::TestCase def setup Timecop.freeze(2015, 1, 15, 9, 0) @apps = 5.times.map { |i| create(:application, name: "App #{i}") } @user = create(:two_step_enabled_user, name: "Test User", email: "test@dept.gov.uk") create(:supported_permissio...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_agent_test.rb
Ruby
mit
97
main
419
require "test_helper" class UserAgentTest < ActiveSupport::TestCase setup do @user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36" end test "can create a valid record" do assert UserAgent.new(user_agent_string: @user_age...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/two_step_verification_exemption_test.rb
Ruby
mit
97
main
4,303
require "test_helper" class TwoStepVerificationExemptionTest < ActiveSupport::TestCase setup do @today = Time.zone.today end context "validation" do should "be valid if a reason and a valid expiry date are provided" do exemption = build(:two_step_verification_exemption) assert exemption.vali...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/api_user_test.rb
Ruby
mit
97
main
653
require "test_helper" class ApiUserTest < ActiveSupport::TestCase should "not be valid if require 2sv is set to true" do user = build(:api_user, require_2sv: true) assert_not user.valid? end should "be valid if require 2sv is set to false" do user = build(:api_user, require_2sv: false) assert use...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_o_auth_presenter_test.rb
Ruby
mit
97
main
1,980
require "test_helper" class UserOAuthPresenterTest < ActiveSupport::TestCase setup do @application = create(:application, with_non_delegated_supported_permissions: %w[managing_editor]) end should "generate JSON" do user = create(:user) justice_league = create(:organisation, slug: "justice-league") ...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/batch_invitation_user_test.rb
Ruby
mit
97
main
8,286
require "test_helper" class BatchInvitationUserTest < ActiveSupport::TestCase context ".create!" do should "strip unwanted whitespace from name before persisting" do user = create(:batch_invitation_user, name: " Ailean Millard ") assert_equal "Ailean Millard", user.name end should "strip u...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/suspension_test.rb
Ruby
mit
97
main
2,588
require "test_helper" class SuspensionTest < ActiveSupport::TestCase setup do EventLog.stubs(:record_event) PermissionUpdater.stubs(:perform_on) ReauthEnforcer.stubs(:perform_on) end should "be valid when a reason is given for a suspension" do suspension = Suspension.new(suspend: true, reason_fo...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/organisation_test.rb
Ruby
mit
97
main
3,480
require "test_helper" class OrganisationTest < ActiveSupport::TestCase should "have ancestry" do assert_nothing_raised do Organisation.new.ancestors end end should "raise an exception when creating a new organisation using an existing slug" do existing_organisation = create(:organisation) ...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/event_log_test.rb
Ruby
mit
97
main
4,846
require "test_helper" require "ipaddr" class EventLogTest < ActiveSupport::TestCase context "#event" do context "when the event has an `event_id`" do should "return the correctly mapped event description" do assert_equal "Account suspended", EventLog.new(event_id: EventLog::ACCOUNT_SUSPENDED.id).ev...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/users_filter_test.rb
Ruby
mit
97
main
15,709
require "test_helper" class UsersFilterTest < ActiveSupport::TestCase setup do @current_user = User.new end should "return all users in alphabetical name order" do create(:user, name: "beta") create(:user, name: "alpha") filter = UsersFilter.new(User.all, @current_user) assert_equal %w[alp...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/user_application_permission_test.rb
Ruby
mit
97
main
925
require "test_helper" class UserApplicationPermissionTest < ActiveSupport::TestCase context "validations" do setup do @user = create(:user) @application = create(:application) @supported_permission = @application.signin_permission end should "be invalid without user_id" do assert...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/batch_invitation_test.rb
Ruby
mit
97
main
5,797
require "test_helper" class BatchInvitationTest < ActiveSupport::TestCase include ActiveJob::TestHelper setup do ActionMailer::Base.deliveries = [] @app = create(:application) @bi = create(:batch_invitation, supported_permissions: [@app.signin_permission]) @user_a = create(:batch_invitation_user...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/doorkeeper/application_test.rb
Ruby
mit
97
main
19,532
require "test_helper" class Doorkeeper::ApplicationTest < ActiveSupport::TestCase should "have a signin supported permission on create" do assert_not_nil create(:application).signin_permission end context "user_update_permission" do should "not be grantable from ui" do user_update_permission = cre...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/doorkeeper/access_grant_test.rb
Ruby
mit
97
main
483
require "test_helper" class Doorkeeper::AccessGrantTest < ActiveSupport::TestCase context ".expired" do should "return grants that have expired" do grant_expiring_1_day_ago = create(:access_grant, expires_in: -1.day) grant_expiring_in_1_day = create(:access_grant, expires_in: 1.day) grants = D...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/doorkeeper/access_token_test.rb
Ruby
mit
97
main
2,695
require "test_helper" class Doorkeeper::AccessTokenTest < ActiveSupport::TestCase context ".not_revoked" do should "return tokens that have not been revoked" do revoked_token = create(:access_token, revoked_at: Time.current) non_revoked_token = create(:access_token, revoked_at: nil) tokens = D...
github
alphagov/signon
https://github.com/alphagov/signon
test/models/doorkeeper/after_successful_authorization_processor_test.rb
Ruby
mit
97
main
1,878
require "test_helper" class Doorkeeper::AfterSuccessfulAuthorizationProcessorTest < ActiveSupport::TestCase context "#process" do setup do @controller = Doorkeeper::TokensController.new @user = create(:user) @application = create(:application) token = create(:access_token, application: @a...
github
alphagov/signon
https://github.com/alphagov/signon
test/services/user_update_test.rb
Ruby
mit
97
main
7,566
require "test_helper" require "ipaddr" class UserUpdateTest < ActionView::TestCase attr_reader :current_user, :affected_user, :ip_address setup do @current_user = create(:superadmin_user) @affected_user = create(:user) @ip_address = "1.2.3.4" end should "record an event" do UserUpdate.new(aff...
github
alphagov/signon
https://github.com/alphagov/signon
config/routes.rb
Ruby
mit
97
main
4,843
Rails.application.routes.draw do get "/healthcheck/live", to: proc { [200, {}, %w[OK]] } get "/healthcheck/ready", to: GovukHealthcheck.rack_response( GovukHealthcheck::ActiveRecord, GovukHealthcheck::SidekiqRedis, ) use_doorkeeper do controllers authorizations: "signin_required_authorizations" ...
github
alphagov/signon
https://github.com/alphagov/signon
config/application.rb
Ruby
mit
97
main
3,702
require_relative "boot" require "rails" # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" # require "active_storage/engine" require "action_controller/railtie" require "action_mailer/railtie" # require "action_mailbox/engine" # require "action_t...
github
alphagov/signon
https://github.com/alphagov/signon
config/environments/production.rb
Ruby
mit
97
main
4,228
require "active_support/core_ext/integer/time" 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 for better performance and memory savings (ignor...
github
alphagov/signon
https://github.com/alphagov/signon
config/environments/development.rb
Ruby
mit
97
main
3,100
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
alphagov/signon
https://github.com/alphagov/signon
config/environments/test.rb
Ruby
mit
97
main
2,625
# 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 there! Rails.application.configure do # Settings...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/doorkeeper_scopes.rb
Ruby
mit
97
main
327
Doorkeeper::OAuth::PreAuthorization.class_eval do alias_method :old_validate_scopes, :validate_scopes def scope @scope.presence || build_scopes end def validate_scopes return true if scope.blank? old_validate_scopes end def validate_params response_type.blank? ? :response_type : true e...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/rack_attack.rb
Ruby
mit
97
main
355
Rack::Attack.throttle("limit 'POST /users/password' attempts per IP", limit: 20, period: 1.hour) do |request| if request.path == "/users/password" && request.post? request.env["action_dispatch.remote_ip"].to_s end end Rack::Attack.throttled_responder = lambda do |_request| [429, { "Content-Type" => "text/pla...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/session_store.rb
Ruby
mit
97
main
316
# Be sure to restart your server when you modify this file. Signon::Application.config.session_store :cookie_store, key: "_signonotron2_session", secure: Rails.env.production?, httponly: true
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/content_security_policy.rb
Ruby
mit
97
main
622
GovukContentSecurityPolicy.configure do |policy| # Ensures the ability to use inline JavaScript without protections. This is # required for compatibility with govuk_admin_template which both uses script # tags without nonces and uses jQuery 1.x which requires unsafe-inline in # some browsers (Firefox is one) ...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/inflections.rb
Ruby
mit
97
main
572
# 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
alphagov/signon
https://github.com/alphagov/signon
config/initializers/load_model_enhancements.rb
Ruby
mit
97
main
688
# We conditionally apply the model enhancements (at the time of writing, only one exists) since the model change # was breaking a migration when spinning up a clean install. # # == SwapMagicEverythingPermissionsForRealOnes: migrating ====================== # rake aborted! # An error has occurred, all later migrations ...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/doorkeeper.rb
Ruby
mit
97
main
17,601
# frozen_string_literal: true Rails.configuration.oauth_apps_uri_sub_pattern = ENV["SIGNON_APPS_URI_SUB_PATTERN"] Rails.configuration.oauth_apps_uri_sub_replacement = ENV["SIGNON_APPS_URI_SUB_REPLACEMENT"] Doorkeeper.configure do # Change the ORM that doorkeeper will use (requires ORM extensions installed). # Che...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/date_formats.rb
Ruby
mit
97
main
358
Date::DATE_FORMATS[:short_ordinal] = "%d %B %Y" Date::DATE_FORMATS[:govuk_date] = "%-e %B %Y" Date::DATE_FORMATS[:govuk_date_short] = "%-e %b %Y" Time::DATE_FORMATS[:short_ordinal] = "%d %B %Y" Time::DATE_FORMATS[:govuk_date] = "%-I:%M%P, %-e %B %Y" Time::DATE_FORMATS[:govuk_date_short] = "%-I:%M%P, %-e %b %Y" Time::D...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/filter_parameter_logging.rb
Ruby
mit
97
main
441
# Be sure to restart your server when you modify this file. # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behavio...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/devise.rb
Ruby
mit
97
main
13,746
require "govuk_app_config" devise_config = Rails.application.config_for(:devise).symbolize_keys if devise_config[:secret_key].blank? || devise_config[:pepper].blank? raise "Required Devise secrets are unset" end # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration op...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/i18n.rb
Ruby
mit
97
main
450
# this is required to catch errors thrown from calls to I18n directly - primarily mailers if Rails.env.test? module I18n class AlwaysRaiseExceptionHandler < ExceptionHandler def call(exception, locale, key, options) if exception.is_a?(MissingTranslation) raise exception.to_exception ...
github
alphagov/signon
https://github.com/alphagov/signon
config/initializers/assets.rb
Ruby
mit
97
main
576
# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = "1.0" # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path # Precompile additional...
github
alphagov/signon
https://github.com/alphagov/signon
app/presenters/user_export_presenter.rb
Ruby
mit
97
main
1,473
class UserExportPresenter include UsersHelper attr_reader :applications, :app_permissions def initialize(applications) @applications = applications permission_names = Hash[SupportedPermission.pluck(:id, :name)] @app_permissions = {} UserApplicationPermission.find_each do |permission| @ap...
github
alphagov/signon
https://github.com/alphagov/signon
app/presenters/user_o_auth_presenter.rb
Ruby
mit
97
main
810
# Generates a hash suitable for exposing to an application integrating with # signon for SSO over OAuth. Also used when pushing user updates, which isn't # part of OAuth. UserOAuthPresenter = Struct.new(:user, :application) do def as_hash { user: { uid: user.uid, name: user.name, ema...
github
alphagov/signon
https://github.com/alphagov/signon
app/presenters/api/user_presenter.rb
Ruby
mit
97
main
644
module Api class UserPresenter def self.present_many(users) users.map { |user| present(user) } end def self.present(user) new(user).present end def present { uid: @user.uid, name: @user.name, email: @user.email, organisation: organisation, ...
github
alphagov/signon
https://github.com/alphagov/signon
app/jobs/reauth_enforcer.rb
Ruby
mit
97
main
432
require "sso_push_client" class ReauthEnforcer < PushUserUpdatesJob def perform(uid, application_id) application = Doorkeeper::Application.find_by(id: application_id) # It's possible the application has been deleted between when the job was scheduled and run. return if application.nil? return unless ...
github
alphagov/signon
https://github.com/alphagov/signon
app/jobs/permission_updater.rb
Ruby
mit
97
main
744
require "sso_push_client" class PermissionUpdater < PushUserUpdatesJob def perform(uid, application_id) user = User.find_by(uid:) application = Doorkeeper::Application.find_by(id: application_id) # It's possible they've been deleted between when the job was scheduled and run. return if user.nil? || a...
github
alphagov/signon
https://github.com/alphagov/signon
app/jobs/push_user_updates_job.rb
Ruby
mit
97
main
374
class PushUserUpdatesJob < ApplicationJob include ActiveJob::Retry.new(strategy: :exponential, limit: 6) def perform(*_args) raise NotImplementedError, "PushUserUpdatesJob must be subclassed" end class << self def perform_on(user) user.authorised_applications .each { |application| perfor...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/organisation_policy.rb
Ruby
mit
97
main
380
class OrganisationPolicy < BasePolicy def index? current_user.govuk_admin? end def can_assign? return true if current_user.govuk_admin? false end def edit? current_user.superadmin? end class Scope < ::BasePolicy::Scope def resolve if current_user.govuk_admin? scope.al...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/application_policy.rb
Ruby
mit
97
main
337
class ApplicationPolicy < BasePolicy def index? current_user.superadmin? end alias_method :edit?, :index? alias_method :update?, :index? alias_method :manage_supported_permissions?, :index? alias_method :users_with_access?, :index? alias_method :access_logs?, :index? alias_method :monthly_access_sta...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/api_user_policy.rb
Ruby
mit
97
main
379
class ApiUserPolicy < BasePolicy def new? current_user.superadmin? end alias_method :create?, :new? alias_method :index?, :new? alias_method :edit?, :new? alias_method :update?, :new? alias_method :revoke?, :new? alias_method :manage_tokens?, :new? alias_method :suspension?, :new? def resend_em...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/base_policy.rb
Ruby
mit
97
main
678
class BasePolicy attr_reader :current_user, :record def initialize(current_user, record) @current_user = current_user @record = record end def scope Pundit.policy_scope!(current_user, record.class) end protected def record_in_own_organisation? record.organisation && (record.organisation_...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/supported_permission_policy.rb
Ruby
mit
97
main
633
class SupportedPermissionPolicy < BasePolicy class Scope < ::BasePolicy::Scope def resolve if current_user.govuk_admin? scope.all elsif current_user.publishing_manager? scope .delegated .joins(:application) .where(oauth_applications: { id: publishing_manag...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/batch_invitation_policy.rb
Ruby
mit
97
main
221
class BatchInvitationPolicy < BasePolicy def new? return true if current_user.govuk_admin? false end alias_method :create?, :new? alias_method :show?, :new? alias_method :manage_permissions?, :new? end
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/user_policy.rb
Ruby
mit
97
main
2,107
class UserPolicy < BasePolicy def index? current_user.govuk_admin? || current_user.publishing_manager? end # invitations#new def new? current_user.govuk_admin? end alias_method :assign_organisation?, :new? # invitations#create alias_method :create?, :new? def edit? case current_user.rol...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/users/application_policy.rb
Ruby
mit
97
main
907
class Users::ApplicationPolicy < BasePolicy attr_reader :user, :application def initialize(current_user, record) super @user = record[:user] @application = record[:application] end def show? Pundit.policy(current_user, user).edit? end alias_method :index?, :show? alias_method :view_per...
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/account/emails_policy.rb
Ruby
mit
97
main
211
class Account::EmailsPolicy < BasePolicy def edit? current_user.present? end alias_method :update?, :edit? alias_method :resend_email_change?, :edit? alias_method :cancel_email_change?, :edit? end
github
alphagov/signon
https://github.com/alphagov/signon
app/policies/account/application_policy.rb
Ruby
mit
97
main
630
class Account::ApplicationPolicy < BasePolicy def show? current_user.govuk_admin? || current_user.publishing_manager? end alias_method :index?, :show? alias_method :view_permissions?, :index? def grant_signin_permission? current_user.govuk_admin? end def remove_signin_permission? current_us...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/application_table_helper.rb
Ruby
mit
97
main
4,274
module ApplicationTableHelper include Pundit::Authorization def account_applications_grant_access_link(application) if policy([:account, Doorkeeper::Application]).grant_signin_permission? grant_access_link(application) else "" end end def users_applications_grant_access_link(applicatio...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/api_users_helper.rb
Ruby
mit
97
main
515
module ApiUsersHelper def truncate_access_token(token) raw "#{token[0..7]}#{'&bull;' * 24}#{token[-8..]}" end def api_user_name(user) link_to(user.name, edit_api_user_path(user), class: "govuk-link") end def application_list(user) content_tag(:ul, class: "govuk-list") do safe_join( ...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/application_access_helper.rb
Ruby
mit
97
main
716
module ApplicationAccessHelper def access_granted_description(application_id, user = current_user) application = Doorkeeper::Application.find_by(id: application_id) return nil unless application return "You have been granted access to #{application.name}." if user == current_user "#{user.name} has b...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/organisation_helper.rb
Ruby
mit
97
main
377
module OrganisationHelper def options_for_organisation_select(selected_id: nil) [{ text: Organisation::NONE, value: nil }] + policy_scope(Organisation).not_closed.map do |organisation| { text: organisation.name_with_abbreviation, value: organisation.id }.tap do |option| option[:selected] = true if o...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/application_permissions_helper.rb
Ruby
mit
97
main
2,008
module ApplicationPermissionsHelper include ActionView::Helpers::TagHelper def permissions_updated_description(application_id, user = current_user) application = Doorkeeper::Application.find_by(id: application_id) return nil unless application additional_permissions = user.permissions_for(application)...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/account_helper.rb
Ruby
mit
97
main
618
module AccountHelper def two_step_verification_page_title if current_user.has_2sv? "Change your 2-step verification phone" else "Set up 2-step verification" end end def role_page_title if policy(%i[account roles]).update? "Change your role" else "View your role" en...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/navigation_items_helper.rb
Ruby
mit
97
main
1,178
module NavigationItemsHelper def navigation_items return [] unless current_user items = [] unless content_for(:suppress_navbar_items) items << { text: "Dashboard", href: root_path, active: is_current?(root_path) } if policy(User).index? items << { text: "Users", href: users_path, ac...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/batch_invitations_helper.rb
Ruby
mit
97
main
966
module BatchInvitationsHelper def batch_invite_status_message(batch_invitation) if batch_invitation.in_progress? "In progress. " \ "#{batch_invitation.batch_invitation_users.processed.count} of " \ "#{batch_invitation.batch_invitation_users.count} " \ "users processed." elsif bat...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/event_log_helper.rb
Ruby
mit
97
main
1,103
module EventLogHelper def formatted_date(log) log.created_at.to_fs(:govuk_date_short) end def formatted_message(log) [ formatted_event(log), formatted_application(log), formatted_initiator(log), formatted_trailing_message(log), formatted_ip_address(log), formatted_user...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/application_helper.rb
Ruby
mit
97
main
1,097
require "addressable/uri" module ApplicationHelper def nav_link(text, link) recognized = Rails.application.routes.recognize_path(link) if recognized[:controller] == params[:controller] && recognized[:action] == params[:action] tag.li(class: "active") do link_to(text, link) end ...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/two_step_verification_helper.rb
Ruby
mit
97
main
1,871
module TwoStepVerificationHelper private def handle_two_step_verification # TODO: Should raise error if this helper is reached and not already signed in. return unless signed_in?(:user) if warden.session(:user)["need_two_step_verification"] handle_failed_second_step elsif current_user.prompt_f...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/users_helper.rb
Ruby
mit
97
main
5,701
module UsersHelper include Pundit::Authorization def status(user) user.status.humanize end def status_with_tag(user) css_classes = if user.status == User::USER_STATUS_ACTIVE "govuk-tag--green" else "govuk-tag--grey" end g...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/root_helper.rb
Ruby
mit
97
main
439
module RootHelper def gds_only_application_and_non_gds_user?(application) application.present? && application.gds_only? && !current_user.belongs_to_gds? end def signin_required_title(application) if application.blank? || gds_only_application_and_non_gds_user?(application) "You don’t have permission...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/users_with_access_helper.rb
Ruby
mit
97
main
691
module UsersWithAccessHelper def formatted_user_name(user) status = if user.invited_but_not_yet_accepted? "(invited)" elsif user.suspended? "(suspended)" elsif user.access_locked? "(access locked)" end link = link_to(user.nam...
github
alphagov/signon
https://github.com/alphagov/signon
app/helpers/components/table_helper.rb
Ruby
mit
97
main
2,310
module Components module TableHelper def self.helper(context, caption = nil, opt = {}) builder = TableBuilder.new(context.tag) classes = %w[app-c-table govuk-table] classes << "govuk-table--sortable" if opt[:sortable] classes << opt[:classes] if opt[:classes] caption_classes = %w[g...
github
alphagov/signon
https://github.com/alphagov/signon
app/services/user_update.rb
Ruby
mit
97
main
4,217
class UserUpdate attr_reader :user, :user_params, :current_user, :user_ip def initialize(user, user_params, current_user, user_ip) @user = user @user_params = user_params @current_user = current_user @user_ip = user_ip end def call user.skip_reconfirmation! old_permissions = fetch_user...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/doorkeeper_applications_controller.rb
Ruby
mit
97
main
2,574
class DoorkeeperApplicationsController < ApplicationController before_action :authenticate_user! before_action :load_and_authorize_application, except: :index respond_to :html def index authorize Doorkeeper::Application @applications = Doorkeeper::Application.all end def edit; end def update ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/confirmations_controller.rb
Ruby
mit
97
main
2,547
# Copied from # https://github.com/plataformatec/devise/blob/v2.1.2/app/controllers/devise/confirmations_controller.rb#L19 class ConfirmationsController < Devise::ConfirmationsController def new handle_new_token_needed end def create handle_new_token_needed end # GET /users/confirmation?confirmation...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/signin_required_authorizations_controller.rb
Ruby
mit
97
main
1,519
class SigninRequiredAuthorizationsController < Doorkeeper::AuthorizationsController include Pundit::Authorization # This controller was based on (and inherits from) # https://github.com/doorkeeper-gem/doorkeeper/blob/main/app/controllers/doorkeeper/authorizations_controller.rb # # Future doorkeeper changes ma...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/supported_permissions_controller.rb
Ruby
mit
97
main
1,899
class SupportedPermissionsController < ApplicationController before_action :authenticate_user! before_action :load_and_authorize_application respond_to :html def index @supported_permissions = @application.sorted_supported_permissions_grantable_from_ui end def new @supported_permission = @applicat...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/root_controller.rb
Ruby
mit
97
main
796
class RootController < ApplicationController before_action :authenticate_user!, except: %i[privacy_notice accessibility_statement] skip_after_action :verify_authorized def index @applications = Doorkeeper::Application.not_api_only.with_home_uri.can_signin(current_user) end def signin_required @appli...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/invitations_controller.rb
Ruby
mit
97
main
2,081
# https://raw.github.com/scambra/devise_invitable/master/app/controllers/devise/invitations_controller.rb class InvitationsController < Devise::InvitationsController before_action :authenticate_inviter!, only: %i[new create] after_action :verify_authorized, only: %i[new create] before_action :redirect_if_invitee...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/authorisations_controller.rb
Ruby
mit
97
main
1,854
class AuthorisationsController < ApplicationController before_action :authenticate_user! before_action :load_api_user before_action :build_authorisation, only: %i[new create] before_action :load_authorisation, only: %i[edit revoke] before_action :authorize_authorisation respond_to :html def new; end ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/oauth_users_controller.rb
Ruby
mit
97
main
812
class OauthUsersController < ApplicationController before_action :doorkeeper_authorize! before_action :validate_token_matches_client_id skip_after_action :verify_authorized def show current_resource_owner.permissions_synced!(application_making_request) respond_to do |format| format.json do ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/passwords_controller.rb
Ruby
mit
97
main
1,808
class PasswordsController < Devise::PasswordsController before_action :record_password_reset_request, only: :create # rubocop:disable Rails/LexicallyScopedActionFilter before_action :record_reset_page_loaded, only: :edit def edit super user = user_from_params unless user && user.reset_password_perio...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/organisations_controller.rb
Ruby
mit
97
main
649
class OrganisationsController < ApplicationController before_action :authenticate_user! respond_to :html def index authorize Organisation @organisations = policy_scope(Organisation) end def update authorize Organisation, :edit? @organisation = Organisation.find(params[:id]) if params[:o...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/api_users_controller.rb
Ruby
mit
97
main
1,377
class ApiUsersController < ApplicationController before_action :authenticate_user! before_action :load_and_authorize_api_user, only: %i[edit manage_tokens] helper_method :visible_applications respond_to :html def index authorize ApiUser @api_users = ApiUser.includes(application_permissions: :applica...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/application_controller.rb
Ruby
mit
97
main
2,161
require "devise/hooks/two_step_verification" class ApplicationController < ActionController::Base include Pundit::Authorization protect_from_forgery with: :exception include TwoStepVerificationHelper before_action :handle_two_step_verification after_action :verify_authorized, unless: :devise_controller? ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/sessions_controller.rb
Ruby
mit
97
main
1,357
class SessionsController < Devise::SessionsController skip_before_action :handle_two_step_verification def destroy ReauthEnforcer.perform_on(current_user) if current_user super end def create log_event store_location_for("2sv", session[stored_location_key_for(:user)]) super end private ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/batch_invitation_permissions_controller.rb
Ruby
mit
97
main
1,046
class BatchInvitationPermissionsController < ApplicationController before_action :authenticate_user! before_action :load_batch_invitation before_action :authorise_to_manage_permissions before_action :prevent_updating def new; end def create @batch_invitation.supported_permission_ids = params[:user][:s...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/two_step_verification_exemptions_controller.rb
Ruby
mit
97
main
812
class TwoStepVerificationExemptionsController < ApplicationController before_action :authenticate_user!, :load_and_authorize_user def edit @exemption = TwoStepVerificationExemption.from_user(@user) end def update @exemption = TwoStepVerificationExemption.from_params(exemption_params) if @exemption...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users_controller.rb
Ruby
mit
97
main
2,296
require "csv" class UsersController < ApplicationController before_action :authenticate_user! before_action :load_user, except: %i[index] before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit] before_action :authorize_user, except: %i[index] before_action :redirect_legacy_filters, only...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/batch_invitations_controller.rb
Ruby
mit
97
main
2,285
require "csv" class BatchInvitationsController < ApplicationController before_action :authenticate_user! def new @batch_invitation = BatchInvitation.new(organisation_id: current_user.organisation_id) authorize @batch_invitation end def create @batch_invitation = BatchInvitation.new(user: current_...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/suspensions_controller.rb
Ruby
mit
97
main
1,112
class SuspensionsController < ApplicationController before_action :authenticate_user!, :load_and_authorize_user respond_to :html def edit @suspension = Suspension.new(suspend: @user.suspended?, reason_for_suspension: @user.reason_for_suspension) end def update @suspe...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/user_research_recruitment_controller.rb
Ruby
mit
97
main
623
class UserResearchRecruitmentController < ApplicationController USER_RESEARCH_RECRUITMENT_FORM_URL = "https://docs.google.com/forms/d/1Bdu_GqOrSR4j6mbuzXkFTQg6FRktRMQc8Y-q879Mny8/viewform".freeze before_action :authenticate_user! skip_after_action :verify_authorized def update case params[:choice] whe...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/devise/two_step_verification_session_controller.rb
Ruby
mit
97
main
1,338
class Devise::TwoStepVerificationSessionController < DeviseController before_action { |c| c.authenticate_user! force: true } before_action :ensure_user_has_2sv_setup skip_before_action :handle_two_step_verification def new; end def create render(:show) && return if params[:code].nil? if current_us...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/devise/two_step_verification_controller.rb
Ruby
mit
97
main
2,025
class Devise::TwoStepVerificationController < DeviseController before_action -> { authenticate_user!(force: true) }, only: :prompt before_action :prepare_and_validate, except: :prompt attr_reader :otp_secret_key def prompt; end def show generate_secret end def update mode = current_user.has_2s...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/api/users_controller.rb
Ruby
mit
97
main
494
class Api::UsersController < ApplicationController before_action :authorize_api_access, unless: -> { Rails.env.development? } skip_after_action :verify_authorized def index users = User.where(uid: params[:uuids]) render json: Api::UserPresenter.present_many(users) end private def authorize_api_acce...