Add missing validation of maximum number of labels
authorMatthias Schmidt <gravatronics@live.com>
Sun, 10 May 2015 07:23:49 +0000 (09:23 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 10 May 2015 07:23:49 +0000 (09:23 +0200)
files/js/WCF.Conversation.js
files/lib/data/conversation/ConversationAction.class.php
files/lib/data/conversation/label/ConversationLabelAction.class.php

index 23687e379c9e84ccde831c9c0efa8b010868e75d..ffd2dcd490d88811a9b979b63870bf39f2afad59 100644 (file)
@@ -1061,6 +1061,18 @@ WCF.Conversation.Label.Manager = Class.extend({
         */
        _proxy: null,
        
+       /**
+        * maximum number of labels the user may create
+        * @var integer
+        */
+       _maxLabels: 0,
+       
+       /**
+        * number of labels the user created
+        * @var integer
+        */
+       _labelCount: 0,
+       
        /**
         * Initializes the label manager for conversations.
         * 
@@ -1068,6 +1080,8 @@ WCF.Conversation.Label.Manager = Class.extend({
         */
        init: function(link) {
                this._deletedLabelID = 0;
+               this._maxLabels = 0;
+               this._labelCount = 0;
                this._link = link;
                
                this._labels = WCF.Dropdown.getDropdownMenu('conversationLabelFilter').children('.scrollableDropdownMenu');
@@ -1109,6 +1123,9 @@ WCF.Conversation.Label.Manager = Class.extend({
                                break;
                                
                                case 'getLabelManagement':
+                                       this._maxLabels = parseInt(data.returnValues.maxLabels);
+                                       this._labelCount = parseInt(data.returnValues.labelCount);
+                                       
                                        // render dialog
                                        this._dialog.empty().html(data.returnValues.template);
                                        this._dialog.wcfDialog({
@@ -1146,6 +1163,12 @@ WCF.Conversation.Label.Manager = Class.extend({
                this._labels.append($listItem);
                
                this._notification.show();
+               
+               this._labelCount++;
+               
+               if (this._labelCount >= this._maxLabels) {
+                       $('#conversationLabelManagementForm').hide();
+               }
        },
        
        /**
@@ -1157,6 +1180,11 @@ WCF.Conversation.Label.Manager = Class.extend({
                        $('#labelName').on('input', $.proxy(this._updateLabels, this));
                }
                
+               if (this._labelCount >= this._maxLabels) {
+                       $('#conversationLabelManagementForm').hide();
+                       this._dialog.wcfDialog('render');
+               }
+               
                $('#addLabel').disable().click($.proxy(this._addLabel, this));
                $('#editLabel').disable();
                
@@ -1169,6 +1197,11 @@ WCF.Conversation.Label.Manager = Class.extend({
         * @param       object          event
         */
        _edit: function(event) {
+               if (this._labelCount >= this._maxLabels) {
+                       $('#conversationLabelManagementForm').show();
+                       this._dialog.wcfDialog('render');
+               }
+               
                var $label = $(event.currentTarget);
                
                // replace legends
index 41305146194ccf8090502dd62e23bcca208ecccf..6830bb4997fed9530d6125445f2d64634c7e92aa 100644 (file)
@@ -374,7 +374,9 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                
                return array(
                        'actionName' => 'getLabelManagement',
-                       'template' => WCF::getTPL()->fetch('conversationLabelManagement')
+                       'template' => WCF::getTPL()->fetch('conversationLabelManagement'),
+                       'maxLabels' => WCF::getSession()->getPermission('user.conversation.maxLabels'),
+                       'labelCount' => count(ConversationLabel::getLabelsByUser())
                );
        }
        
index 0a060d8c0490ec26b3fb136f56aa39f3afe66388..de39825aa3a3c11ff7b3230b7670bbcbe882fdec 100644 (file)
@@ -89,6 +89,11 @@ class ConversationLabelAction extends AbstractDatabaseObjectAction {
                        throw new PermissionDeniedException();
                }
                
+               // check if user has already created maximum number of labels
+               if (count(ConversationLabel::getLabelsByUser()) >= WCF::getSession()->getPermission('user.conversation.maxLabels')) {
+                       throw new PermissionDeniedException();
+               }
+               
                $this->readString('labelName', false, 'data');
                $this->readString('cssClassName', false, 'data');
                if (!in_array($this->parameters['data']['cssClassName'], ConversationLabel::getLabelCssClassNames())) {