diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2016-08-01 21:12:30 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2016-08-01 21:12:30 +0300 |
commit | 6d92cd3e836f2252b660479f5b33d15e6456b04d (patch) | |
tree | 547f223094b73a62ce033e9526660dd5457a45a8 /app | |
parent | e299504b798c053817f1c866649542ac0c779924 (diff) |
WIP
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/project_members_controller.rb | 2 | ||||
-rw-r--r-- | app/models/member.rb | 6 | ||||
-rw-r--r-- | app/models/members/project_member.rb | 4 | ||||
-rw-r--r-- | app/models/project_team.rb | 5 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/projects/project_members/_new_project_member.html.haml | 5 |
6 files changed, 16 insertions, 8 deletions
diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index 3435a118964..0fe96b66fa2 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -36,7 +36,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController end def create - @project.team.add_users(params[:user_ids].split(','), params[:access_level], current_user) + @project.team.add_users(params[:user_ids].split(','), params[:access_level], current_user, params[:expires_at]) redirect_to namespace_project_project_members_path(@project.namespace, @project) end diff --git a/app/models/member.rb b/app/models/member.rb index 24ab1276ee9..998144330b1 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -31,6 +31,7 @@ class Member < ActiveRecord::Base scope :non_invite, -> { where(invite_token: nil) } scope :request, -> { where.not(requested_at: nil) } scope :has_access, -> { where('access_level > 0') } + scope :still_active, -> { where('expires_at IS NULL OR expires_at > ?', Time.current) } scope :guests, -> { where(access_level: GUEST) } scope :reporters, -> { where(access_level: REPORTER) } @@ -54,7 +55,7 @@ class Member < ActiveRecord::Base class << self def access_for_user_ids(user_ids) - where(user_id: user_ids).has_access.pluck(:user_id, :access_level).to_h + where(user_id: user_ids).has_access.still_active.pluck(:user_id, :access_level).to_h end def find_by_invite_token(invite_token) @@ -73,7 +74,7 @@ class Member < ActiveRecord::Base user end - def add_user(members, user_id, access_level, current_user = nil) + def add_user(members, user_id, access_level, current_user = nil, expires_at = nil) user = user_for_id(user_id) # `user` can be either a User object or an email to be invited @@ -87,6 +88,7 @@ class Member < ActiveRecord::Base if can_update_member?(current_user, member) || project_creator?(member, access_level) member.created_by ||= current_user member.access_level = access_level + member.expires_at = expires_at member.save end diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index f39afc61ce9..b86b536005b 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -33,7 +33,7 @@ class ProjectMember < Member # :master # ) # - def add_users_into_projects(project_ids, user_ids, access, current_user = nil) + def add_users_into_projects(project_ids, user_ids, access, current_user = nil, expires_at = nil) access_level = if roles_hash.has_key?(access) roles_hash[access] elsif roles_hash.values.include?(access.to_i) @@ -49,7 +49,7 @@ class ProjectMember < Member project = Project.find(project_id) users.each do |user| - Member.add_user(project.project_members, user, access_level, current_user) + Member.add_user(project.project_members, user, access_level, current_user, expires_at) end end end diff --git a/app/models/project_team.rb b/app/models/project_team.rb index fdfaf052730..cf1d2396974 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -33,12 +33,13 @@ class ProjectTeam member end - def add_users(users, access, current_user = nil) + def add_users(users, access, current_user = nil, expires_at = nil) ProjectMember.add_users_into_projects( [project.id], users, access, - current_user + current_user, + expires_at ) end diff --git a/app/models/user.rb b/app/models/user.rb index db747434959..2995db9a5f2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -66,7 +66,7 @@ class User < ActiveRecord::Base # Projects has_many :groups_projects, through: :groups, source: :projects has_many :personal_projects, through: :namespace, source: :projects - has_many :project_members, -> { where(requested_at: nil) }, dependent: :destroy, class_name: 'ProjectMember' + has_many :project_members, -> { where(requested_at: nil).still_active }, dependent: :destroy, class_name: 'ProjectMember' has_many :projects, through: :project_members has_many :created_projects, foreign_key: :creator_id, class_name: 'Project' has_many :users_star_projects, dependent: :destroy diff --git a/app/views/projects/project_members/_new_project_member.html.haml b/app/views/projects/project_members/_new_project_member.html.haml index 978c4dfc5ec..f84aa9e5423 100644 --- a/app/views/projects/project_members/_new_project_member.html.haml +++ b/app/views/projects/project_members/_new_project_member.html.haml @@ -14,5 +14,10 @@ Read more about role permissions %strong= link_to "here", help_page_path("user/permissions"), class: "vlink" + .form-group + = f.label :expires_at, "Membership expires at", class: 'control-label' + .col-sm-10 + = text_field_tag :expires_at, nil, class: "datepicker form-control", placeholder: "Select expires at" + .form-actions = f.submit 'Add users to project', class: "btn btn-create" |