Browse Source

Evolution #711: Anonyme: page profil user & user favoris

Bastien Sevajol 11 years ago
parent
commit
61be636650

+ 1 - 1
composer.json View File

@@ -26,7 +26,7 @@
26 26
         "doctrine/doctrine-fixtures-bundle": "dev-master",
27 27
         "stof/doctrine-extensions-bundle": "dev-master",  
28 28
         "gregwar/image-bundle": "dev-master",
29
-        "cedriclombardot/admingenerator-generator-bundle": "1.0.*@dev",
29
+        "cedriclombardot/admingenerator-generator-bundle": "2.1.*@dev",
30 30
         "cedriclombardot/twig-generator": "dev-master",
31 31
         "white-october/pagerfanta-bundle": "1.0.*@dev",
32 32
         "pagerfanta/pagerfanta": "1.0.*@dev",

+ 35 - 32
composer.lock View File

@@ -1,19 +1,19 @@
1 1
 {
2
-    "hash": "de4530fc22c2b2f2da7b60c62cbf96f6",
2
+    "hash": "dd5c41c30319b0b4e3eff5370c6bedd2",
3 3
     "packages": [
4 4
         {
5 5
             "name": "cedriclombardot/admingenerator-generator-bundle",
6
-            "version": "dev-master",
6
+            "version": "2.1.x-dev",
7 7
             "target-dir": "Admingenerator/GeneratorBundle",
8 8
             "source": {
9 9
                 "type": "git",
10 10
                 "url": "https://github.com/symfony2admingenerator/AdmingeneratorGeneratorBundle.git",
11
-                "reference": "6fea0cc8aa814f877c3b1ae535a7addbfb904bc2"
11
+                "reference": "1b2ea73c01a5b3d39ae8dd545e46966b5bb1a1e3"
12 12
             },
13 13
             "dist": {
14 14
                 "type": "zip",
15
-                "url": "https://api.github.com/repos/symfony2admingenerator/AdmingeneratorGeneratorBundle/zipball/6fea0cc8aa814f877c3b1ae535a7addbfb904bc2",
16
-                "reference": "6fea0cc8aa814f877c3b1ae535a7addbfb904bc2",
15
+                "url": "https://api.github.com/repos/symfony2admingenerator/AdmingeneratorGeneratorBundle/zipball/1b2ea73c01a5b3d39ae8dd545e46966b5bb1a1e3",
16
+                "reference": "1b2ea73c01a5b3d39ae8dd545e46966b5bb1a1e3",
17 17
                 "shasum": ""
18 18
             },
19 19
             "require": {
@@ -33,7 +33,7 @@
33 33
                 "avalanche123/imagine-bundle": "Image manipulation using Imagine and Twig Filters",
34 34
                 "cedriclombardot/admingenerator-user-bundle": "Help you to overwrite the base layout of FOSUserBundle or others giving a parameter key of the container"
35 35
             },
36
-            "time": "2013-04-23 06:32:11",
36
+            "time": "2013-04-14 09:22:28",
37 37
             "type": "symfony-bundle",
38 38
             "extra": {
39 39
                 "branch-alias": {
@@ -167,7 +167,7 @@
167 167
                 {
168 168
                     "name": "Johannes Schmitt",
169 169
                     "email": "schmittjoh@gmail.com",
170
-                    "homepage": "https://github.com/schmittjoh",
170
+                    "homepage": "http://jmsyst.com",
171 171
                     "role": "Developer of wrapped JMSSerializerBundle"
172 172
                 }
173 173
             ],
@@ -375,21 +375,21 @@
375 375
             "source": {
376 376
                 "type": "git",
377 377
                 "url": "https://github.com/doctrine/DoctrineFixturesBundle.git",
378
-                "reference": "275540d96599baec19fa3292c4d06c5cd4eefd06"
378
+                "reference": "5696cd636df7cbfaf4d1c45ed2922438968cf890"
379 379
             },
380 380
             "dist": {
381 381
                 "type": "zip",
382
-                "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/275540d96599baec19fa3292c4d06c5cd4eefd06",
383
-                "reference": "275540d96599baec19fa3292c4d06c5cd4eefd06",
382
+                "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/5696cd636df7cbfaf4d1c45ed2922438968cf890",
383
+                "reference": "5696cd636df7cbfaf4d1c45ed2922438968cf890",
384 384
                 "shasum": ""
385 385
             },
386 386
             "require": {
387 387
                 "doctrine/data-fixtures": "*",
388 388
                 "doctrine/doctrine-bundle": ">=1.0,<2.0",
389 389
                 "php": ">=5.3.2",
390
-                "symfony/doctrine-bridge": ">=2.1.0,<2.3-dev"
390
+                "symfony/doctrine-bridge": ">=2.1.0,<2.4-dev"
391 391
             },
392
-            "time": "2013-02-12 11:13:27",
392
+            "time": "2013-04-27 11:57:35",
393 393
             "type": "symfony-bundle",
394 394
             "extra": {
395 395
                 "branch-alias": {
@@ -686,22 +686,25 @@
686 686
         },
687 687
         {
688 688
             "name": "jdorn/sql-formatter",
689
-            "version": "v1.2.0",
689
+            "version": "v1.2.9",
690 690
             "source": {
691 691
                 "type": "git",
692
-                "url": "git://github.com/jdorn/sql-formatter.git",
693
-                "reference": "v1.2.0"
692
+                "url": "https://github.com/jdorn/sql-formatter.git",
693
+                "reference": "v1.2.9"
694 694
             },
695 695
             "dist": {
696 696
                 "type": "zip",
697
-                "url": "https://github.com/jdorn/sql-formatter/archive/v1.2.0.zip",
698
-                "reference": "v1.2.0",
697
+                "url": "https://api.github.com/repos/jdorn/sql-formatter/zipball/v1.2.9",
698
+                "reference": "v1.2.9",
699 699
                 "shasum": ""
700 700
             },
701 701
             "require": {
702 702
                 "php": ">=5.2.4"
703 703
             },
704
-            "time": "2012-12-22 21:46:50",
704
+            "require-dev": {
705
+                "phpunit/phpunit": "3.7.*"
706
+            },
707
+            "time": "2013-04-26 18:42:52",
705 708
             "type": "library",
706 709
             "extra": {
707 710
                 "branch-alias": {
@@ -715,7 +718,7 @@
715 718
             },
716 719
             "notification-url": "https://packagist.org/downloads/",
717 720
             "license": [
718
-                "LGPL"
721
+                "MIT"
719 722
             ],
720 723
             "authors": [
721 724
                 {
@@ -765,7 +768,7 @@
765 768
                 {
766 769
                     "name": "Johannes M. Schmitt",
767 770
                     "email": "schmittjoh@gmail.com",
768
-                    "homepage": "https://github.com/schmittjoh",
771
+                    "homepage": "http://jmsyst.com",
769 772
                     "role": "Developer of wrapped JMSSerializerBundle"
770 773
                 }
771 774
             ],
@@ -866,7 +869,7 @@
866 869
                 {
867 870
                     "name": "Johannes M. Schmitt",
868 871
                     "email": "schmittjoh@gmail.com",
869
-                    "homepage": "https://github.com/schmittjoh",
872
+                    "homepage": "http://jmsyst.com",
870 873
                     "role": "Developer of wrapped JMSSerializerBundle"
871 874
                 }
872 875
             ],
@@ -909,7 +912,7 @@
909 912
                 {
910 913
                     "name": "Johannes M. Schmitt",
911 914
                     "email": "schmittjoh@gmail.com",
912
-                    "homepage": "https://github.com/schmittjoh",
915
+                    "homepage": "http://jmsyst.com",
913 916
                     "role": "Developer of wrapped JMSSerializerBundle"
914 917
                 }
915 918
             ],
@@ -972,7 +975,7 @@
972 975
                 {
973 976
                     "name": "Johannes M. Schmitt",
974 977
                     "email": "schmittjoh@gmail.com",
975
-                    "homepage": "https://github.com/schmittjoh",
978
+                    "homepage": "http://jmsyst.com",
976 979
                     "role": "Developer of wrapped JMSSerializerBundle"
977 980
                 }
978 981
             ],
@@ -1105,12 +1108,12 @@
1105 1108
             "source": {
1106 1109
                 "type": "git",
1107 1110
                 "url": "https://github.com/kriswallsmith/assetic.git",
1108
-                "reference": "0a55a9ba70bd9250899ad77deceaf8cb9e145371"
1111
+                "reference": "1b17f9a239276f24344f9f7d7be8293f6dca4e19"
1109 1112
             },
1110 1113
             "dist": {
1111 1114
                 "type": "zip",
1112
-                "url": "https://api.github.com/repos/kriswallsmith/assetic/zipball/0a55a9ba70bd9250899ad77deceaf8cb9e145371",
1113
-                "reference": "0a55a9ba70bd9250899ad77deceaf8cb9e145371",
1115
+                "url": "https://api.github.com/repos/kriswallsmith/assetic/zipball/1b17f9a239276f24344f9f7d7be8293f6dca4e19",
1116
+                "reference": "1b17f9a239276f24344f9f7d7be8293f6dca4e19",
1114 1117
                 "shasum": ""
1115 1118
             },
1116 1119
             "require": {
@@ -1136,7 +1139,7 @@
1136 1139
                 "ptachoire/cssembed": "Assetic provides the integration with phpcssembed to embed data uris",
1137 1140
                 "twig/twig": "Assetic provides the integration with the Twig templating engine"
1138 1141
             },
1139
-            "time": "2013-04-02 21:36:28",
1142
+            "time": "2013-04-27 14:32:20",
1140 1143
             "type": "library",
1141 1144
             "extra": {
1142 1145
                 "branch-alias": {
@@ -1483,12 +1486,12 @@
1483 1486
             "source": {
1484 1487
                 "type": "git",
1485 1488
                 "url": "https://github.com/sonata-project/SonataAdminBundle.git",
1486
-                "reference": "041174991a1d3c6725e1603c389b5767261972c7"
1489
+                "reference": "c611614f23d5d42257747ae81bcc36df86216bae"
1487 1490
             },
1488 1491
             "dist": {
1489 1492
                 "type": "zip",
1490
-                "url": "https://api.github.com/repos/sonata-project/SonataAdminBundle/zipball/041174991a1d3c6725e1603c389b5767261972c7",
1491
-                "reference": "041174991a1d3c6725e1603c389b5767261972c7",
1493
+                "url": "https://api.github.com/repos/sonata-project/SonataAdminBundle/zipball/c611614f23d5d42257747ae81bcc36df86216bae",
1494
+                "reference": "c611614f23d5d42257747ae81bcc36df86216bae",
1492 1495
                 "shasum": ""
1493 1496
             },
1494 1497
             "require": {
@@ -1515,7 +1518,7 @@
1515 1518
                 "sonata-project/doctrine-orm-admin-bundle": "2.1.*@dev",
1516 1519
                 "sonata-project/intl-bundle": "2.1.*"
1517 1520
             },
1518
-            "time": "2013-04-11 21:38:12",
1521
+            "time": "2013-05-03 19:57:10",
1519 1522
             "type": "symfony-bundle",
1520 1523
             "extra": {
1521 1524
                 "branch-alias": {
@@ -1540,7 +1543,7 @@
1540 1543
                 },
1541 1544
                 {
1542 1545
                     "name": "Sonata Community",
1543
-                    "homepage": "https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle/contributors"
1546
+                    "homepage": "https://github.com/sonata-project/SonataAdminBundle/contributors"
1544 1547
                 }
1545 1548
             ],
1546 1549
             "description": "Symfony SonataAdminBundle",

+ 10 - 2
src/Muzich/CoreBundle/Repository/GroupRepository.php View File

@@ -79,16 +79,24 @@ class GroupRepository extends EntityRepository
79 79
    */
80 80
   public function getElementsTags($group_id, $current_user_id)
81 81
   {
82
+    $parameters = array('gid' => $group_id);
83
+    $current_user_sql = '';
84
+    if ($current_user_id)
85
+    {
86
+      $parameters['uidt'] = '%"'.$current_user_id.'"%';
87
+      $current_user_sql = 'OR t.privateids LIKE :uidt';
88
+    }
89
+    
82 90
     return $this->getEntityManager()
83 91
       ->createQuery('
84 92
         SELECT t FROM MuzichCoreBundle:Tag t
85 93
         LEFT JOIN t.elements e
86 94
         WHERE e.group = :gid
87 95
         AND (t.tomoderate = \'FALSE\' OR t.tomoderate IS NULL
88
-          OR t.privateids LIKE :uidt)
96
+          '.$current_user_sql.')
89 97
         ORDER BY t.name ASC'
90 98
       )
91
-      ->setParameters(array('gid' => $group_id, 'uidt' => '%"'.$current_user_id.'"%'))
99
+      ->setParameters($parameters)
92 100
       ->getResult()
93 101
     ;
94 102
   }

+ 10 - 2
src/Muzich/CoreBundle/Repository/UserRepository.php View File

@@ -194,16 +194,24 @@ class UserRepository extends EntityRepository
194 194
    */
195 195
   public function getElementsTags($user_id, $current_user_id)
196 196
   {
197
+    $parameters = array('uid' => $user_id);
198
+    $current_user_sql = '';
199
+    if ($current_user_id)
200
+    {
201
+      $parameters['uidt'] = '%"'.$current_user_id.'"%';
202
+      $current_user_sql = 'OR t.privateids LIKE :uidt';
203
+    }
204
+    
197 205
     return $this->getEntityManager()
198 206
       ->createQuery('
199 207
         SELECT t FROM MuzichCoreBundle:Tag t
200 208
         LEFT JOIN t.elements e
201 209
         WHERE e.owner = :uid
202 210
         AND (t.tomoderate = \'FALSE\' OR t.tomoderate IS NULL
203
-          OR t.privateids LIKE :uidt)
211
+          '.$current_user_sql.')
204 212
         ORDER BY t.name ASC'
205 213
       )
206
-      ->setParameters(array('uid' => $user_id, 'uidt' => '%"'.$current_user_id.'"%'))
214
+      ->setParameters($parameters)
207 215
       ->getResult()
208 216
     ;
209 217
   }

+ 4 - 0
src/Muzich/CoreBundle/Resources/config/security.yml View File

@@ -96,6 +96,10 @@ security:
96 96
         - { path: ^/(?:fr|en)$, role: IS_AUTHENTICATED_ANONYMOUSLY }
97 97
         - { path: ^/(?:fr|en)/$, role: IS_AUTHENTICATED_ANONYMOUSLY }
98 98
         - { path: ^/$, role: IS_AUTHENTICATED_ANONYMOUSLY }
99
+        - { path: ^//user, role: IS_AUTHENTICATED_ANONYMOUSLY }
100
+        - { path: ^/(?:fr|en)/user, role: IS_AUTHENTICATED_ANONYMOUSLY }
101
+        - { path: ^//group, role: IS_AUTHENTICATED_ANONYMOUSLY }
102
+        - { path: ^/(?:fr|en)/group, role: IS_AUTHENTICATED_ANONYMOUSLY }
99 103
                                         
100 104
         - { path: ^/, roles: ROLE_USER }
101 105
         

+ 5 - 10
src/Muzich/FavoriteBundle/Controller/FavoriteController.php View File

@@ -212,7 +212,7 @@ class FavoriteController extends Controller
212 212
     ));
213 213
     
214 214
     $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
215
-      ->getTags($viewed_user->getId(), $this->getUserId())      
215
+      ->getTags($viewed_user->getId(), $this->getUserId(true))      
216 216
     ;
217 217
     
218 218
     $tags_id = array();
@@ -226,19 +226,14 @@ class FavoriteController extends Controller
226 226
       'tags_id_json'  => json_encode($tags_id),
227 227
       'user'          => $this->getUser(),
228 228
       'viewed_user'   => $viewed_user,
229
-      'elements'      => $search_object->getElements($this->getDoctrine(), $this->getUserId())
229
+      'elements'      => $search_object->getElements($this->getDoctrine(), $this->getUserId(true))
230 230
     );
231 231
   }
232 232
   
233 233
   public function getElementsAction($user_id, $tags_ids_json, $id_limit = null)
234 234
   {
235
-    if (($response = $this->mustBeConnected()))
236
-    {
237
-      return $response;
238
-    }
239
-    
240 235
     $autoplay_context = 'favorite_user';
241
-    if ($user_id == $this->getUserId())
236
+    if ($user_id == $this->getUserId(true))
242 237
     {
243 238
       $autoplay_context = 'favorite_my';
244 239
     }
@@ -272,13 +267,13 @@ class FavoriteController extends Controller
272 267
     );
273 268
     
274 269
     $viewed_user = $this->getUser();
275
-    if ($user_id != $this->getUserId())
270
+    if ($user_id != $this->getUserId(true))
276 271
     {
277 272
       $viewed_user = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:User')
278 273
         ->findOneById($user_id, array())->getSingleResult();
279 274
     }
280 275
     
281
-    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
276
+    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
282 277
     $count = count($elements);
283 278
     $html = '';
284 279
     if ($count)

+ 13 - 18
src/Muzich/HomeBundle/Controller/ShowController.php View File

@@ -29,7 +29,7 @@ class ShowController extends Controller
29 29
     ));
30 30
     
31 31
     $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
32
-      ->getElementsTags($viewed_user->getId(), $this->getUserId())      
32
+      ->getElementsTags($viewed_user->getId(), $this->getUserId(true))      
33 33
     ;
34 34
     
35 35
     // Organisation des tags en fonction de leurs utilisation
@@ -63,17 +63,17 @@ class ShowController extends Controller
63 63
       'tags'            => $tags,
64 64
       'tags_id_json'    => json_encode($tags_id),
65 65
       'viewed_user'     => $viewed_user,
66
-      'elements'        => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
67
-      'following'       => $this->getUser()->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId()),
66
+      'elements'        => $search_object->getElements($this->getDoctrine(), $this->getUserId(true)),
67
+      'following'       => (!$this->isVisitor())?$this->getUser()->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId()):false,
68 68
       'user'            => $this->getUser(),
69 69
       'more_count'      => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
70 70
       'more_route'      => 'show_user_more',
71
-      'topmenu_active'  => ($viewed_user->getId() == $this->getUserId()) ? 'myfeeds' : 'public',
71
+      'topmenu_active'  => ($viewed_user->getId() == $this->getUserId(true)) ? 'myfeeds' : 'public',
72 72
       'count_owned'     => count($element_ids_owned),
73 73
       'count_favorited' => $count_favorited,
74 74
       'count_favorited_users' => $count_favorited_users,
75 75
       'count_followers' => $count_followers,
76
-      'add_form'        => ($this->getUserId() == $viewed_user->getId())?$this->getAddForm()->createView():null,
76
+      'add_form'        => ($this->getUserId(true) == $viewed_user->getId())?$this->getAddForm()->createView():null,
77 77
       'add_form_name'   => 'add'
78 78
     );
79 79
   }
@@ -93,14 +93,14 @@ class ShowController extends Controller
93 93
       'count'     => ($count)?$count:$this->container->getParameter('search_default_count')
94 94
     ));
95 95
     
96
-    ($group->getOwner()->getId() == $this->getUserId()) ? $his = true : $his = false;
96
+    ($group->getOwner()->getId() == $this->getUserId(true)) ? $his = true : $his = false;
97 97
     if ($his || $group->getOpen())
