Commit b0af83f9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'dz-profile-organization' into 'master'

Add organization field to the user profile

## What does this MR do?

Add organization field to the user profile 

## Are there points in the code the reviewer needs to double check?

no

## Why was this MR needed?

So we can let users fill organization information separately

## Screenshots (if relevant)

![Screen_Shot_2016-09-26_at_7.32.27_PM](/uploads/d11a9a86aa22227f9c9915d195106c5f/Screen_Shot_2016-09-26_at_7.32.27_PM.png)

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- [x] API support added
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

https://gitlab.com/gitlab-org/gitlab-ce/issues/21903

See merge request !6526
parents 166c6cd8 0614cf19
...@@ -4,6 +4,7 @@ v 8.13.0 (unreleased) ...@@ -4,6 +4,7 @@ v 8.13.0 (unreleased)
- Speed-up group milestones show page - Speed-up group milestones show page
- Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison) - Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison)
- Revoke button in Applications Settings underlines on hover. - Revoke button in Applications Settings underlines on hover.
- Add organization field to user profile
v 8.12.2 (unreleased) v 8.12.2 (unreleased)
- Fix Import/Export not recognising correctly the imported services. - Fix Import/Export not recognising correctly the imported services.
......
...@@ -73,7 +73,8 @@ class ProfilesController < Profiles::ApplicationController ...@@ -73,7 +73,8 @@ class ProfilesController < Profiles::ApplicationController
:skype, :skype,
:twitter, :twitter,
:username, :username,
:website_url :website_url,
:organization
) )
end end
end end
...@@ -86,6 +86,9 @@ ...@@ -86,6 +86,9 @@
.form-group .form-group
= f.label :location, 'Location', class: "label-light" = f.label :location, 'Location', class: "label-light"
= f.text_field :location, class: "form-control" = f.text_field :location, class: "form-control"
.form-group
= f.label :organization, 'Organization', class: "label-light"
= f.text_field :organization, class: "form-control"
.form-group .form-group
= f.label :bio, class: "label-light" = f.label :bio, class: "label-light"
= f.text_area :bio, rows: 4, class: "form-control", maxlength: 250 = f.text_area :bio, rows: 4, class: "form-control", maxlength: 250
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
.avatar-holder .avatar-holder
= link_to avatar_icon(@user, 400), target: '_blank' do = link_to avatar_icon(@user, 400), target: '_blank' do
= image_tag avatar_icon(@user, 90), class: "avatar s90", alt: '' = image_tag avatar_icon(@user, 90), class: "avatar s90", alt: ''
.user-info .user-info
.cover-title .cover-title
= @user.name = @user.name
...@@ -70,6 +70,10 @@ ...@@ -70,6 +70,10 @@
.profile-link-holder.middle-dot-divider .profile-link-holder.middle-dot-divider
= icon('map-marker') = icon('map-marker')
= @user.location = @user.location
- unless @user.organization.blank?
.profile-link-holder.middle-dot-divider
= icon('building')
= @user.organization
- if @user.bio.present? - if @user.bio.present?
.cover-desc .cover-desc
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddOrganizationToUser < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :users, :organization, :string
end
end
...@@ -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: 20160920160832) do ActiveRecord::Schema.define(version: 20160926145521) 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"
...@@ -1132,6 +1132,7 @@ ActiveRecord::Schema.define(version: 20160920160832) do ...@@ -1132,6 +1132,7 @@ ActiveRecord::Schema.define(version: 20160920160832) do
t.datetime "otp_grace_period_started_at" t.datetime "otp_grace_period_started_at"
t.boolean "ldap_email", default: false, null: false t.boolean "ldap_email", default: false, null: false
t.boolean "external", default: false t.boolean "external", default: false
t.string "organization"
end end
add_index "users", ["admin"], name: "index_users_on_admin", using: :btree add_index "users", ["admin"], name: "index_users_on_admin", using: :btree
......
...@@ -57,6 +57,7 @@ GET /users ...@@ -57,6 +57,7 @@ GET /users
"linkedin": "", "linkedin": "",
"twitter": "", "twitter": "",
"website_url": "", "website_url": "",
"organization": "",
"last_sign_in_at": "2012-06-01T11:41:01Z", "last_sign_in_at": "2012-06-01T11:41:01Z",
"confirmed_at": "2012-05-23T09:05:22Z", "confirmed_at": "2012-05-23T09:05:22Z",
"theme_id": 1, "theme_id": 1,
...@@ -89,6 +90,7 @@ GET /users ...@@ -89,6 +90,7 @@ GET /users
"linkedin": "", "linkedin": "",
"twitter": "", "twitter": "",
"website_url": "", "website_url": "",
"organization": "",
"last_sign_in_at": null, "last_sign_in_at": null,
"confirmed_at": "2012-05-30T16:53:06.148Z", "confirmed_at": "2012-05-30T16:53:06.148Z",
"theme_id": 1, "theme_id": 1,
...@@ -147,7 +149,8 @@ Parameters: ...@@ -147,7 +149,8 @@ Parameters:
"skype": "", "skype": "",
"linkedin": "", "linkedin": "",
"twitter": "", "twitter": "",
"website_url": "" "website_url": "",
"organization": ""
} }
``` ```
...@@ -178,6 +181,7 @@ Parameters: ...@@ -178,6 +181,7 @@ Parameters:
"linkedin": "", "linkedin": "",
"twitter": "", "twitter": "",
"website_url": "", "website_url": "",
"organization": "",
"last_sign_in_at": "2012-06-01T11:41:01Z", "last_sign_in_at": "2012-06-01T11:41:01Z",
"confirmed_at": "2012-05-23T09:05:22Z", "confirmed_at": "2012-05-23T09:05:22Z",
"theme_id": 1, "theme_id": 1,
...@@ -214,6 +218,7 @@ Parameters: ...@@ -214,6 +218,7 @@ Parameters:
- `linkedin` (optional) - LinkedIn - `linkedin` (optional) - LinkedIn
- `twitter` (optional) - Twitter account - `twitter` (optional) - Twitter account
- `website_url` (optional) - Website URL - `website_url` (optional) - Website URL
- `organization` (optional) - Organization name
- `projects_limit` (optional) - Number of projects user can create - `projects_limit` (optional) - Number of projects user can create
- `extern_uid` (optional) - External UID - `extern_uid` (optional) - External UID
- `provider` (optional) - External provider name - `provider` (optional) - External provider name
...@@ -242,6 +247,7 @@ Parameters: ...@@ -242,6 +247,7 @@ Parameters:
- `linkedin` - LinkedIn - `linkedin` - LinkedIn
- `twitter` - Twitter account - `twitter` - Twitter account
- `website_url` - Website URL - `website_url` - Website URL
- `organization` - Organization name
- `projects_limit` - Limit projects each user can create - `projects_limit` - Limit projects each user can create
- `extern_uid` - External UID - `extern_uid` - External UID
- `provider` - External provider name - `provider` - External provider name
...@@ -296,6 +302,7 @@ GET /user ...@@ -296,6 +302,7 @@ GET /user
"linkedin": "", "linkedin": "",
"twitter": "", "twitter": "",
"website_url": "", "website_url": "",
"organization": "",
"last_sign_in_at": "2012-06-01T11:41:01Z", "last_sign_in_at": "2012-06-01T11:41:01Z",
"confirmed_at": "2012-05-23T09:05:22Z", "confirmed_at": "2012-05-23T09:05:22Z",
"theme_id": 1, "theme_id": 1,
......
...@@ -13,6 +13,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps ...@@ -13,6 +13,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps
fill_in 'user_website_url', with: 'testurl' fill_in 'user_website_url', with: 'testurl'
fill_in 'user_location', with: 'Ukraine' fill_in 'user_location', with: 'Ukraine'
fill_in 'user_bio', with: 'I <3 GitLab' fill_in 'user_bio', with: 'I <3 GitLab'
fill_in 'user_organization', with: 'GitLab'
click_button 'Update profile settings' click_button 'Update profile settings'
@user.reload @user.reload
end end
...@@ -23,6 +24,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps ...@@ -23,6 +24,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps
expect(@user.twitter).to eq 'testtwitter' expect(@user.twitter).to eq 'testtwitter'
expect(@user.website_url).to eq 'testurl' expect(@user.website_url).to eq 'testurl'
expect(@user.bio).to eq 'I <3 GitLab' expect(@user.bio).to eq 'I <3 GitLab'
expect(@user.organization).to eq 'GitLab'
expect(find('#user_location').value).to eq 'Ukraine' expect(find('#user_location').value).to eq 'Ukraine'
end end
......
...@@ -15,7 +15,7 @@ module API ...@@ -15,7 +15,7 @@ module API
class User < UserBasic class User < UserBasic
expose :created_at expose :created_at
expose :is_admin?, as: :is_admin expose :is_admin?, as: :is_admin
expose :bio, :location, :skype, :linkedin, :twitter, :website_url expose :bio, :location, :skype, :linkedin, :twitter, :website_url, :organization
end end
class Identity < Grape::Entity class Identity < Grape::Entity
......
...@@ -60,6 +60,7 @@ module API ...@@ -60,6 +60,7 @@ module API
# linkedin - Linkedin # linkedin - Linkedin
# twitter - Twitter account # twitter - Twitter account
# website_url - Website url # website_url - Website url
# organization - Organization
# projects_limit - Number of projects user can create # projects_limit - Number of projects user can create
# extern_uid - External authentication provider UID # extern_uid - External authentication provider UID
# provider - External provider # provider - External provider
...@@ -74,7 +75,7 @@ module API ...@@ -74,7 +75,7 @@ module API
post do post do
authenticated_as_admin! authenticated_as_admin!
required_attributes! [:email, :password, :name, :username] required_attributes! [:email, :password, :name, :username]
attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :bio, :location, :can_create_group, :admin, :confirm, :external] attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :bio, :location, :can_create_group, :admin, :confirm, :external, :organization]
admin = attrs.delete(:admin) admin = attrs.delete(:admin)
confirm = !(attrs.delete(:confirm) =~ /(false|f|no|0)$/i) confirm = !(attrs.delete(:confirm) =~ /(false|f|no|0)$/i)
user = User.build_user(attrs) user = User.build_user(attrs)
...@@ -111,6 +112,7 @@ module API ...@@ -111,6 +112,7 @@ module API
# linkedin - Linkedin # linkedin - Linkedin
# twitter - Twitter account # twitter - Twitter account
# website_url - Website url # website_url - Website url
# organization - Organization
# projects_limit - Limit projects each user can create # projects_limit - Limit projects each user can create
# bio - Bio # bio - Bio
# location - Location of the user # location - Location of the user
...@@ -122,7 +124,7 @@ module API ...@@ -122,7 +124,7 @@ module API
put ":id" do put ":id" do
authenticated_as_admin! authenticated_as_admin!
attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :website_url, :projects_limit, :username, :bio, :location, :can_create_group, :admin, :external] attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :website_url, :projects_limit, :username, :bio, :location, :can_create_group, :admin, :external, :organization]
user = User.find(params[:id]) user = User.find(params[:id])
not_found!('User') unless user not_found!('User') unless user
......
...@@ -62,6 +62,7 @@ describe API::API, api: true do ...@@ -62,6 +62,7 @@ describe API::API, api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first.keys).to include 'email' expect(json_response.first.keys).to include 'email'
expect(json_response.first.keys).to include 'organization'
expect(json_response.first.keys).to include 'identities' expect(json_response.first.keys).to include 'identities'
expect(json_response.first.keys).to include 'can_create_project' expect(json_response.first.keys).to include 'can_create_project'
expect(json_response.first.keys).to include 'two_factor_enabled' expect(json_response.first.keys).to include 'two_factor_enabled'
...@@ -265,6 +266,14 @@ describe API::API, api: true do ...@@ -265,6 +266,14 @@ describe API::API, api: true do
expect(user.reload.bio).to eq('new test bio') expect(user.reload.bio).to eq('new test bio')
end end
it "updates user with organization" do
put api("/users/#{user.id}", admin), { organization: 'GitLab' }
expect(response).to have_http_status(200)
expect(json_response['organization']).to eq('GitLab')
expect(user.reload.organization).to eq('GitLab')
end
it 'updates user with his own email' do it 'updates user with his own email' do
put api("/users/#{user.id}", admin), email: user.email put api("/users/#{user.id}", admin), email: user.email
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
......
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