[issue #174] A half of work to create invitations system
This commit is contained in:
parent
e9f3b79bd2
commit
ce39cdd04f
|
@ -0,0 +1,32 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class RegisterRequestsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@register_requests = @register_requests.unprocessed.paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
render :layout => 'sessions'
|
||||
end
|
||||
|
||||
def show_message
|
||||
end
|
||||
|
||||
def create
|
||||
if @register_request = RegisterRequest.create(params[:register_request])
|
||||
redirect_to show_message_register_requests_path
|
||||
else
|
||||
redirect_to :action => :new
|
||||
end
|
||||
end
|
||||
|
||||
def approve
|
||||
@register_request.update_attributes(:approved => true, :rejected => false)
|
||||
end
|
||||
|
||||
def reject
|
||||
@register_request.update_attributes(:approved => false, :rejected => true)
|
||||
end
|
||||
end
|
||||
|
|
@ -16,6 +16,7 @@ class Ability
|
|||
can :manage, :all
|
||||
cannot :destroy, Subscribe
|
||||
cannot :create, Subscribe
|
||||
cannot :create, RegisterRequest
|
||||
else
|
||||
# Shared rights between guests and registered users
|
||||
can :forbidden, Platform
|
||||
|
@ -26,6 +27,7 @@ class Ability
|
|||
|
||||
if user.guest? # Guest rights
|
||||
can :create, User
|
||||
can :create, RegisterRequest
|
||||
else # Registered user rights
|
||||
can [:show, :autocomplete_user_uname], User
|
||||
|
||||
|
@ -97,6 +99,7 @@ class Ability
|
|||
can(:update, Comment) {|comment| comment.user_id == user.id or local_admin?(comment.project || comment.commentable.project)}
|
||||
#cannot :manage, Comment, :commentable => {:project => {:has_issues => false}} # switch off issues
|
||||
cannot(:manage, Comment) {|comment| comment.commentable_type == 'Issue' && !comment.commentable.project.has_issues} # switch off issues
|
||||
cannot :manage, RegisterRequest
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
class RegisterRequest < ActiveRecord::Base
|
||||
default_scope order('created_at ASC')
|
||||
|
||||
scope :rejected, where(:rejected => true)
|
||||
scope :approved, where(:approved => true)
|
||||
scope :unprocessed, where(:approved => false, :rejected => false)
|
||||
|
||||
before_create :generate_token
|
||||
|
||||
validate :name, :presence => true
|
||||
validate :email, :presence => true, :uniqueness => {:case_sensitive => false}
|
||||
|
||||
protected
|
||||
|
||||
def generate_token
|
||||
token = Digest::SHA1.hexdigest(name + email + Time.now.to_s + rand.to_s)
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ class User < ActiveRecord::Base
|
|||
LANGUAGES_FOR_SELECT = [['Russian', 'ru'], ['English', 'en']]
|
||||
LANGUAGES = LANGUAGES_FOR_SELECT.map(&:last)
|
||||
|
||||
devise :database_authenticatable, :registerable, :omniauthable, # :token_authenticatable, :encryptable, :timeoutable
|
||||
devise :database_authenticatable, :registerable, #:omniauthable, # :token_authenticatable, :encryptable, :timeoutable
|
||||
:recoverable, :rememberable, :validatable #, :trackable, :confirmable, :lockable
|
||||
|
||||
has_one :notifier, :class_name => 'Settings::Notifier' #:notifier
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
.right
|
||||
= f.text_field :name, :class => "text_field"
|
||||
|
||||
.group.wat-cf
|
||||
.left
|
||||
= f.label 'Token', :class => "label"
|
||||
.right
|
||||
= text_field_tag :token, '', :class => "text_field", :style => 'width: 70%'
|
||||
= link_to t('get_token'), new_register_request_path, :style => 'display: inline-block; float: right'
|
||||
|
||||
- if resource.authentications.blank?
|
||||
.group.wat-cf
|
||||
.left
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
- if controller_name != 'sessions'
|
||||
= link_to t("layout.devise.shared_links.sign_in"), new_session_path(resource_name), :class => "text_button_padding link_button"
|
||||
- if devise_mapping.registerable? && controller_name != 'registrations'
|
||||
= link_to t("layout.devise.shared_links.sign_up"), new_registration_path(resource_name), :class => "text_button_padding link_button"
|
||||
=# link_to t("layout.devise.shared_links.sign_up"), new_registration_path(resource_name), :class => "text_button_padding link_button"
|
||||
= link_to t("layout.devise.shared_links.sign_up"), new_register_request_path, :class => "text_button_padding link_button" # to prereg form
|
||||
- if devise_mapping.recoverable? && controller_name != 'passwords'
|
||||
= link_to t("layout.devise.shared_links.forgot_password"), new_password_path(resource_name), :class => "text_button_padding link_button"
|
||||
- if devise_mapping.confirmable? && controller_name != 'confirmations'
|
||||
= link_to t("layout.devise.shared_links.confirm_again"), new_confirmation_path(resource_name), :class => "text_button_padding link_button"
|
||||
- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
|
||||
= link_to t("layout.devise.shared_links.unlock"), new_unlock_path(resource_name), :class => "text_button_padding link_button"
|
||||
- if devise_mapping.omniauthable?
|
||||
-# if devise_mapping.omniauthable?
|
||||
- resource_class.omniauth_providers.each do |provider|
|
||||
= link_to t("layout.devise.shared_links.sign_in_through", :provider => provider.to_s.classify), omniauth_authorize_path(resource_name, provider), :class => "text_button_padding link_button"
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
.block
|
||||
.secondary-navigation
|
||||
%ul.wat-cf
|
||||
%li.first= link_to t("layout.users.list"), users_path
|
||||
%li= link_to t("layout.users.new"), new_user_path
|
||||
%li.active= link_to t("layout.users.register_requests"), register_requests_path
|
||||
.content
|
||||
%h2.title
|
||||
= t("layout.register_request.list_header")
|
||||
.inner
|
||||
%table.table
|
||||
%tr
|
||||
%th= t("activerecord.attributes.register_request.name")
|
||||
%th= t("activerecord.attributes.register_request.email")
|
||||
%th= t("activerecord.attributes.register_request.created_at")
|
||||
%th.last
|
||||
- @register_requests.each do |request|
|
||||
%tr{:class => cycle("odd", "even")}
|
||||
%td= request.name
|
||||
%td= request.email
|
||||
%td
|
||||
= link_to t("layout.approve"), register_request_approve_path(request) if can? :approve, request
|
||||
|
|
||||
= link_to t("layout.reject"), register_request_reject_path(request) if can? :reject, request
|
||||
.actions-bar.wat-cf
|
||||
.actions
|
||||
= will_paginate @register_requests
|
|
@ -0,0 +1,24 @@
|
|||
#block-login.block
|
||||
%h2= title t("layout.register_request.get_token_header")
|
||||
.content.login
|
||||
- if flash.present?
|
||||
.flash
|
||||
- flash.each do |key, value|
|
||||
.message{ :title => key.to_s.humanize, :class => (key == :alert ? "error" : key) }
|
||||
%p= value
|
||||
- form_for(@register_request, :html => { :class => "form login" }) do |f|
|
||||
.group.wat-cf
|
||||
.left
|
||||
= f.label :name, :class => "label right"
|
||||
.right
|
||||
= f.text_field :name, :class => "text_field"
|
||||
.group.wat-cf
|
||||
.left
|
||||
= f.label :email, :class => "label right"
|
||||
.right
|
||||
= f.text_field :email, :class => "text_field"
|
||||
.group.navform.wat-cf
|
||||
.right
|
||||
%button.button{ :type => "submit" }
|
||||
= t("layout.register_request.get_token_button")
|
||||
%span.text_button_padding
|
|
@ -3,6 +3,7 @@
|
|||
%ul.wat-cf
|
||||
%li.first.active= link_to t("layout.users.list"), users_path
|
||||
%li= link_to t("layout.users.new"), new_user_path
|
||||
%li= link_to t("layout.users.register_requests"), register_requests_path if can? :read, RegisterRequest
|
||||
.content
|
||||
%h2.title
|
||||
= t("layout.users.list_header")
|
||||
|
|
|
@ -9,7 +9,15 @@ Rosa::Application.routes.draw do
|
|||
|
||||
resources :users do
|
||||
resources :groups, :only => [:new, :create, :index]
|
||||
get :autocomplete_user_uname, :on => :collection
|
||||
collection do
|
||||
resources :register_requests, :only => [:index, :new, :create, :show_message, :approve, :reject] do
|
||||
get :show_message, :on => :collection
|
||||
get :approve
|
||||
get :reject
|
||||
end
|
||||
get :autocomplete_user_uname
|
||||
end
|
||||
|
||||
namespace :settings do
|
||||
resource :notifier, :only => [:show, :update]
|
||||
end
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
class CreateRegisterRequests < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :register_requests do |t|
|
||||
t.string :name
|
||||
t.string :email
|
||||
t.string :token
|
||||
t.boolean :approved, :default => false
|
||||
t.boolean :rejected, :default => false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :register_requests, [:email], :unique => true, :case_sensitive => false
|
||||
add_index :register_requests, [:token], :unique => true, :case_sensitive => false
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_index :register_requests, [:email]
|
||||
remove_index :register_requests, [:token]
|
||||
drop_table :register_requests
|
||||
end
|
||||
end
|
29
db/schema.rb
29
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120131124517) do
|
||||
ActiveRecord::Schema.define(:version => 20120209135822) do
|
||||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
|
@ -253,15 +253,27 @@ ActiveRecord::Schema.define(:version => 20120131124517) do
|
|||
t.text "description"
|
||||
t.string "ancestry"
|
||||
t.boolean "has_issues", :default => true
|
||||
t.boolean "has_wiki", :default => false
|
||||
t.string "srpm_file_name"
|
||||
t.string "srpm_content_type"
|
||||
t.integer "srpm_file_size"
|
||||
t.datetime "srpm_updated_at"
|
||||
t.boolean "has_wiki", :default => false
|
||||
end
|
||||
|
||||
add_index "projects", ["category_id"], :name => "index_projects_on_category_id"
|
||||
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
|
||||
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true
|
||||
|
||||
create_table "register_requests", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
t.string "token"
|
||||
t.boolean "approved", :default => false
|
||||
t.boolean "rejected", :default => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "register_requests", ["email"], :name => "index_register_requests_on_email", :unique => true, :case_sensitive => false
|
||||
|
||||
create_table "relations", :force => true do |t|
|
||||
t.integer "object_id"
|
||||
|
@ -320,19 +332,18 @@ ActiveRecord::Schema.define(:version => 20120131124517) do
|
|||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.string "remember_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.string "role"
|
||||
t.string "language", :default => "en"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.string "language", :default => "en"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# Read about factories at http://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :register_request do
|
||||
name "MyString"
|
||||
email "MyString"
|
||||
token "MyString"
|
||||
approved false
|
||||
end
|
||||
end
|
|
@ -22,6 +22,7 @@ describe CanCan do
|
|||
let(:personal_repository) { Factory(:personal_repository) }
|
||||
let(:open_platform) { Factory(:platform, :visibility => 'open') }
|
||||
let(:hidden_platform) { Factory(:platform, :visibility => 'hidden') }
|
||||
let(:register_request) { Factory(:register_request) }
|
||||
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
@ -44,6 +45,10 @@ describe CanCan do
|
|||
it 'should not be able to destroy personal repositories' do
|
||||
@ability.should_not be_able_to(:destroy, personal_repository)
|
||||
end
|
||||
|
||||
it 'should not be able to create new register requests' do
|
||||
@ability.should_not be_able_to(:create, RegisterRequest)
|
||||
end
|
||||
end
|
||||
|
||||
context 'Site guest' do
|
||||
|
@ -69,6 +74,22 @@ describe CanCan do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should be able to create register request' do
|
||||
@ability.should be_able_to(:create, RegisterRequest)
|
||||
end
|
||||
|
||||
it 'should not be able to update register request' do
|
||||
@ability.should_not be_able_to(:update, register_request)
|
||||
end
|
||||
|
||||
it 'should not be able to list register requests' do
|
||||
@ability.should_not be_able_to(:read, register_request)
|
||||
end
|
||||
|
||||
it 'should not be able to destroy register requests' do
|
||||
@ability.should_not be_able_to(:destroy, register_request)
|
||||
end
|
||||
|
||||
it 'should be able to register new user' do
|
||||
@ability.should be_able_to(:create, User)
|
||||
end
|
||||
|
@ -105,6 +126,10 @@ describe CanCan do
|
|||
@ability.should be_able_to(:create, Project)
|
||||
end
|
||||
|
||||
it "should not be able to manage register requests" do
|
||||
@ability.should_not be_able_to(:manage, RegisterRequest)
|
||||
end
|
||||
|
||||
context "private users relations" do
|
||||
before(:each) do
|
||||
@private_user = Factory(:private_user)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe RegisterRequest do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue