]> granicus.if.org Git - icinga2/commitdiff
Make AddGroup() unique.
authorMichael Friedrich <Michael.Friedrich@netways.de>
Thu, 1 May 2014 22:38:46 +0000 (00:38 +0200)
committerMichael Friedrich <Michael.Friedrich@netways.de>
Thu, 1 May 2014 22:38:46 +0000 (00:38 +0200)
Refs #6105

lib/base/array.cpp
lib/base/array.h
lib/icinga/checkable.cpp
lib/icinga/user.cpp

index 9d236954b7bc8e03a2a86dcb36167a4bc4224d38..d9e8ea06cb8e9df79385f1bb6c3ccb772317cdb8 100644 (file)
@@ -108,6 +108,20 @@ size_t Array::GetLength(void) const
        return m_Data.size();
 }
 
+/**
+ * Checks whether the array contains the specified value.
+ *
+ * @param value The value.
+ * @returns true if the array contains the value, false otherwise.
+ */
+bool Array::Contains(const String& value) const
+{
+       ASSERT(!OwnsLock());
+       ObjectLock olock(this);
+
+       return (std::find(m_Data.begin(), m_Data.end(), value) != m_Data.end());
+}
+
 /**
  * Insert the given value at the specified index
  *
index 0e53fbf783ae36d5f132bcbe67c689d4ef83617b..b7e39b0ef1e8c112fa0d46e7622a4d306fdfedb4 100644 (file)
@@ -50,6 +50,7 @@ public:
        Iterator End(void);
 
        size_t GetLength(void) const;
+       bool Contains(const String& value) const;
 
        void Insert(unsigned int index, const Value& value);
        void Remove(unsigned int index);
index eabce35e36a772752adc08605fd5d2e8dcf10360..d60ffaf440994c2ad9c4ac1aa1c62aa9d7075606 100644 (file)
@@ -94,6 +94,9 @@ void Checkable::AddGroup(const String& name)
 
        Array::Ptr groups = GetGroups();
 
+       if (groups && groups->Contains(name))
+               return;
+
        if (!groups)
                groups = make_shared<Array>();
 
index ca29c293517345de1aa6c228d42a05dcae40dcf4..71ab946b8aafd41ef4a746d9d8a5ceaa9a8ab195 100644 (file)
@@ -75,6 +75,9 @@ void User::AddGroup(const String& name)
 
        Array::Ptr groups = GetGroups();
 
+       if (groups && groups->Contains(name))
+               return;
+
        if (!groups)
                groups = make_shared<Array>();