98 98
     {      
99 99
       $add_form = $this->getAddForm();
100 100
     }
101 101
     
102 102
     $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
103
-      ->getElementsTags($group->getId(), $this->getUserId())      
103
+      ->getElementsTags($group->getId(), $this->getUserId(true))      
104 104
     ;
105 105
     
106 106
     $tags_id = array();
@@ -129,9 +129,9 @@ class ShowController extends Controller
129 129
       'tags'          => $tags,
130 130
       'tags_id_json'  => json_encode($tags_id),
131 131
       'group'         => $group,
132
-      'his_group'     => ($group->getOwner()->getId() == $this->getUserId()) ? true : false,
133
-      'elements'      => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
134
-      'following'     => $this->getUser()->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()),
132
+      'his_group'     => ($group->getOwner()->getId() == $this->getUserId(true)) ? true : false,
133
+      'elements'      => $search_object->getElements($this->getDoctrine(), $this->getUserId(true)),
134
+      'following'     => (!$this->isVisitor())?$this->getUser()->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()):false,
135 135
       'user'          => $this->getUser(),
136 136
       'add_form'      => (isset($add_form)) ? $add_form->createView() : null,
137 137
       'add_form_name' => (isset($add_form)) ? 'add' : null,
@@ -145,19 +145,14 @@ class ShowController extends Controller
145 145
   }
