docs: def get_object_perms(obj, user=None):
      """Return permissions for given object in Resolwe specific format.
  
      Function returns permissions for given object ``obj`` in following
      format::
  
         {
             "type": "group"/"user"/"public",
             "id": <group_or_user_id>,
             "name": <group_or_user_name>,
             "permissions": [<first_permission>, <second_permission>,...]
         }
  
      For ``public`` type ``id`` and ``name`` keys are omitted.
  
      If ``user`` parameter is given, permissions are limited only to
      given user, groups he belongs to and public permissions.
  
      :param obj: Resolwe's DB model's instance
      :type obj: a subclass of :class:`~resolwe.flow.models.base.BaseModel`
      :param user: Django user
      :type user: :class:`~django.contrib.auth.models.User` or :data:`None`
      :return: list of permissions object in described format
      :rtype: list
  
      """
      def format_permissions(perms):
          """Remove model name from permission."""
          ctype = ContentType.objects.get_for_model(obj)
          return [perm.replace('_{}'.format(ctype.name), '') for perm in perms]
  
      perms_list = []
  
      if user:
          if user.is_authenticated:
              user_perms, group_perms = get_user_group_perms(user, obj)
          else:
              user_perms, group_perms = [], []
  
          if user_perms != []:
              perms_list.append({
                  'type': 'user',
                  'id': user.pk,
                  'name': user.get_full_name() or user.username,
                  'permissions': format_permissions(user_perms),
              })
  
          if group_perms != []:
              for group_id, group_name, perms in group_perms:
                  perms_list.append({
                      'type': 'group',
                      'id': group_id,
                      'name': group_name,
                      'permissions': format_permissions(perms),
                  })
      else:
          user_options = {
              'attach_perms': True,
              'with_group_users': False
          }
          for user, perms in get_users_with_perms(obj, **user_options).items():
              if user.username == settings.ANONYMOUS_USER_NAME:
                  # public user is treated separately
                  continue
              perms_list.append({
                  'type': 'user',
                  'id': user.pk,
                  'name': user.get_full_name() or user.username,
                  'permissions': format_permissions(perms),
              })
  
          group_options = {
              'attach_perms': True,
          }
          for group, perms in get_groups_with_perms(obj, **group_options).items():
              perms_list.append({
                  'type': 'group',
                  'id': group.pk,
                  'name': group.name,
                  'permissions': format_permissions(perms),
              })
  
      public_perms = get_perms(AnonymousUser(), obj)
      if public_perms != []:
          perms_list.append({
              'type': 'public',
              'permissions': format_permissions(public_perms),
          })
  
      return perms_list