Parcourir la source

Evolution #614: Paramètrage de la vie personelle

Sevajol Bastien il y a 11 ans
Parent
révision
7fa717902c

+ 1 - 0
app/Resources/translations/network.fr.yml Voir le fichier

@@ -16,6 +16,7 @@ followed_by:          Ces utilisateurs suivent désormais vos publications
16 16
 favorites:
17 17
   your_favorites:     Vos favoris
18 18
   user_favorites:     Favoris de %name%
19
+  nopublic:           %user_username% n'a pas souhaité rendre ses favoris publiques
19 20
   
20 21
 nothing:    |
21 22
               Votre réseau n'est pas encore constitué. Utilisez la recherche pour

+ 9 - 1
app/Resources/translations/userui.fr.yml Voir le fichier

@@ -90,10 +90,18 @@ my_account:
90 90
                     La configuration de vos tags favoris permettrons de filtrer
91 91
                     la liste de partage selon vos goûts musicaux lors de chacunes de vos
92 92
                     visites. N'hésitez pas à en configurer beaucoups !
93
+  privacy:
94
+    title:          Vie privée
95
+    submit:         Mettre à jour
96
+    form:
97
+      favorites:    Les autres utilisateurs peuvent voir mes favoris
98
+      playlists:    Les autres utilisateurs peuvent voir mes listes de lecture
99
+    success:        Vos paramètres de vie privée ont bien été mises à jour
100
+    error:          Une erreur est survenue lors de la mise à jour de vos paramètres de vie privée
93 101
 
94 102
 change_username:
95 103
   submit:           Changer
96
-  warning:          Attention: une fois votre nom d'utilisateur modifié vous ne pourrez plus en changer !
104
+  warning:          "Attention: une fois votre nom d'utilisateur modifié vous ne pourrez plus en changer !"
97 105
 
98 106
 connexion:
99 107
   password_lost:    Récupérer mon mot de passe

+ 28 - 1
src/Muzich/CoreBundle/Entity/User.php Voir le fichier

@@ -10,9 +10,9 @@ use Gedmo\Mapping\Annotation as Gedmo;
10 10
 use Doctrine\ORM\EntityManager;
11 11
 use Muzich\CoreBundle\Entity\UsersTagsFavorites;
12 12
 use Symfony\Component\Validator\Constraints as Assert;
13
-use Muzich\CoreBundle\Validator as MuzichAssert;
14 13
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
15 14
 use Muzich\CoreBundle\Entity\Tag;
15
+use Muzich\CoreBundle\Managers\UserPrivacy as PrivacyManager;
16 16
 
17 17
 /**
18 18
  * Cet entité est l'utilisateur ayant effectué la requête.
@@ -295,6 +295,11 @@ class User extends BaseUser
295 295
   /** @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) */
296 296
   protected $facebook_id;
297 297
   
298
+  /** 
299
+   * @ORM\Column(type="text", unique=false, nullable=true)
300
+   */
301
+  protected $privacy;
302
+
298 303
   /**
299 304
    * 
300 305
    */
@@ -1258,4 +1263,26 @@ class User extends BaseUser
1258 1263
     $this->playlists_owneds = $playlists_owneds;
1259 1264
   }
1260 1265
   
1266
+  public function getPrivacy()
1267
+  {
1268
+    return json_decode($this->privacy, true);
1269
+  }
1270
+  
1271
+  public function setPrivacy($privacy)
1272
+  {
1273
+    $this->privacy = json_encode($privacy);
1274
+  }
1275
+  
1276
+  public function isFavoritesPublics()
1277
+  {
1278
+    $privacy_manager = new PrivacyManager($this);
1279
+    return $privacy_manager->get(PrivacyManager::CONF_FAVORITES_PUBLIC);
1280
+  }
1281
+  
1282
+  public function setFavoritesPublics($public)
1283
+  {
1284
+    $privacy_manager = new PrivacyManager($this);
1285
+    return $privacy_manager->set(PrivacyManager::CONF_FAVORITES_PUBLIC, $public);
1286
+  }
1287
+  
1261 1288
 }

+ 16 - 1
src/Muzich/CoreBundle/Extension/MyTwigExtension.php Voir le fichier

@@ -6,6 +6,7 @@ use Symfony\Bundle\FrameworkBundle\Translation\Translator;
6 6
 use Muzich\CoreBundle\Entity\Event;
7 7
 use Symfony\Component\Form\FormView;
