gitlab-org--gitlab-foss/app/models
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
..
concerns Added comment notification events to HipChat and Slack services. 2015-03-06 06:54:00 -08:00
hooks Explicitly define ordering in models using default_scope 2015-02-05 14:20:55 -08:00
members Use `project_member` instead of `team_member`. 2015-03-15 13:50:38 +01:00
network
project_services Merge branch 'irker-service-use-supported-events' into 'master' 2015-03-13 00:41:07 +00:00
.gitkeep
ability.rb Merge branch 'fix-restricted-visibility' into 'master' 2015-03-16 17:49:46 +00:00
application_setting.rb Move restricted visibility settings to the UI 2015-03-07 13:11:08 -07:00
broadcast_message.rb Explicitly define ordering in models using default_scope 2015-02-05 14:20:55 -08:00
commit.rb Rubocop: Style/ElseAlignment enabled 2015-02-02 21:38:50 -08:00
deploy_key.rb
deploy_keys_project.rb
diff_line.rb
email.rb Explicitly define ordering in models using default_scope 2015-02-05 14:20:55 -08:00
event.rb Use Gitlab::Git helper methods and constants as much as possible. 2015-03-10 13:39:31 +01:00
external_issue.rb Add ExternalIssue base model to make issue referencing more robust for external issue trackers. 2015-02-11 09:21:57 -08:00
forked_project_link.rb
group.rb Split up AttachmentUploader. 2015-02-20 15:19:50 +01:00
group_milestone.rb Remove duplicates from group milestone participants list. 2015-02-05 21:26:57 +01:00
identity.rb Re-annotate models 2015-03-04 14:14:00 -08:00
issue.rb Remove old team scopes. 2015-03-15 13:50:38 +01:00
key.rb Explicitly define ordering in models using default_scope 2015-02-05 14:20:55 -08:00
label.rb Apply default scope to labels and remove one for notes 2015-02-05 20:29:41 -08:00
label_link.rb
member.rb Explicitly define ordering in models using default_scope 2015-02-05 14:20:55 -08:00
merge_request.rb Remove old team scopes. 2015-03-15 13:50:38 +01:00
merge_request_diff.rb Explicitly define ordering in models using default_scope 2015-02-05 14:20:55 -08:00
milestone.rb Fix method overlap for issue sorting 2015-02-05 16:49:41 -08:00
namespace.rb Fix import check for case sensetive namespaces 2015-03-02 23:06:59 -08:00
note.rb Merge branch 'condensed-mr-commits' into 'master' 2015-03-07 00:13:10 +00:00
notification.rb
personal_snippet.rb
project.rb Merge branch 'fix-restricted-visibility' into 'master' 2015-03-16 17:49:46 +00:00
project_contributions.rb Improve contribution calendar on user page 2015-01-29 17:07:44 -08:00
project_snippet.rb
project_team.rb Use `member` instead of `tm`. 2015-03-15 13:50:38 +01:00
project_wiki.rb Rubocop enabled for: Use spaces inside hash literal braces 2015-02-02 20:36:54 -08:00
protected_branch.rb
repository.rb Everything from gitlab_git is already UTF-8. 2015-03-13 13:49:27 +01:00
service.rb Added comment notification events to HipChat and Slack services. 2015-03-06 06:54:00 -08:00
snippet.rb Added comment notification events to HipChat and Slack services. 2015-03-06 06:54:00 -08:00
tree.rb
user.rb Use `project_member` instead of `team_member`. 2015-03-15 13:50:38 +01:00
users_star_project.rb
wiki_page.rb Rubocop: Style/Alias enabled 2015-02-02 20:57:10 -08:00