prototype for groups

This commit is contained in:
tykayn 2019-08-27 17:05:17 +02:00
parent 427a07d83d
commit 1a6808a69f
27 changed files with 609 additions and 4 deletions

View File

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -0,0 +1,80 @@
body {
background-color: #fff;
color: #333;
margin: 33px;
}
body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a {
color: #000;
}
a:visited {
color: #666;
}
a:hover {
color: #fff;
background-color: #000;
}
th {
padding-bottom: 5px;
}
td {
padding: 0 5px 7px;
}
div.field,
div.actions {
margin-bottom: 10px;
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px 7px 0;
margin-bottom: 20px;
background-color: #f0f0f0;
}
#error_explanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px -7px 0;
background-color: #c00;
color: #fff;
}
#error_explanation ul li {
font-size: 12px;
list-style: square;
}
label {
display: block;
}

View File

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View File

@ -0,0 +1,58 @@
class UserGroupsController < ApplicationController
before_action :set_user_group, only: [:show, :edit, :update, :destroy]
# GET /user_groups
def index
@user_groups = UserGroup.all
end
# GET /user_groups/1
def show
end
# GET /user_groups/new
def new
@user_group = UserGroup.new
end
# GET /user_groups/1/edit
def edit
end
# POST /user_groups
def create
@user_group = UserGroup.new(user_group_params)
if @user_group.save
redirect_to @user_group, notice: 'User group was successfully created.'
else
render :new
end
end
# PATCH/PUT /user_groups/1
def update
if @user_group.update(user_group_params)
redirect_to @user_group, notice: 'User group was successfully updated.'
else
render :edit
end
end
# DELETE /user_groups/1
def destroy
@user_group.destroy
redirect_to user_groups_url, notice: 'User group was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user_group
@user_group = UserGroup.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def user_group_params
params.require(:user_group).permit(:name, :createAt, :visibility, :members)
end
end

View File

@ -0,0 +1,2 @@
module UserGroupsHelper
end

View File

@ -1,5 +1,30 @@
$no-columns-breakpoint: 600px;
table{
thead{
th{
font-weight: strong;
}
}
td{
padding: 1rem;
}
}
.table-responsive{
width: 100%;
}
.table-striped{
margin: 1rem 0;
tr{
&:odd{
background: $ui-base-lighter-color;
}
}
}
.group-form{
}
code {
font-family: $font-monospace, monospace;
font-weight: 400;

16
app/models/user_group.rb Normal file
View File

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: user_groups
#
# id :bigint(8) not null, primary key
# name :string not null
# createdAt :datetime
# visibility :string
# account_id :integer
# creator_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class UserGroup < ApplicationRecord
end

View File

@ -0,0 +1,3 @@
class UserGroupSerializer < ActiveModel::Serializer
attributes :id, :name, :createAt, :visibility, :members
end

View File

@ -0,0 +1,16 @@
.container.group-form
%p
WORK IN PROGRESS
= simple_form_for(@user_group) do |f|
= f.error_notification
.form-inputs
= f.input :name
= f.input :createdAt
= f.input :visibility
= f.input :account_id
.form-actions
= f.button :submit

View File

@ -0,0 +1,10 @@
- content_for :page_title do
= 'Modifier le groupe'
%h1 Editing user_group
= render 'form'
= link_to 'Show', @user_group
\|
= link_to 'Back', user_groups_path

View File

@ -0,0 +1,32 @@
- content_for :page_title do
= 'Groupes'
.container
.page-header
%h1 Listing user_groups
%table.table-responsive.table-striped
%thead
%tr
%th Name
%th Createat
%th Visibility
%th Members
%th
%th
%th
%tbody
- @user_groups.each do |user_group|
%tr
%td= user_group.name
%td= user_group.createAt
%td= user_group.visibility
%td= user_group.members
%td= link_to 'Show', user_group
%td= link_to 'Edit', edit_user_group_path(user_group)
%td= link_to 'Destroy', user_group, :method => :delete, :data => { :confirm => 'Are you sure?' }
%br
.text-btn
= link_to 'New User group', new_user_group_path

View File

@ -0,0 +1,8 @@
- content_for :page_title do
= 'Nouveau groupe'
.container
%h1 New user_group
= render 'form'
= link_to 'Back', user_groups_path

View File

@ -0,0 +1,18 @@
%p#notice= notice
%p
%b Name:
= @user_group.name
%p
%b Createat:
= @user_group.createAt
%p
%b Visibility:
= @user_group.visibility
%p
%b Members:
= @user_group.members
= link_to 'Edit', edit_user_group_path(@user_group)
\|
= link_to 'Back', user_groups_path

View File

@ -6,6 +6,7 @@ require 'sidekiq-scheduler/web'
Sidekiq::Web.set :session_secret, Rails.application.secrets[:secret_key_base]
Rails.application.routes.draw do
resources :user_groups
mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
authenticate :user, lambda { |u| u.admin? } do

View File

@ -1,4 +1,4 @@
class AddCommentsToDomainBlocks < ActiveRecord::Migration[5.2]
class AddCommentsToDomainBlocks < ActiveRecordinteger::Migration[5.2]
def change
add_column :domain_blocks, :private_comment, :text
add_column :domain_blocks, :public_comment, :text

View File

@ -0,0 +1,14 @@
class CreateUserGroups < ActiveRecord::Migration[5.2]
def change
create_table :user_groups do |t|
t.string :name, null: false
t.datetime :createdAt
t.string :visibility
t.integer :account_id
t.integer :creator_id
has_many :accounts, foreign_key: :domain, primary_key: :domain
t.timestamps
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_08_07_135426) do
ActiveRecord::Schema.define(version: 2019_08_27_120456) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -609,8 +609,8 @@ ActiveRecord::Schema.define(version: 2019_08_07_135426) do
create_table "status_pins", force: :cascade do |t|
t.bigint "account_id", null: false
t.bigint "status_id", null: false
t.datetime "created_at", default: -> { "now()" }, null: false
t.datetime "updated_at", default: -> { "now()" }, null: false
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "updated_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.index ["account_id", "status_id"], name: "index_status_pins_on_account_id_and_status_id", unique: true
end
@ -680,6 +680,16 @@ ActiveRecord::Schema.define(version: 2019_08_07_135426) do
t.index ["uri"], name: "index_tombstones_on_uri"
end
create_table "user_groups", force: :cascade do |t|
t.string "name", null: false
t.datetime "createdAt"
t.string "visibility"
t.integer "account_id"
t.integer "creator_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "user_invite_requests", force: :cascade do |t|
t.bigint "user_id"
t.text "text"