8 8
 use Symfony\Component\DependencyInjection\Container;
9
+use Muzich\CoreBundle\Entity\User;
9 10
 
10 11
 class MyTwigExtension extends \Twig_Extension {
11 12
 
@@ -29,7 +30,8 @@ class MyTwigExtension extends \Twig_Extension {
29 30
       'form_has_errors'        => new \Twig_Filter_Method($this, 'form_has_errors'),
30 31
       'format_score'           => new \Twig_Filter_Method($this, 'format_score'),
31 32
       'can_autoplay'           => new \Twig_Filter_Method($this, 'can_autoplay'),
32
-      'can_autoplay_type'      => new \Twig_Filter_Method($this, 'can_autoplay_type')
33
+      'can_autoplay_type'      => new \Twig_Filter_Method($this, 'can_autoplay_type'),
34
+      'userId'                 => new \Twig_Filter_Method($this, 'id_or_null')
33 35
     );
34 36
   }
35 37
   
@@ -233,5 +235,18 @@ class MyTwigExtension extends \Twig_Extension {
233 235
     }
234 236
     return false;
235 237
   }
238
+  
239
+  public function id_or_null($user)
240
+  {
241
+    if ($user)
242
+    {
243
+      if ($user instanceof User)
244
+      {
245
+        return $user->getId();
246
+      }
247
+    }
248
+    
249
+    return null;
250
+  }
236 251
 
237 252
 }

+ 45 - 0
src/Muzich/CoreBundle/Form/User/PrivacyForm.php Voir le fichier

@@ -0,0 +1,45 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Form\User;
4
+
5
+use Symfony\Component\Form\AbstractType;
6
+use Symfony\Component\Form\FormBuilderInterface;
7
+use Muzich\CoreBundle\Managers\UserPrivacy as UserPrivacyManager;
8
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
9
+
10
+class PrivacyForm extends AbstractType
11
+{
12
+  protected $options;
13
+  
14
+  public function buildForm(FormBuilderInterface $builder, array $options)
15
+  {
16
+    $this->options = $options;
17
+    foreach (UserPrivacyManager::$configurations as $configuration_id => $configuration_default)
18
+    {
19
+      $builder->add($configuration_id, 'checkbox', array(
20
+        'required' => false
21
+      ));
22
+    }
23
+  }
24
+  
25
+  public function getName()
26
+  {
27
+    return 'user_privacy';
28
+  }
29
+  
30
+  public function setDefaultOptions(OptionsResolverInterface $resolver)
31
+  {
32
+    $defaults = array();
33
+    $alloweds = array();
34
+    
35
+    foreach (UserPrivacyManager::$configurations as $configuration_id => $configuration_default)
36
+    {
37
+      $defaults[$configuration_id] = $configuration_default;
38
+      $alloweds[$configuration_id] = array(true, false);
39
+    }
40
+    
41
+    $resolver->setDefaults($defaults);
42
+    $resolver->setAllowedValues($alloweds);
43
+  }
44
+
45
+}

+ 62 - 0
src/Muzich/CoreBundle/Managers/UserPrivacy.php Voir le fichier

@@ -0,0 +1,62 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Managers;
4
+
5
+use Muzich\CoreBundle\Entity\User;
6
+
7
+class UserPrivacy
8
+{
9
+  
10
+  const CONF_FAVORITES_PUBLIC = 'favorites_publics';
11
+  
12
+  static public $configurations = array(
13
+    self::CONF_FAVORITES_PUBLIC => true
14
+  );
15
+  
16
+  protected $user;
17
+  
18
+  public function __construct(User $user)
19
+  {
20
+    $this->user = $user;
21
+  }
22
+
23
+  public function get($configuration)
24
+  {
25
+    $this->configurationKnew($configuration);
26
+    return $this->getConfigurationValue($configuration);
27
+  }
28
+  
29
+  public function configurationKnew($configuration)
30
+  {
31
+    if (!array_key_exists($configuration, self::$configurations))
32
+      throw new \Exception('Configuration is unknow');
33
+  }
34
+  
35
+  protected function getConfigurationValue($configuration)
36
+  {
37
+    $user_privacy = $this->getUserPrivacy();
38
+    if (!array_key_exists($configuration, $user_privacy))
39
+      return self::$configurations[$configuration];
40
+    
41
+    return $user_privacy[$configuration];
42
+  }
43
+  
44
+  protected function getUserPrivacy()
45
+  {
46
+    $privacy = $this->user->getPrivacy();
47
+    if (!is_array($privacy))
48
+      return array();
49
+    
50
+    return $privacy;
51
+  }
52
+
53
+
54
+  public function set($configuration, $value)
55
+  {
56
+    $this->configurationKnew($configuration);
57
+    $user_privacy = $this->getUserPrivacy();
58
+    $user_privacy[$configuration] = ($value)?true:false;
59
+    $this->user->setPrivacy($user_privacy);
60
+  }
61
+  
62
+}

