Skip to content

Commit

Permalink
Add keys model
Browse files Browse the repository at this point in the history
git shell(customized version of gitlab-shell) will use keys for authortization
before git pull and push. Users can add multiple keys to their accounts.
  • Loading branch information
sonalkr132 committed Jul 18, 2015
1 parent 5d21e8d commit 83f4c85
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Key < ActiveRecord::Base
belongs_to :user
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class User < ActiveRecord::Base
has_many :member_projects, through: :project_members,
source: :member_project
has_many :issues
# authorization of ssh access
has_many :keys

VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20150718043105_create_keys.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateKeys < ActiveRecord::Migration
def change
create_table :keys do |t|
t.integer :user_id
t.text :key
t.string :title
t.string :fingerprint

t.timestamps
end

add_index :keys, [:user_id], name: 'index_keys_on_user_id'
end
end
13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150623095804) do
ActiveRecord::Schema.define(version: 20150718043105) do

create_table "comments", force: true do |t|
t.text "body"
Expand Down Expand Up @@ -67,6 +67,17 @@
t.datetime "updated_at"
end

create_table "keys", force: true do |t|
t.integer "user_id"
t.text "key"
t.string "title"
t.string "fingerprint"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "keys", ["user_id"], name: "index_keys_on_user_id"

create_table "notification_statuses", force: true do |t|
t.integer "victim_id"
t.integer "notification_id"
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/keys.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :key do
key 'MyText'
title 'MyString'
fingerprint 'MyString'
end
end
5 changes: 5 additions & 0 deletions spec/models/key_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

RSpec.describe Key, type: :model do
pending 'add some examples to (or delete) #{__FILE__}'
end

0 comments on commit 83f4c85

Please sign in to comment.