Browse Source

Evolution #614: Paramètrage de la vie personelle

Sevajol Bastien 11 years ago
parent
commit
7fa717902c

+ 1 - 0
app/Resources/translations/network.fr.yml View File

16
 favorites:
16
 favorites:
17
   your_favorites:     Vos favoris
17
   your_favorites:     Vos favoris
18
   user_favorites:     Favoris de %name%
18
   user_favorites:     Favoris de %name%
19
+  nopublic:           %user_username% n'a pas souhaité rendre ses favoris publiques
19
   
20
   
20
 nothing:    |
21
 nothing:    |
21
               Votre réseau n'est pas encore constitué. Utilisez la recherche pour
22
               Votre réseau n'est pas encore constitué. Utilisez la recherche pour

+ 9 - 1
app/Resources/translations/userui.fr.yml View File

90
                     La configuration de vos tags favoris permettrons de filtrer
90
                     La configuration de vos tags favoris permettrons de filtrer
91
                     la liste de partage selon vos goûts musicaux lors de chacunes de vos
91
                     la liste de partage selon vos goûts musicaux lors de chacunes de vos
92
                     visites. N'hésitez pas à en configurer beaucoups !
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
 change_username:
102
 change_username:
95
   submit:           Changer
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
 connexion:
106
 connexion:
99
   password_lost:    Récupérer mon mot de passe
107
   password_lost:    Récupérer mon mot de passe

+ 28 - 1
src/Muzich/CoreBundle/Entity/User.php View File

10
 use Doctrine\ORM\EntityManager;
10
 use Doctrine\ORM\EntityManager;
11
 use Muzich\CoreBundle\Entity\UsersTagsFavorites;
11
 use Muzich\CoreBundle\Entity\UsersTagsFavorites;
12
 use Symfony\Component\Validator\Constraints as Assert;
12
 use Symfony\Component\Validator\Constraints as Assert;
13
-use Muzich\CoreBundle\Validator as MuzichAssert;
14
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
13
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
15
 use Muzich\CoreBundle\Entity\Tag;
14
 use Muzich\CoreBundle\Entity\Tag;
15
+use Muzich\CoreBundle\Managers\UserPrivacy as PrivacyManager;
16
 
16
 
17
 /**
17
 /**
18
  * Cet entité est l'utilisateur ayant effectué la requête.
18
  * Cet entité est l'utilisateur ayant effectué la requête.
295
   /** @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) */
295
   /** @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) */
296
   protected $facebook_id;
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
     $this->playlists_owneds = $playlists_owneds;
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 View File

6
 use Muzich\CoreBundle\Entity\Event;
6
 use Muzich\CoreBundle\Entity\Event;
7
 use Symfony\Component\Form\FormView;
7
 use Symfony\Component\Form\FormView;
8
 use Symfony\Component\DependencyInjection\Container;
8
 use Symfony\Component\DependencyInjection\Container;
9
+use Muzich\CoreBundle\Entity\User;
9
 
10
 
10
 class MyTwigExtension extends \Twig_Extension {
11
 class MyTwigExtension extends \Twig_Extension {
11
 
12
 
29
       'form_has_errors'        => new \Twig_Filter_Method($this, 'form_has_errors'),
30
       'form_has_errors'        => new \Twig_Filter_Method($this, 'form_has_errors'),
30
       'format_score'           => new \Twig_Filter_Method($this, 'format_score'),
31
       'format_score'           => new \Twig_Filter_Method($this, 'format_score'),
31
       'can_autoplay'           => new \Twig_Filter_Method($this, 'can_autoplay'),
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
     }
235
     }
234
     return false;
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 View File

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 View File

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 View File

1620
   width: 388px;
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
   float: right;
1625
   float: right;
1626
   margin-top: 5px;
1626
   margin-top: 5px;
2320
   font-size: 85%;
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 View File

3
 namespace Muzich\CoreBundle\Tests\Controller;
3
 namespace Muzich\CoreBundle\Tests\Controller;
4
 
4
 
5
 use Muzich\CoreBundle\lib\FunctionalTest;
5
 use Muzich\CoreBundle\lib\FunctionalTest;
6
-use Muzich\CoreBundle\Entity\RegistrationToken;
7
 
6
 
8
 class UserControllerTest extends FunctionalTest
7
 class UserControllerTest extends FunctionalTest