+ 6 - 1
src/Muzich/CoreBundle/Resources/public/css/main.css Voir le fichier

@@ -1620,7 +1620,7 @@ form.changeemail input[type="text"]
1620 1620
   width: 388px;
1621 1621
 }
1622 1622
 
1623
-form.changeemail input[type="submit"]
1623
+form.changeemail input[type="submit"], form.privacy input[type="submit"]
1624 1624
 {
1625 1625
   float: right;
1626 1626
   margin-top: 5px;
@@ -2320,6 +2320,11 @@ div.playlists_prompt ul.form-errors li
2320 2320
   font-size: 85%;
2321 2321
 }
2322 2322
 
2323
+p.solop
2324
+{
2325
+  margin: 15px;
2326
+}
2327
+
2323 2328
 /*
2324 2329
 *
2325 2330
 *

+ 43 - 1
src/Muzich/CoreBundle/Tests/Controller/UserControllerTest.php Voir le fichier

@@ -3,7 +3,6 @@
3 3
 namespace Muzich\CoreBundle\Tests\Controller;
4 4
 
5 5
 use Muzich\CoreBundle\lib\FunctionalTest;
6
-use Muzich\CoreBundle\Entity\RegistrationToken;
7 6
 
8 7
 class UserControllerTest extends FunctionalTest
9 8
 {
@@ -546,4 +545,47 @@ class UserControllerTest extends FunctionalTest
546 545
     $this->assertEquals(false, $paul->mail_partner);
547 546
   }
548 547
   
548
+  public function testPrivacyUpdate()
549
+  {
550
+    $this->client = self::createClient();
551
+    
552
+    $bux = $this->findUserByUsername('bux');
553
+    
554
+    $this->checkFavoritesViewable($bux, true);
555
+    $this->connectUser('bux', 'toor');
556
+    $this->updateFavoritePrivacy(false);
557
+    $this->disconnectUser();
558
+    $this->checkFavoritesViewable($bux, false);
559
+    $this->connectUser('paul', 'toor');
560
+    $this->checkFavoritesViewable($bux, false);
561
+    $this->disconnectUser();
562
+    $this->connectUser('bux', 'toor');
563
+    $this->checkFavoritesViewable($bux, true);
564
+  }
565
+  
566
+  protected function checkFavoritesViewable($user, $public)
567
+  {
568
+    $this->goToPage($this->generateUrl('favorite_user_list', array('slug' => $user->getSlug(), '_locale' => 'fr')));
569
+    $this->isResponseSuccess();
570
+    if ($public)
571
+      $this->notExist('p.favorites_no_publics');
572
+    if (!$public)
573
+      $this->exist('p.favorites_no_publics');
574
+  }
575
+  
576
+  protected function updateFavoritePrivacy($public)
577
+  {
578
+    $this->goToPage($this->generateUrl('my_account'));
579
+    $form = $this->selectForm('form.privacy input[type="submit"]');
580
+    if ($public)
581
+      $form['user_privacy[favorites_publics]']->tick();
582
+    if (!$public)
583
+      $form['user_privacy[favorites_publics]']->untick();
584
+    $this->submit($form);
585
+    
586
+    $this->isResponseRedirection();
587
+    $this->followRedirection();
588
+    $this->isResponseSuccess();
589
+  }
590
+  
549 591
 }

+ 21 - 18
src/Muzich/FavoriteBundle/Controller/FavoriteController.php Voir le fichier

@@ -11,11 +11,6 @@ use Muzich\CoreBundle\Entity\User;
11 11
 use Muzich\CoreBundle\lib\Tag as TagLib;
12 12
 use Muzich\CoreBundle\Security\Context as SecurityContext;
13 13
 
14
-//use Muzich\CoreBundle\Entity\Group;
15
-//use Muzich\CoreBundle\Form\Group\GroupForm;
16
-//use Symfony\Component\HttpFoundation\Request;
17
-//use Muzich\CoreBundle\Managers\GroupManager;
18
-
19 14
 class FavoriteController extends Controller
20 15
 {
21 16
   
@@ -205,20 +200,28 @@ class FavoriteController extends Controller
205 200
   {
206 201
     $viewed_user = $this->findUserWithSlug($slug);
207 202
     
208
-    $search_object = $this->createSearchObject(array(
209
-      'user_id'  => $viewed_user->getId(),
210
-      'favorite' => true,
211
-      'count'    => $this->container->getParameter('search_default_count')
212
-    ));
213
-    
214
-    $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
215
-      ->getTags($viewed_user->getId(), $this->getUserId(true))      
216
-    ;
217
-    
203
+    $tags = array();
218 204
     $tags_id = array();
219
-    foreach ($tags as $tag)
205
+    $elements = array();
206
+    if ($viewed_user->isFavoritesPublics() || $viewed_user->getId() == $this->getUserId(true))
220 207
     {
221
-      $tags_id[] = $tag->getId();
208
+      $search_object = $this->createSearchObject(array(
209
+        'user_id'  => $viewed_user->getId(),
210
+        'favorite' => true,
211
+        'count'    => $this->container->getParameter('search_default_count')
212
+      ));
213
+
214
+      $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
215
+        ->getTags($viewed_user->getId(), $this->getUserId(true))      
216
+      ;
217
+
218
+      $tags_id = array();
219
+      foreach ($tags as $tag)
220
+      {
221
+        $tags_id[] = $tag->getId();
222
+      }
223
+      
224
+      $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
222 225
     }
223 226
     
224 227
     return array(
@@ -226,7 +229,7 @@ class FavoriteController extends Controller
226 229
       'tags_id_json'  => json_encode($tags_id),
227 230
       'user'          => $this->getUser(),
228 231
       'viewed_user'   => $viewed_user,
229
-      'elements'      => $search_object->getElements($this->getDoctrine(), $this->getUserId(true))
232
+      'elements'      => $elements
230 233
     );
231 234
   }
232 235
   

+ 12 - 4
src/Muzich/FavoriteBundle/Resources/views/Favorite/userList.html.twig Voir le fichier

@@ -23,10 +23,18 @@
23 23
     
24 24
   </div>
25 25
 
26
-  {% include "MuzichCoreBundle:SearchElement:default.html.twig" with{
27
-      'display_autoplay'     : true,
28
-      'autoplay_context'     : 'favorite_user'
29
-  } %}
26
+  {% if not viewed_user.favoritesPublics and viewed_user.id != app.user|userId %}
27
+    
28
+    <p class="solop favorites_no_publics">{{ 'favorites.nopublic'|trans({'%user_username%' : viewed_user.name}, 'network') }}</p>
29
+    
30
+  {% else %}
31
+    
32
+    {% include "MuzichCoreBundle:SearchElement:default.html.twig" with{
33
+        'display_autoplay'     : true,
34
+        'autoplay_context'     : 'favorite_user'
35
+    } %}
36
+    
37
+  {% endif %}
30 38
     
31 39
   {% if elements|length %}
32 40
     {% include "MuzichCoreBundle:SearchElement:more_button.html.twig" with {

+ 32 - 3
src/Muzich/UserBundle/Controller/UserController.php Voir le fichier

@@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\Request;
14 14
 use Muzich\UserBundle\Form\Type\RegistrationFormType;
15 15
 use Muzich\CoreBundle\Entity\User;
16 16
 use Muzich\CoreBundle\Form\User\PasswordForm;
17
+use Muzich\CoreBundle\Form\User\PrivacyForm;
17 18
 
18 19
 class UserController extends Controller
19 20
 {
@@ -44,6 +45,11 @@ class UserController extends Controller
44 45
     ;
45 46
   }
46 47
   
48
+  protected function getPrivacyForm()
49
+  {
50
+    return $this->createForm(new PrivacyForm(), $this->getUser());
51
+  }
52
+  
47 53
   protected function getTagsFavoritesForm($user)
48 54
   {
49 55
     $ids = array();
@@ -91,7 +97,8 @@ class UserController extends Controller
91 97
       'favorite_tags_id'         => $this->getTagsFavorites(),
92 98
       'change_email_form'        => $change_email_form->createView(),
93 99
       'avatar_form'              => $this->getAvatarForm()->createView(),
94
-      'preferences_form'         => $this->getPreferencesForm()->createView()
100
+      'preferences_form'         => $this->getPreferencesForm()->createView(),
101
+      'privacy_form'             => $this->getPrivacyForm()->createView()
95 102
     );
96 103
   }
97 104
   
@@ -263,7 +270,8 @@ class UserController extends Controller
263 270
         'favorite_tags_id'         => $this->getTagsFavorites(),
264 271
         'change_email_form'        => $change_email_form->createView(),
265 272
         'avatar_form'              => $this->getAvatarForm()->createView(),
266
-        'preferences_form'         => $this->getPreferencesForm()->createView()
273
+        'preferences_form'         => $this->getPreferencesForm()->createView(),
274
+        'privacy_form'             => $this->getPrivacyForm()->createView()
267 275
       )
268 276
     );
269 277
   }
@@ -441,7 +449,8 @@ class UserController extends Controller
441 449
         'favorite_tags_id'         => $this->getTagsFavorites(),
442 450
         'change_email_form'        => $change_email_form->createView(),
443 451
         'avatar_form'              => $this->getAvatarForm()->createView(),
444
-        'preferences_form'         => $this->getPreferencesForm()->createView()
452
+        'preferences_form'         => $this->getPreferencesForm()->createView(),
453
+        'privacy_form'             => $this->getPrivacyForm()->createView()
445 454
       )
446 455
     );
447 456
   }
@@ -566,6 +575,26 @@ class UserController extends Controller
566 575
     return $this->redirect($this->generateUrl('my_account'));
567 576
   }
568 577
   
578
+  public function updatePrivacyAction(Request $request)
579
+  {
580
+    $form = $this->getPrivacyForm();
581
+    $form->bind($request);
582
+    
583
+    if ($form->isValid()) {
584
+      $em = $this->getEntityManager();
585
+      $em->persist($form->getData());
586
+      $em->flush();
587
+
588
+      $this->setFlash('success',
589
+        $this->trans('my_account.privacy.success', array(), 'userui'));
590
+      return $this->redirect($this->generateUrl('my_account'));
591
+    }
592
+    
593
+    $this->setFlash('error',
594
+      $this->trans('my_account.privacy.error', array(), 'userui'));
595
+    return $this->redirect($this->generateUrl('my_account'));
596
+  }
597
+  
569 598
   public function updateHelpViewedAction($help_id, $token)
570 599
   {
571 600
     if ($this->getUser()->getPersonalHash('updateHelpAction') != $token)

+ 6 - 0
src/Muzich/UserBundle/Resources/config/routing.yml Voir le fichier

@@ -62,6 +62,12 @@ user_update_preferences:
62 62
   defaults: { _controller: MuzichUserBundle:User:updatePreferences }
63 63
   requirements:
64 64
     _method:  POST
65
+
66
+user_update_privacy:
67
+  pattern:  /account/update-privacy
68
+  defaults: { _controller: MuzichUserBundle:User:updatePrivacy }
69
+  requirements:
70
+    _method:  POST
65 71
   
66 72
 user_hide_help:
67 73
   pattern: /account/update-help/hide/{help_id}/{token}

+ 23 - 0
src/Muzich/UserBundle/Resources/views/User/account.html.twig Voir le fichier

@@ -127,5 +127,28 @@
127 127
     </div>
128 128
     <div style="clear:both;"></div>
129 129
     
130
+    <h2 data-open="myaccount_privacy">{{ 'my_account.privacy.title'|trans({}, 'userui') }}</h2>
131
+  
132
+    <div id="myaccount_privacy" class="myaccount_part"
133
+       style="display: none;"
134
+    >
135
+      <form
136
+        class="privacy"
137
+        action="{{ path('user_update_privacy') }}"
138
+        method="post"
139
+      >
140
+        
141
+        <div class="field">
142
+          <label for="user_privacy_favorites_publics" >{{ 'my_account.privacy.form.favorites'|trans({}, 'userui') }}</label>
143
+          {{ form_widget(privacy_form.favorites_publics) }}
144
+        </div>
145
+        
146
+        {{ form_rest(privacy_form) }}
147
+      
148
+          <input type="submit" class="button" value="{{ 'my_account.privacy.submit'|trans({}, 'userui') }}" />
149
+      </form>
150
+    </div>
151
+    <div style="clear:both;"></div>
152
+    
130 153
   </div>
131 154
 {% endblock %}