146 146
   
147 147
   public function getElementsAction($type, $object_id, $tags_ids_json, $id_limit = null)
148
-  {
149
-    if (($response = $this->mustBeConnected()))
150
-    {
151
-      return $response;
152
-    }
153
-    
148
+  { 
154 149
     if ($type != 'user' && $type != 'group')
155 150
     {
156 151
       throw new \Exception("Wrong Type.");
157 152
     }
158 153
     
159 154
     $viewed_user = null;
160
-    if ($type == 'user' && $object_id == $this->getUserId())
155
+    if ($type == 'user' && $object_id == $this->getUserId(true))
161 156
     {
162 157
       $object = $viewed_user = $this->getUser();
163 158
     }
@@ -199,7 +194,7 @@ class ShowController extends Controller
199 194
       'elements'
200 195
     );
201 196
     
202
-    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
197
+    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
203 198
     $count = count($elements);
204 199
     $html = '';
205 200
     if ($count)

+ 10 - 8
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig View File

@@ -19,14 +19,16 @@
19 19
         </a>
20 20
       {% endif %}
21 21
       
22
-      <a href="{{ path('follow', { 'type': 'group', 'id': group.id, 'token': user.personalHash(group.id) }) }}" 
23
-         class="follow_link button darkbutton {% if following %}following{% else %}notfollowing{% endif %}">
24
-        {% if following %}
25
-          {{ 'group.following'|trans({}, 'groups') }}
26
-        {% else %}
27
-          {{ 'group.follow'|trans({}, 'groups') }}
28
-        {% endif %}
29
-      </a>
22
+      {% if app.user %}
23
+        <a href="{{ path('follow', { 'type': 'group', 'id': group.id, 'token': app.user.personalHash(group.id) }) }}" 
24
+           class="follow_link button darkbutton {% if following %}following{% else %}notfollowing{% endif %}">
25
+          {% if following %}
26
+            {{ 'group.following'|trans({}, 'groups') }}
27
+          {% else %}
28
+            {{ 'group.follow'|trans({}, 'groups') }}
29
+          {% endif %}
30
+        </a>
31
+      {% endif %}
30 32
       
31 33
     </div>
32 34
       

+ 21 - 15
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig View File

@@ -7,21 +7,25 @@
7 7
 
8 8
   <div class="top_tools">
9 9
     
10
-    {% if app.user.id == viewed_user.id %}
11
-      {% include 'MuzichCoreBundle:Component:element_add_buttons_topright.html.twig' %}
12
-    {% endif %}
10
+    {% if app.user %}
11
+      {% if app.user.id == viewed_user.id %}
12
+        {% include 'MuzichCoreBundle:Component:element_add_buttons_topright.html.twig' %}
13
+      {% endif %}
14
+    {% endif  %}
13 15
     
14 16
     <div class="show_options">
15 17
             
16
-      {% if app.user.id != viewed_user.id %}
17
-        <a href="{{ path('follow', { 'type': 'user', 'id': viewed_user.id, 'token': user.personalHash(viewed_user.id) }) }}" 
18
-           class="follow_link button darkbutton {% if following %}following{% else %}notfollowing{% endif %}" >
19
-          {% if following %}
20
-            {{ 'user.following'|trans({}, 'users') }}
21
-          {% else %}
22
-            {{ 'user.follow'|trans({}, 'users') }}
23
-          {% endif %}
24
-        </a>
18
+      {% if app.user %}
19
+        {% if app.user.id != viewed_user.id %}
20
+          <a href="{{ path('follow', { 'type': 'user', 'id': viewed_user.id, 'token': user.personalHash(viewed_user.id) }) }}" 
21
+             class="follow_link button darkbutton {% if following %}following{% else %}notfollowing{% endif %}" >
22
+            {% if following %}
23
+              {{ 'user.following'|trans({}, 'users') }}
24
+            {% else %}
25
+              {{ 'user.follow'|trans({}, 'users') }}
26
+            {% endif %}
27
+          </a>
28
+        {% endif %}
25 29
       {% endif %}
26 30
       
27 31
       <a class="button darkbutton" href="{{ path('favorite_user_list', {'slug' : viewed_user.slug}) }}" >
@@ -32,9 +36,11 @@
32 36
     
33 37
     <h1>{{ 'user.show.title'|trans({'%name%' : viewed_user.name}, 'users') }}</h1>
34 38
   
35
-    {% if app.user.id == viewed_user.id %}
36
-      {% include 'MuzichCoreBundle:Component:element_add_box.html.twig'  %}
37
-    {% endif %}
39
+    {% if app.user %}
40
+      {% if app.user.id == viewed_user.id %}
41
+        {% include 'MuzichCoreBundle:Component:element_add_box.html.twig'  %}
42
+      {% endif %}
43
+    {% endif  %}
38 44
     
39 45
     <div class="reputation">
40 46