Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6d92cd3e
Commit
6d92cd3e
authored
Aug 01, 2016
by
Adam Niedzielski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
e299504b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
9 deletions
+47
-9
app/controllers/projects/project_members_controller.rb
app/controllers/projects/project_members_controller.rb
+1
-1
app/models/member.rb
app/models/member.rb
+4
-2
app/models/members/project_member.rb
app/models/members/project_member.rb
+2
-2
app/models/project_team.rb
app/models/project_team.rb
+3
-2
app/models/user.rb
app/models/user.rb
+1
-1
app/views/projects/project_members/_new_project_member.html.haml
...ws/projects/project_members/_new_project_member.html.haml
+5
-0
db/migrate/20160801163421_add_expires_at_to_member.rb
db/migrate/20160801163421_add_expires_at_to_member.rb
+29
-0
db/schema.rb
db/schema.rb
+2
-1
No files found.
app/controllers/projects/project_members_controller.rb
View file @
6d92cd3e
...
@@ -36,7 +36,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
...
@@ -36,7 +36,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
end
end
def
create
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
)
redirect_to
namespace_project_project_members_path
(
@project
.
namespace
,
@project
)
end
end
...
...
app/models/member.rb
View file @
6d92cd3e
...
@@ -31,6 +31,7 @@ class Member < ActiveRecord::Base
...
@@ -31,6 +31,7 @@ class Member < ActiveRecord::Base
scope
:non_invite
,
->
{
where
(
invite_token:
nil
)
}
scope
:non_invite
,
->
{
where
(
invite_token:
nil
)
}
scope
:request
,
->
{
where
.
not
(
requested_at:
nil
)
}
scope
:request
,
->
{
where
.
not
(
requested_at:
nil
)
}
scope
:has_access
,
->
{
where
(
'access_level > 0'
)
}
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
:guests
,
->
{
where
(
access_level:
GUEST
)
}
scope
:reporters
,
->
{
where
(
access_level:
REPORTER
)
}
scope
:reporters
,
->
{
where
(
access_level:
REPORTER
)
}
...
@@ -54,7 +55,7 @@ class Member < ActiveRecord::Base
...
@@ -54,7 +55,7 @@ class Member < ActiveRecord::Base
class
<<
self
class
<<
self
def
access_for_user_ids
(
user_ids
)
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
end
def
find_by_invite_token
(
invite_token
)
def
find_by_invite_token
(
invite_token
)
...
@@ -73,7 +74,7 @@ class Member < ActiveRecord::Base
...
@@ -73,7 +74,7 @@ class Member < ActiveRecord::Base
user
user
end
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
=
user_for_id
(
user_id
)
# `user` can be either a User object or an email to be invited
# `user` can be either a User object or an email to be invited
...
@@ -87,6 +88,7 @@ class Member < ActiveRecord::Base
...
@@ -87,6 +88,7 @@ class Member < ActiveRecord::Base
if
can_update_member?
(
current_user
,
member
)
||
project_creator?
(
member
,
access_level
)
if
can_update_member?
(
current_user
,
member
)
||
project_creator?
(
member
,
access_level
)
member
.
created_by
||=
current_user
member
.
created_by
||=
current_user
member
.
access_level
=
access_level
member
.
access_level
=
access_level
member
.
expires_at
=
expires_at
member
.
save
member
.
save
end
end
...
...
app/models/members/project_member.rb
View file @
6d92cd3e
...
@@ -33,7 +33,7 @@ class ProjectMember < Member
...
@@ -33,7 +33,7 @@ class ProjectMember < Member
# :master
# :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
)
access_level
=
if
roles_hash
.
has_key?
(
access
)
roles_hash
[
access
]
roles_hash
[
access
]
elsif
roles_hash
.
values
.
include?
(
access
.
to_i
)
elsif
roles_hash
.
values
.
include?
(
access
.
to_i
)
...
@@ -49,7 +49,7 @@ class ProjectMember < Member
...
@@ -49,7 +49,7 @@ class ProjectMember < Member
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
users
.
each
do
|
user
|
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
end
end
end
...
...
app/models/project_team.rb
View file @
6d92cd3e
...
@@ -33,12 +33,13 @@ class ProjectTeam
...
@@ -33,12 +33,13 @@ class ProjectTeam
member
member
end
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
(
ProjectMember
.
add_users_into_projects
(
[
project
.
id
],
[
project
.
id
],
users
,
users
,
access
,
access
,
current_user
current_user
,
expires_at
)
)
end
end
...
...
app/models/user.rb
View file @
6d92cd3e
...
@@ -66,7 +66,7 @@ class User < ActiveRecord::Base
...
@@ -66,7 +66,7 @@ class User < ActiveRecord::Base
# Projects
# Projects
has_many
:groups_projects
,
through: :groups
,
source: :projects
has_many
:groups_projects
,
through: :groups
,
source: :projects
has_many
:personal_projects
,
through: :namespace
,
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
:projects
,
through: :project_members
has_many
:created_projects
,
foreign_key: :creator_id
,
class_name:
'Project'
has_many
:created_projects
,
foreign_key: :creator_id
,
class_name:
'Project'
has_many
:users_star_projects
,
dependent: :destroy
has_many
:users_star_projects
,
dependent: :destroy
...
...
app/views/projects/project_members/_new_project_member.html.haml
View file @
6d92cd3e
...
@@ -14,5 +14,10 @@
...
@@ -14,5 +14,10 @@
Read more about role permissions
Read more about role permissions
%strong
=
link_to
"here"
,
help_page_path
(
"user/permissions"
),
class:
"vlink"
%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
.form-actions
=
f
.
submit
'Add users to project'
,
class:
"btn btn-create"
=
f
.
submit
'Add users to project'
,
class:
"btn btn-create"
db/migrate/20160801163421_add_expires_at_to_member.rb
0 → 100644
View file @
6d92cd3e
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddExpiresAtToMember
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method is the _only_ method called in the migration, any other changes
# should go in a separate migration. This ensures that upon failure _only_ the
# index creation fails and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def
change
add_column
:members
,
:expires_at
,
:datetime
end
end
db/schema.rb
View file @
6d92cd3e
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20160
722221922
)
do
ActiveRecord
::
Schema
.
define
(
version:
20160
801163421
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -581,6 +581,7 @@ ActiveRecord::Schema.define(version: 20160722221922) do
...
@@ -581,6 +581,7 @@ ActiveRecord::Schema.define(version: 20160722221922) do
t
.
string
"invite_token"
t
.
string
"invite_token"
t
.
datetime
"invite_accepted_at"
t
.
datetime
"invite_accepted_at"
t
.
datetime
"requested_at"
t
.
datetime
"requested_at"
t
.
datetime
"expires_at"
end
end
add_index
"members"
,
[
"access_level"
],
name:
"index_members_on_access_level"
,
using: :btree
add_index
"members"
,
[
"access_level"
],
name:
"index_members_on_access_level"
,
using: :btree
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment