gitlab-org--gitlab-foss/app/controllers
Dmitriy Zaporozhets 648f38cd98 Merge branch 'fix-restricted-visibility' into 'master'
Restricted visibility levels - bug fix and new feature

This allows admin users to override restricted visibility settings when creating and updating projects and snippets, and moves the restricted visibility configuration from gitlab.yml to the web UI.  See #1903.

## Move configuration location

I added a new section to the application settings page for restricted visibility levels.  Each level has a checkbox, styled with Bootstrap to look like a toggle button.  A checked box means that the level is restricted.  I added a glowing text shadow and changed the background color for checked buttons because the default styles made it hard to distinguish between checked and unchecked.  This image shows the new section with the "Public" box checked:

![restricted_visibility_settings](https://dev.gitlab.org/Okada/gitlabhq/uploads/629562e4313f89b795e81c3bb0f95893/restricted_visibility_settings.png)

## Allow admins to override

To allow admin users to override the restricted visibility levels, I had to remove the `visibility_level` validation from the `Project` class.  The model doesn't know about the `current_user`, which should determine whether the restrictions can be overridden.  We could use the creator in the validation, but that wouldn't work correctly for projects where a non-admin user is the creator and an admin tries to change the project to a restricted visibility level.

The `Project::UpdateService` and `Project::CreateService` classes already had code to determine whether the current user is allowed to use a given visibility level; now all visibility level validation is done in those classes.  Currently, when a non-admin tries to create or update a project using a restricted level, these classes silently set the visibility level to the global default (create) or the project's existing value (update).  I changed this behavior to be more like an Active Model validation, where using a restricted level causes the entire request to be rejected.

Project and personal snippets didn't have service classes, and restricted visibility levels weren't being enforced in the model or the controllers.  The UI disabled radio buttons for restricted levels, but that wouldn't be difficult to circumvent.  I created the `CreateSnippetService` and `UpdateSnippetService` classes to do the same restricted visibility check that the project classes do.  And since I was dealing with snippet visibility levels, I updated the API endpoints for project snippets to allow users to set and update the visibility level.

## TODO

* [x] Add more tests for restricted visibility functionality

cc @sytse @dzaporozhets

See merge request !1655
2015-03-16 17:49:46 +00:00
..
admin Merge branch 'fix-restricted-visibility' into 'master' 2015-03-16 17:49:46 +00:00
dashboard Move group leave action from dashboard/groups to groups/group_members. 2015-03-15 13:52:28 +01:00
explore Use same constant for amount of items per page 2015-03-12 15:37:00 -07:00
groups Move group leave action from dashboard/groups to groups/group_members. 2015-03-15 13:52:28 +01:00
import Merge branch 'github-org-repos' into 'master' 2015-03-12 17:13:25 +00:00
oauth Application admin scaffold 2015-01-17 15:40:09 -08:00
profiles Use `group_member` instead of `users_group` or `membership`. 2015-03-15 13:49:41 +01:00
projects Merge branch 'fix-restricted-visibility' into 'master' 2015-03-16 17:49:46 +00:00
application_controller.rb Use same constant for amount of items per page 2015-03-12 15:37:00 -07:00
confirmations_controller.rb Try signing in the user after user confirmation is correct and redirect to dashboard, otherwise redirect to signin page 2014-10-02 14:38:26 +02:00
dashboard_controller.rb Use same constant for amount of items per page 2015-03-12 15:37:00 -07:00
groups_controller.rb Move group members index from `/members` to `/group_members`. 2015-03-15 13:51:11 +01:00
help_controller.rb Add GitLab UI development kit 2015-03-08 14:46:22 -07:00
namespaces_controller.rb Rubocop: no trailing newlines 2015-02-02 21:53:27 -08:00
omniauth_callbacks_controller.rb When add new social account - redirect to accounts page and show notice message 2015-02-08 00:53:31 -08:00
passwords_controller.rb Use ruby 1.9 hash syntax 2015-01-23 17:41:10 -08:00
profiles_controller.rb Use same constant for amount of items per page 2015-03-12 15:37:00 -07:00
projects_controller.rb Update html-pipeline and emoji 2015-03-11 16:05:01 -07:00
registrations_controller.rb Redirect signup page to signin page. 2015-02-05 15:56:28 +01:00
search_controller.rb Merge pull request #7695 from coverer/search_wiki 2014-09-09 16:50:43 +03:00
sessions_controller.rb Improve application settings and write tests 2015-01-08 09:53:35 -08:00
snippets_controller.rb Merge branch 'master' into fix-restricted-visibility 2015-03-14 10:49:11 -06:00
uploads_controller.rb Reject access to group/project avatar if the user doesn't have access. 2015-03-10 17:13:02 +01:00
users_controller.rb Exclude forks from profile contributions list. 2015-02-24 16:28:23 +01:00