Ver código fonte

Evolution #706: TagPrompt tool: favoris: anonyme

Bastien Sevajol 12 anos atrás
pai
commit
e38faab305

+ 7 - 0
src/Muzich/CoreBundle/Controller/CoreController.php Ver arquivo

433
    */
433
    */
434
   public function getDefaultTagsAction($favorites = false)
434
   public function getDefaultTagsAction($favorites = false)
435
   {    
435
   {    
436
+    if ($favorites && ($non_condition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_GET_FAVORITES_TAGS)) !== false)
437
+    {
438
+      return $this->jsonResponseError($non_condition);
439
+    }
440
+    
436
     $last_tags = $this->get("session")->get('user.element_search.last_tags');
441
     $last_tags = $this->get("session")->get('user.element_search.last_tags');
437
     if (!count($last_tags) || $favorites)
442
     if (!count($last_tags) || $favorites)
438
     {
443
     {
439
       $es = $this->getElementSearcher(null, true);
444
       $es = $this->getElementSearcher(null, true);
440
       return $this->jsonResponse(array(
445
       return $this->jsonResponse(array(
441
         'response' => 'success',
446
         'response' => 'success',
447
+        'status' => 'success',
442
         'tags'     => $es->getTags()
448
         'tags'     => $es->getTags()
443
       ));
449
       ));
444
     }
450
     }
445
     
451
     
446
     return $this->jsonResponse(array(
452
     return $this->jsonResponse(array(
447
         'response' => 'success',
453
         'response' => 'success',
454
+        'status' => 'success',
448
         'tags'     => $last_tags
455
         'tags'     => $last_tags
449
       ));
456
       ));
450
   }
457
   }

+ 4 - 0
src/Muzich/CoreBundle/Security/Context.php Ver arquivo

17
   const ACTION_COMMENT_ALERT = 7;
17
   const ACTION_COMMENT_ALERT = 7;
18
   const ACTION_USER_FOLLOW = 8;
18
   const ACTION_USER_FOLLOW = 8;
19
   const ACTION_TAG_ADD = 9;
19
   const ACTION_TAG_ADD = 9;
20
+  const ACTION_GET_FAVORITES_TAGS = 10;
20
   
21
   
21
   const AFFECT_CANT_MAKE = 0;
22
   const AFFECT_CANT_MAKE = 0;
22
   const AFFECT_NO_SCORING = 1;
23
   const AFFECT_NO_SCORING = 1;
62
       ),
63
       ),
63
       self::ACTION_USER_FOLLOW => array(
64
       self::ACTION_USER_FOLLOW => array(
64
         self::CONDITION_USER_NOT_CONNECTED
65
         self::CONDITION_USER_NOT_CONNECTED
66
+      ),
67
+      self::ACTION_GET_FAVORITES_TAGS => array(
68
+        self::CONDITION_USER_NOT_CONNECTED
65
       )
69
       )
66
     ),
70
     ),
67
     self::AFFECT_NO_SCORING => array(
71
     self::AFFECT_NO_SCORING => array(

+ 5 - 0
src/Muzich/CoreBundle/Tests/Controller/AnonymousTest.php Ver arquivo

88
       SecurityContext::CONDITION_USER_NOT_CONNECTED,
88
       SecurityContext::CONDITION_USER_NOT_CONNECTED,
89
       $match
89
       $match
90
     );
90
     );
91
+    $this->security_context_test->testUserCantMakeActionStatus( 
92
+      SecurityContext::ACTION_GET_FAVORITES_TAGS, 
93
+      SecurityContext::CONDITION_USER_NOT_CONNECTED,
94
+      $match
95
+    );
91
   }
96
   }
92
   
97
   
93
   protected function registerUser($email)
98
   protected function registerUser($email)

+ 2 - 0
src/Muzich/CoreBundle/Tests/Security/ContextTest.php Ver arquivo

68
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_GROUP_ADD));
68
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_GROUP_ADD));
69
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_USER_FOLLOW));
69
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_USER_FOLLOW));
70
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
70
     $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
71
+    $this->assertFalse($secutiry_context->canMakeAction(SecurityContext::ACTION_GET_FAVORITES_TAGS));
71
     
72
     
72
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_ADD));
73
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_ADD));
73
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_NOTE));
74
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_NOTE));
79
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
80
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_TAGS_PROPOSITION));
80
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_GROUP_ADD));
81
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_GROUP_ADD));
81
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
82
     $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_ELEMENT_ADD_TO_FAVORITES));
83
+    $this->assertEquals('UserNotConnected', $secutiry_context->actionIsAffectedBy(SecurityContext::AFFECT_CANT_MAKE, SecurityContext::ACTION_GET_FAVORITES_TAGS));
82
   }
84
   }
83
   
85
   
84
 }
86
 }

+ 3 - 0
src/Muzich/CoreBundle/Tests/lib/Security/Context.php Ver arquivo

75
       case SecurityContext::ACTION_USER_FOLLOW:
75
       case SecurityContext::ACTION_USER_FOLLOW:
76
         return $this->security_context_tests->followUserResponseIs($success, $condition);
76
         return $this->security_context_tests->followUserResponseIs($success, $condition);
77
       break;
77
       break;
78
+      case SecurityContext::ACTION_GET_FAVORITES_TAGS:
79
+        return $this->security_context_tests->getFavoritesTagsResponseIs($success, $condition);
80
+      break;
78
       default:
81
       default:
79
         throw new \Exception('Action unknow');
82
         throw new \Exception('Action unknow');
80
     }
83
     }

+ 14 - 0
src/Muzich/CoreBundle/Tests/lib/Security/ContextTestCases.php Ver arquivo

224
     );
224
     );
225
   }
225
   }
226
   
226
   
227
+  public function getFavoritesTagsResponseIs($success, $condition)
228
+  {
229
+    return $this->responseSatisfyConditions(
230
+      $this->getAjaxRequestContentResponse(
231
+        'GET',
232
+        $this->test->generateUrl('ajax_get_favorites_tags', array(
233
+          'favorites' => true
234
+        ))
235
+      ), 
236
+      $success, 
237
+      $condition
238
+    );
239
+  }
240
+  
227
 }
241
 }