summaryrefslogtreecommitdiff
path: root/app/controllers/groups
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-09-19 16:49:08 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:57:15 -0200
commit52e0c3b565b7b177abbf8ea3bc573651060179a2 (patch)
tree1cd659377de0a28c7dc5afee456a1b9bb9849d7b /app/controllers/groups
parentd820c090ec85f8118e4cea75bd63d800e812ea25 (diff)
downloadgitlab-ce-52e0c3b565b7b177abbf8ea3bc573651060179a2.tar.gz
Add CRUD for Group Labels
Diffstat (limited to 'app/controllers/groups')
-rw-r--r--app/controllers/groups/labels_controller.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/app/controllers/groups/labels_controller.rb b/app/controllers/groups/labels_controller.rb
new file mode 100644
index 00000000000..449298f51a8
--- /dev/null
+++ b/app/controllers/groups/labels_controller.rb
@@ -0,0 +1,67 @@
+class Groups::LabelsController < Groups::ApplicationController
+ include ToggleSubscriptionAction
+
+ before_action :label, only: [:edit, :update, :destroy, :toggle_subscription]
+ before_action :authorize_admin_labels!, only: [:new, :create, :edit, :update, :destroy]
+
+ respond_to :html
+
+ def index
+ @labels = @group.labels.page(params[:page])
+ end
+
+ def new
+ @label = @group.labels.new
+ end
+
+ def create
+ @label = @group.labels.create(label_params)
+
+ if @label.valid?
+ redirect_to group_labels_path(@group)
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @label.update_attributes(label_params)
+ redirect_to group_labels_path(@group)
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @label.destroy
+
+ respond_to do |format|
+ format.html do
+ redirect_to group_labels_path(@group), notice: 'Label was removed'
+ end
+ format.js
+ end
+ end
+
+ protected
+
+ def authorize_admin_labels!
+ return render_404 unless can?(current_user, :admin_label, @group)
+ end
+
+ def authorize_read_labels!
+ return render_404 unless can?(current_user, :read_label, @group)
+ end
+
+ def label
+ @label ||= @group.labels.find(params[:id])
+ end
+ alias_method :subscribable_resource, :label
+
+ def label_params
+ params.require(:label).permit(:title, :description, :color)
+ end
+end