diff --git a/docs/usage.md b/docs/usage.md index a2437baf9..fe86cae05 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -15,17 +15,6 @@ This will create and return a client ID and secret that can be used in the app You can then add the ID and secret to the app's `ENV` using your preferred method. -To create a new user, use the following syntax: - -```sh -rake users:create name='First Last' email=user@example.com \ -applications=Comma,Seperated,ListOf,Application,Names* \ -[github=username] [twitter=username] -``` - -\* You can also set the applications in a comma separated list via an -`ENV['applications']` variable if you prefer. - ## Access Tokens You may also need to create an access token, so one application can identify diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index fb7262fd9..c5c120a5d 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -1,19 +1,6 @@ require "date" namespace :users do - desc "Create a new user (specify name and email in environment)" - task create: :environment do - raise "Requires name, email and applications specified in environment" unless ENV["name"] && ENV["email"] && ENV["applications"] - - user_creator = UserCreator.new(ENV["name"], ENV["email"], ENV["applications"]) - user_creator.create_user! - - puts "User created: user.name <#{user_creator.user.name}>" - puts " user.email <#{user_creator.user.email}>" - puts " signin permissions for: '#{user_creator.applications.map(&:name).join("', '")}' " - puts " follow this link to set a password: #{user_creator.invitation_url}" - end - desc "Remind users that their account will get suspended" task send_suspension_reminders: :environment do include VolatileLock::DSL diff --git a/lib/user_creator.rb b/lib/user_creator.rb deleted file mode 100644 index ccd12280a..000000000 --- a/lib/user_creator.rb +++ /dev/null @@ -1,47 +0,0 @@ -require "plek" - -class UserCreator - attr_reader :user - - def initialize(name, email, application_names) - @name = name.dup - @email = email.dup - @application_names = application_names.dup - end - - def applications - @applications ||= extract_applications_from_names - end - - def create_user! - @user = User.invite!(name:, email:) - grant_requested_signin_permissions - grant_default_permissions - end - - def invitation_url - "#{Plek.external_url_for('signon')}/users/invitation/accept?invitation_token=#{user.raw_invitation_token}" - end - -private - - attr_reader :name, :email, :application_names - - def extract_applications_from_names - application_names.split(",").uniq.map do |application_name| - Doorkeeper::Application.find_by!(name: application_name) - end - end - - def grant_requested_signin_permissions - applications.each do |application| - user.grant_application_signin_permission(application) - end - end - - def grant_default_permissions - SupportedPermission.default.each do |default_permission| - user.grant_permission(default_permission) - end - end -end diff --git a/test/lib/user_creator_test.rb b/test/lib/user_creator_test.rb deleted file mode 100644 index f710b41a5..000000000 --- a/test/lib/user_creator_test.rb +++ /dev/null @@ -1,48 +0,0 @@ -require "test_helper" - -class UserCreatorTest < ActiveSupport::TestCase - test "it creates a new user with the supplied name and email" do - FactoryBot.create(:application, name: "app-o-tron", with_supported_permissions: [SupportedPermission::SIGNIN_NAME]) - user_creator = UserCreator.new("Alicia", "alicia@example.com", "app-o-tron") - - user_creator.create_user! - - assert user_creator.user.persisted? - assert_equal "Alicia", user_creator.user.name - assert_equal "alicia@example.com", user_creator.user.email - end - - test "invites the new user, so they must validate their email before they can signin" do - FactoryBot.create(:application, name: "app-o-tron", with_supported_permissions: [SupportedPermission::SIGNIN_NAME]) - user_creator = UserCreator.new("Alicia", "alicia@example.com", "app-o-tron") - - user_creator.create_user! - - assert user_creator.user.invited_but_not_yet_accepted? - end - - test 'it grants "signin" permission to each application supplied' do - app_o_tron = FactoryBot.create(:application, name: "app-o-tron", with_supported_permissions: [SupportedPermission::SIGNIN_NAME]) - app_erator = FactoryBot.create(:application, name: "app-erator", with_supported_permissions: [SupportedPermission::SIGNIN_NAME]) - user_creator = UserCreator.new("Alicia", "alicia@example.com", "app-o-tron,app-erator") - - user_creator.create_user! - - assert user_creator.user.has_access_to? app_o_tron - assert user_creator.user.has_access_to? app_erator - end - - test "it grants all default permissions, even if not signin" do - app_o_tron = FactoryBot.create(:application, name: "app-o-tron", with_supported_permissions: [SupportedPermission::SIGNIN_NAME]) - app_erator = FactoryBot.create(:application, name: "app-erator", with_supported_permissions: [SupportedPermission::SIGNIN_NAME, "fall"]) - create(:supported_permission, application: app_o_tron, name: "bounce", default: true) - app_erator.signin_permission.update!(default: true) - user_creator = UserCreator.new("Alicia", "alicia@example.com", "") - - user_creator.create_user! - - created_user = user_creator.user - assert_equal %w[bounce], created_user.permissions_for(app_o_tron) - assert_equal [SupportedPermission::SIGNIN_NAME], created_user.permissions_for(app_erator) - end -end