View File

@ -0,0 +1,141 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
#
# Also compared to earlier versions of this generator, there are no longer any
# expectations of assigns and templates rendered. These features have been
# removed from Rails core in Rails 5, but can be added back in via the
# `rails-controller-testing` gem.
RSpec.describe UserGroupsController, type: :controller do
# This should return the minimal set of attributes required to create a valid
# UserGroup. As you add validations to UserGroup, be sure to
# adjust the attributes here as well.
let(:valid_attributes) {
skip("Add a hash of attributes valid for your model")
}
let(:invalid_attributes) {
skip("Add a hash of attributes invalid for your model")
}
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# UserGroupsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET #index" do
it "returns a success response" do
UserGroup.create! valid_attributes
get :index, params: {}, session: valid_session
expect(response).to be_successful
end
end
describe "GET #show" do
it "returns a success response" do
user_group = UserGroup.create! valid_attributes
get :show, params: {id: user_group.to_param}, session: valid_session
expect(response).to be_successful
end
end
describe "GET #new" do
it "returns a success response" do
get :new, params: {}, session: valid_session
expect(response).to be_successful
end
end
describe "GET #edit" do
it "returns a success response" do
user_group = UserGroup.create! valid_attributes
get :edit, params: {id: user_group.to_param}, session: valid_session
expect(response).to be_successful
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new UserGroup" do
expect {
post :create, params: {user_group: valid_attributes}, session: valid_session
}.to change(UserGroup, :count).by(1)
end
it "redirects to the created user_group" do
post :create, params: {user_group: valid_attributes}, session: valid_session
expect(response).to redirect_to(UserGroup.last)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'new' template)" do
post :create, params: {user_group: invalid_attributes}, session: valid_session
expect(response).to be_successful
end
end
end
describe "PUT #update" do
context "with valid params" do
let(:new_attributes) {
skip("Add a hash of attributes valid for your model")
}
it "updates the requested user_group" do
user_group = UserGroup.create! valid_attributes
put :update, params: {id: user_group.to_param, user_group: new_attributes}, session: valid_session
user_group.reload
skip("Add assertions for updated state")
end
it "redirects to the user_group" do
user_group = UserGroup.create! valid_attributes
put :update, params: {id: user_group.to_param, user_group: valid_attributes}, session: valid_session
expect(response).to redirect_to(user_group)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'edit' template)" do
user_group = UserGroup.create! valid_attributes
put :update, params: {id: user_group.to_param, user_group: invalid_attributes}, session: valid_session
expect(response).to be_successful
end
end
end
describe "DELETE #destroy" do
it "destroys the requested user_group" do
user_group = UserGroup.create! valid_attributes
expect {
delete :destroy, params: {id: user_group.to_param}, session: valid_session
}.to change(UserGroup, :count).by(-1)
end
it "redirects to the user_groups list" do
user_group = UserGroup.create! valid_attributes
delete :destroy, params: {id: user_group.to_param}, session: valid_session
expect(response).to redirect_to(user_groups_url)
end
end
end

View File

@ -0,0 +1,6 @@
Fabricator(:user_group) do
name "MyString"
createAt "2019-08-27 14:04:56"
visibility "MyString"
members ""
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the UserGroupsHelper. For example:
#
# describe UserGroupsHelper 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 UserGroupsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe UserGroup, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,10 @@
require 'rails_helper'
RSpec.describe "UserGroups", type: :request do
describe "GET /user_groups" do
it "works! (now write some real specs)" do
get user_groups_path
expect(response).to have_http_status(200)
end
end
end

View File

@ -0,0 +1,38 @@
require "rails_helper"
RSpec.describe UserGroupsController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/user_groups").to route_to("user_groups#index")
end
it "routes to #new" do
expect(:get => "/user_groups/new").to route_to("user_groups#new")
end
it "routes to #show" do
expect(:get => "/user_groups/1").to route_to("user_groups#show", :id => "1")
end
it "routes to #edit" do
expect(:get => "/user_groups/1/edit").to route_to("user_groups#edit", :id => "1")
end
it "routes to #create" do
expect(:post => "/user_groups").to route_to("user_groups#create")
end
it "routes to #update via PUT" do
expect(:put => "/user_groups/1").to route_to("user_groups#update", :id => "1")
end
it "routes to #update via PATCH" do
expect(:patch => "/user_groups/1").to route_to("user_groups#update", :id => "1")
end
it "routes to #destroy" do
expect(:delete => "/user_groups/1").to route_to("user_groups#destroy", :id => "1")
end
end
end

View File

@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe "user_groups/edit", type: :view do
before(:each) do
@user_group = assign(:user_group, UserGroup.create!(
:name => "MyString",
:visibility => "MyString",
:members => ""
))
end
it "renders the edit user_group form" do
render
assert_select "form[action=?][method=?]", user_group_path(@user_group), "post" do
assert_select "input[name=?]", "user_group[name]"
assert_select "input[name=?]", "user_group[visibility]"
assert_select "input[name=?]", "user_group[members]"
end
end
end

View File

@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe "user_groups/index", type: :view do
before(:each) do
assign(:user_groups, [
UserGroup.create!(
:name => "Name",
:visibility => "Visibility",
:members => ""
),
UserGroup.create!(
:name => "Name",
:visibility => "Visibility",
:members => ""
)
])
end
it "renders a list of user_groups" do
render
assert_select "tr>td", :text => "Name".to_s, :count => 2
assert_select "tr>td", :text => "Visibility".to_s, :count => 2
assert_select "tr>td", :text => "".to_s, :count => 2
end
end

View File

@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe "user_groups/new", type: :view do
before(:each) do
assign(:user_group, UserGroup.new(
:name => "MyString",
:visibility => "MyString",
:members => ""
))
end
it "renders new user_group form" do
render
assert_select "form[action=?][method=?]", user_groups_path, "post" do
assert_select "input[name=?]", "user_group[name]"
assert_select "input[name=?]", "user_group[visibility]"
assert_select "input[name=?]", "user_group[members]"
end
end
end

View File

@ -0,0 +1,18 @@
require 'rails_helper'
RSpec.describe "user_groups/show", type: :view do
before(:each) do
@user_group = assign(:user_group, UserGroup.create!(
:name => "Name",
:visibility => "Visibility",
:members => ""
))
end
it "renders attributes in <p>" do
render
expect(rendered).to match(/Name/)
expect(rendered).to match(/Visibility/)
expect(rendered).to match(//)
end
end