9
 {
8
 {
546
     $this->assertEquals(false, $paul->mail_partner);
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 View File

11
 use Muzich\CoreBundle\lib\Tag as TagLib;
11
 use Muzich\CoreBundle\lib\Tag as TagLib;
12
 use Muzich\CoreBundle\Security\Context as SecurityContext;
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
 class FavoriteController extends Controller
14
 class FavoriteController extends Controller
20
 {
15
 {
21
   
16
   
205
   {
200
   {
206
     $viewed_user = $this->findUserWithSlug($slug);
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
     $tags_id = array();
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
     return array(
227
     return array(
226
       'tags_id_json'  => json_encode($tags_id),
229
       'tags_id_json'  => json_encode($tags_id),
227
       'user'          => $this->getUser(),
230
       'user'          => $this->getUser(),
228
       'viewed_user'   => $viewed_user,
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 View File

23
     
23
     
24
   </div>
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
   {% if elements|length %}
39
   {% if elements|length %}
32
     {% include "MuzichCoreBundle:SearchElement:more_button.html.twig" with {
40
     {% include "MuzichCoreBundle:SearchElement:more_button.html.twig" with {

+ 32 - 3
src/Muzich/UserBundle/Controller/UserController.php View File

14
 use Muzich\UserBundle\Form\Type\RegistrationFormType;
14
 use Muzich\UserBundle\Form\Type\RegistrationFormType;
15
 use Muzich\CoreBundle\Entity\User;
15
 use Muzich\CoreBundle\Entity\User;
16
 use Muzich\CoreBundle\Form\User\PasswordForm;
16
 use Muzich\CoreBundle\Form\User\PasswordForm;
17
+use Muzich\CoreBundle\Form\User\PrivacyForm;
17
 
18
 
18
 class UserController extends Controller
19
 class UserController extends Controller
19
 {
20
 {
44
     ;
45
     ;
45
   }
46
   }
46
   
47
   
48
+  protected function getPrivacyForm()
49
+  {
50
+    return $this->createForm(new PrivacyForm(), $this->getUser());
51
+  }
52
+  
47
   protected function getTagsFavoritesForm($user)
53
   protected function getTagsFavoritesForm($user)
48
   {
54
   {
49
     $ids = array();
55
     $ids = array();
91
       'favorite_tags_id'         => $this->getTagsFavorites(),
97
       'favorite_tags_id'         => $this->getTagsFavorites(),
92
       'change_email_form'        => $change_email_form->createView(),
98
       'change_email_form'        => $change_email_form->createView(),
93
       'avatar_form'              => $this->getAvatarForm()->createView(),
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
         'favorite_tags_id'         => $this->getTagsFavorites(),
270
         'favorite_tags_id'         => $this->getTagsFavorites(),
264
         'change_email_form'        => $change_email_form->createView(),
271
         'change_email_form'        => $change_email_form->createView(),
265
         'avatar_form'              => $this->getAvatarForm()->createView(),
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
         'favorite_tags_id'         => $this->getTagsFavorites(),
449
         'favorite_tags_id'         => $this->getTagsFavorites(),
442
         'change_email_form'        => $change_email_form->createView(),
450
         'change_email_form'        => $change_email_form->createView(),
443
         'avatar_form'              => $this->getAvatarForm()->createView(),
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
     return $this->redirect($this->generateUrl('my_account'));
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
   public function updateHelpViewedAction($help_id, $token)
598
   public function updateHelpViewedAction($help_id, $token)
570
   {
599
   {
571
     if ($this->getUser()->getPersonalHash('updateHelpAction') != $token)
600
     if ($this->getUser()->getPersonalHash('updateHelpAction') != $token)

+ 6 - 0
src/Muzich/UserBundle/Resources/config/routing.yml View File

62
   defaults: { _controller: MuzichUserBundle:User:updatePreferences }
62
   defaults: { _controller: MuzichUserBundle:User:updatePreferences }
63
   requirements:
63
   requirements:
64
     _method:  POST
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
 user_hide_help:
72
 user_hide_help:
67
   pattern: /account/update-help/hide/{help_id}/{token}
73
   pattern: /account/update-help/hide/{help_id}/{token}

+ 23 - 0
src/Muzich/UserBundle/Resources/views/User/account.html.twig View File

127
     </div>
127
     </div>
128
     <div style="clear:both;"></div>
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
   </div>
153
   </div>
131
 {% endblock %}
154
 {% endblock %}