Commit 95965d3f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Added UsersGroup validations. Added ability to add UsersGroup to group via UI

parent 81697850
...@@ -63,18 +63,19 @@ class GroupsController < ApplicationController ...@@ -63,18 +63,19 @@ class GroupsController < ApplicationController
def people def people
@project = group.projects.find(params[:project_id]) if params[:project_id] @project = group.projects.find(params[:project_id]) if params[:project_id]
@users = @project ? @project.users : group.users
@users.sort_by!(&:name) @users_groups = group.users_groups
if @project if @project
@team_member = @project.users_projects.new @team_member = @project.users_projects.new
else else
@team_member = UsersProject.new @team_member = UsersGroup.new
end end
end end
def team_members def team_members
@group.add_users_to_project_teams(params[:user_ids].split(','), params[:project_access]) @group.add_users(params[:user_ids].split(','), params[:group_access])
redirect_to people_group_path(@group), notice: 'Users were successfully added.' redirect_to people_group_path(@group), notice: 'Users were successfully added.'
end end
......
...@@ -16,6 +16,12 @@ class Group < Namespace ...@@ -16,6 +16,12 @@ class Group < Namespace
has_many :users_groups, dependent: :destroy has_many :users_groups, dependent: :destroy
has_many :users, through: :users_groups has_many :users, through: :users_groups
def add_users(user_ids, group_access)
user_ids.compact.each do |user_id|
self.users_groups.create(user_id: user_id, group_access: group_access)
end
end
def add_users_to_project_teams(user_ids, project_access) def add_users_to_project_teams(user_ids, project_access)
UsersProject.add_users_into_projects( UsersProject.add_users_into_projects(
projects.map(&:id), projects.map(&:id),
......
...@@ -5,6 +5,16 @@ class UsersGroup < ActiveRecord::Base ...@@ -5,6 +5,16 @@ class UsersGroup < ActiveRecord::Base
MASTER = 40 MASTER = 40
OWNER = 50 OWNER = 50
def self.group_access_roles
{
"Guest" => GUEST,
"Reporter" => REPORTER,
"Developer" => DEVELOPER,
"Master" => MASTER,
"Owner" => OWNER
}
end
attr_accessible :group_access, :group_id, :user_id attr_accessible :group_access, :group_id, :user_id
belongs_to :user belongs_to :user
...@@ -18,4 +28,12 @@ class UsersGroup < ActiveRecord::Base ...@@ -18,4 +28,12 @@ class UsersGroup < ActiveRecord::Base
scope :with_group, ->(group) { where(group_id: group.id) } scope :with_group, ->(group) { where(group_id: group.id) }
scope :with_user, ->(user) { where(user_id: user.id) } scope :with_user, ->(user) { where(user_id: user.id) }
validates :group_access, inclusion: { in: UsersGroup.group_access_roles.values }, presence: true
validates :user_id, presence: true
validates :group_id, presence: true
def human_group_access
UsersGroup.group_access_roles.index(self.group_access)
end
end end
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
%h6 2. Set access level for them %h6 2. Set access level for them
.clearfix .clearfix
= f.label :project_access, "Project Access" = f.label :group_access, "Group Access"
.input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" .input= select_tag :group_access, options_for_select(UsersGroup.group_access_roles, @team_member.group_access), class: "project-access-select chosen"
.form-actions .form-actions
= hidden_field_tag :redirect_to, people_group_path(@group) = hidden_field_tag :redirect_to, people_group_path(@group)
= f.submit 'Add', class: "btn btn-save" = f.submit 'Add users into group', class: "btn btn-create"
...@@ -8,13 +8,18 @@ ...@@ -8,13 +8,18 @@
%h5.title %h5.title
Team Team
%small %small
(#{@users.size}) (#{@users_groups.count})
%ul.well-list %ul.well-list
- @users.each do |user| - @users_groups.each do |users_group|
- user = users_group.user
%li %li
= image_tag gravatar_icon(user.email, 16), class: "avatar s16" = image_tag gravatar_icon(user.email, 16), class: "avatar s16"
%strong= user.name %strong= user.name
%span.cgray= user.email %span.cgray= user.username
- if @group.owner == user
%span.btn.btn-small.disabled.pull-right Group Owner %span.pull-right
- if @group.owners.include?(user)
%span.label.label-info Group Owner
- else
= users_group.human_group_access
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130614132337) do ActiveRecord::Schema.define(:version => 20130617095603) do
create_table "deploy_keys_projects", :force => true do |t| create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false t.integer "deploy_key_id", :null => false
...@@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t.integer "assignee_id" t.integer "assignee_id"
t.integer "author_id" t.integer "author_id"
t.integer "project_id" t.integer "project_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "position", :default => 0 t.integer "position", :default => 0
t.string "branch_name" t.string "branch_name"
t.text "description" t.text "description"
...@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
create_table "keys", :force => true do |t| create_table "keys", :force => true do |t|
t.integer "user_id" t.integer "user_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.text "key" t.text "key"
t.string "title" t.string "title"
t.string "identifier" t.string "identifier"
...@@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t.integer "author_id" t.integer "author_id"
t.integer "assignee_id" t.integer "assignee_id"
t.string "title" t.string "title"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.text "st_commits", :limit => 2147483647 t.text "st_commits", :limit => 2147483647
t.text "st_diffs", :limit => 2147483647 t.text "st_diffs", :limit => 2147483647
t.integer "milestone_id" t.integer "milestone_id"
...@@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t.text "note" t.text "note"
t.string "noteable_type" t.string "noteable_type"
t.integer "author_id" t.integer "author_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "project_id" t.integer "project_id"
t.string "attachment" t.string "attachment"
t.string "line_code" t.string "line_code"
...@@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t.string "name" t.string "name"
t.string "path" t.string "path"
t.text "description" t.text "description"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "creator_id" t.integer "creator_id"
t.string "default_branch" t.string "default_branch"
t.boolean "issues_enabled", :default => true, :null => false t.boolean "issues_enabled", :default => true, :null => false
...@@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t.text "content" t.text "content"
t.integer "author_id", :null => false t.integer "author_id", :null => false
t.integer "project_id" t.integer "project_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "file_name" t.string "file_name"
t.datetime "expires_at" t.datetime "expires_at"
t.boolean "private", :default => true, :null => false t.boolean "private", :default => true, :null => false
...@@ -228,6 +228,9 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -228,6 +228,9 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t.datetime "created_at" t.datetime "created_at"
end end
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", :force => true do |t| create_table "tags", :force => true do |t|
t.string "name" t.string "name"
end end
...@@ -259,52 +262,61 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -259,52 +262,61 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
end end
create_table "users", :force => true do |t| create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0 t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "name" t.string "name"
t.boolean "admin", :default => false, :null => false t.boolean "admin", :default => false, :null => false
t.integer "projects_limit", :default => 10 t.integer "projects_limit", :default => 10
t.string "skype", :default => "", :null => false t.string "skype", :default => "", :null => false
t.string "linkedin", :default => "", :null => false t.string "linkedin", :default => "", :null => false
t.string "twitter", :default => "", :null => false t.string "twitter", :default => "", :null => false
t.string "authentication_token" t.string "authentication_token"
t.integer "theme_id", :default => 1, :null => false t.integer "theme_id", :default => 1, :null => false
t.string "bio" t.string "bio"
t.integer "failed_attempts", :default => 0 t.integer "failed_attempts", :default => 0
t.datetime "locked_at" t.datetime "locked_at"
t.string "extern_uid" t.string "extern_uid"
t.string "provider" t.string "provider"
t.string "username" t.string "username"
t.boolean "can_create_group", :default => true, :null => false t.boolean "can_create_group", :default => true, :null => false
t.boolean "can_create_team", :default => true, :null => false t.boolean "can_create_team", :default => true, :null => false
t.string "state" t.string "state"
t.integer "color_scheme_id", :default => 1, :null => false t.integer "color_scheme_id", :default => 1, :null => false
t.integer "notification_level", :default => 1, :null => false t.integer "notification_level", :default => 1, :null => false
t.datetime "password_expires_at" t.datetime "password_expires_at"
t.integer "created_by_id" t.integer "created_by_id"
end end
add_index "users", ["admin"], :name => "index_users_on_admin" add_index "users", ["admin"], :name => "index_users_on_admin"
add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["extern_uid", "provider"], :name => "index_users_on_extern_uid_and_provider", :unique => true
add_index "users", ["name"], :name => "index_users_on_name" add_index "users", ["name"], :name => "index_users_on_name"
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_index "users", ["username"], :name => "index_users_on_username" add_index "users", ["username"], :name => "index_users_on_username"
create_table "users_groups", :force => true do |t|
t.integer "access_level", :null => false
t.integer "group_id", :null => false
t.integer "user_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users_projects", :force => true do |t| create_table "users_projects", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.integer "project_id", :null => false t.integer "project_id", :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "project_access", :default => 0, :null => false t.integer "project_access", :default => 0, :null => false
t.integer "notification_level", :default => 3, :null => false t.integer "notification_level", :default => 3, :null => false
end end
...@@ -316,8 +328,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do ...@@ -316,8 +328,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
create_table "web_hooks", :force => true do |t| create_table "web_hooks", :force => true do |t|
t.string "url" t.string "url"
t.integer "project_id" t.integer "project_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "type", :default => "ProjectHook" t.string "type", :default => "ProjectHook"
t.integer "service_id" t.integer "service_id"
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment