This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from sfc-rg/feature/grouping
Grouping
- Loading branch information
Showing
26 changed files
with
196 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the groups controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
.ldap-form { | ||
.setting-form { | ||
margin: 0 auto; | ||
max-width: 400px; | ||
} | ||
|
||
.fields { | ||
position: relative; | ||
} | ||
|
||
.remove_nested_fields { | ||
position: absolute; | ||
left: 410px; | ||
top: 6px; | ||
} | ||
|
||
select { | ||
background-color: white; | ||
border: 1px solid #ddd; | ||
border-radius: 3px; | ||
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06); | ||
box-sizing: border-box; | ||
width: 100%; | ||
height: 36px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class GroupsController < ApplicationController | ||
def index | ||
@groups = Group.all | ||
end | ||
|
||
def create | ||
Group.new(group_params).save | ||
redirect_to groups_path | ||
end | ||
|
||
private | ||
|
||
def group_params | ||
params.require(:group).permit(:name, :kind) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module GroupsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
module SettingsHelper | ||
def group_list | ||
Group.all.map { |t| [t.name, t.id] } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Group < ActiveRecord::Base | ||
enum kind: { other: 0, kg: 10, rg: 20 } | ||
has_many :group_users | ||
has_many :users, through: :group_users | ||
|
||
validates :name, uniqueness: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class GroupUser < ActiveRecord::Base | ||
belongs_to :group | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
class User < ActiveRecord::Base | ||
has_one :slack_credential | ||
has_one :ldap_credential | ||
has_many :group_users | ||
has_many :groups, through: :group_users | ||
|
||
accepts_nested_attributes_for :group_users, allow_destroy: true | ||
|
||
def active? | ||
self.ldap_credential.present? | ||
self.ldap_credential.present? && self.groups.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.content | ||
%h1 グループ一覧 | ||
%table | ||
%tr | ||
%th # | ||
%th Kind | ||
%th Name | ||
%th Members | ||
- @groups.each do |group| | ||
%tr | ||
%td= group.id | ||
%td= group.kind.to_s | ||
%td= group.name | ||
%td= group.users.count | ||
|
||
%h1 グループ追加 | ||
= form_for Group.new do |f| | ||
= f.select :kind, Group.kinds.keys | ||
= f.text_field :name | ||
= f.submit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
.content | ||
%h2 | ||
rg-net のアカウント | ||
rg-net アカウント連携 | ||
= "(#{@current_user.ldap_credential.present? ? '認証済み' : '未認証'})" | ||
- if @current_user.ldap_credential.present? | ||
.ldap-form | ||
.setting-form | ||
%label Username | ||
= text_field :ldap, :username, disabled: true, value: @current_user.ldap_credential.uid | ||
%label Student Id | ||
= text_field :ldap, :username, disabled: true, value: @current_user.ldap_credential.student_id | ||
%p この情報が間違っている場合は #coordinator まで連絡してください。 | ||
- else | ||
= form_tag update_profile_path, method: :patch, class: 'ldap-form' do | ||
= form_tag update_ldap_path, method: :patch, class: 'setting-form' do | ||
%label Username | ||
= text_field :ldap, :username, placeholder: 'username' | ||
%label Password | ||
= password_field :ldap, :password, placeholder: 'password' | ||
= submit_tag '設定' | ||
= submit_tag 'アカウント連携をする' | ||
|
||
%h2 | ||
KG設定 | ||
= nested_form_for @current_user, url: update_profile_path, class: 'setting-form' do |f| | ||
.setting-form | ||
= f.fields_for :group_users do |group_form| | ||
= group_form.link_to_remove do | ||
%i.fa.fa-trash | ||
= group_form.select :group_id, group_list | ||
= f.link_to_add '追加', :group_users | ||
= f.submit 'KG設定を更新する' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
db/migrate/20150906015824_create_groups_and_group_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateGroupsAndGroupUsers < ActiveRecord::Migration | ||
def change | ||
create_table :groups do |t| | ||
t.string :name | ||
t.integer :kind, null: false | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
create_table :group_users do |t| | ||
t.references :group | ||
t.references :user | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GroupsController, type: :controller do | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FactoryGirl.define do | ||
factory :group_user do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FactoryGirl.define do | ||
factory :group do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the GroupsHelper. For example: | ||
# | ||
# describe GroupsHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe GroupsHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Group, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GroupUser, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |