Beispiel #1
0
      public void Has_CanMarkOffensive_And_CanMarkUnoffensive()
      {
         ImageView view = new ImageView { CanMarkOffensive = true, CanUnmarkOffensive = true };

         Assert.IsTrue(view.CanMarkOffensive);
         Assert.IsTrue(view.CanUnmarkOffensive);
      }
Beispiel #2
0
      public void Has_OffensiveCount_And_ShowOffensiveCount()
      {
         ImageView view = new ImageView { OffensiveCount = 0, ShowOffensiveCount = true };

         Assert.AreEqual(0, view.OffensiveCount);
         Assert.AreEqual(true, view.ShowOffensiveCount);
      }
Beispiel #3
0
      public void Has_Title_Description_IsEditable_With_False_Value_IsPublic_And_PreviewUrl()
      {
         Guid id = Guid.NewGuid();

         ImageView view = new ImageView(id, "TitleF", "DescriptionF", "OriginalUrlF");

         Assert.AreEqual(id, view.Id);
         Assert.AreEqual("TitleF", view.Title);
         Assert.AreEqual("DescriptionF", view.Description);
         Assert.IsNotNull(view.IsEditable);
         Assert.IsNotNull(view.IsPublic);
         Assert.IsNull(view.PreviewUrl);
         Assert.AreEqual("OriginalUrlF", view.OriginalUrl);
      }
Beispiel #4
0
      public ActionResult Index(Guid id, IPrincipal principal)
      {
         if (id == Guid.Empty)
            throw new ArgumentException("Cannot be empty(zeros)", "id");

         try
         {
            TadmapImage image = _imageRepository.GetAllImages().WithId(id).Single();

            ImageView model = new ImageView(image.Id, image.Title, image.Description, null);

            if (image.IsOffensive)
            {
               if (!principal.IsInRole(TadMapRoles.Administrator))
                  throw new SecurityException("Only administrator can view images marked as offensive");

               model.OffensiveCount = 1;
               model.ShowOffensiveCount = true;
               model.CanUnmarkOffensive = true;
            }
            else
            {
               model.OffensiveCount = 0;
               model.ShowOffensiveCount = principal.IsInRole(TadMapRoles.Administrator);
               model.CanMarkOffensive = principal.IsInRole(TadMapRoles.Administrator);
            }

            if (principal.Identity.Name == image.OwnerName) // owner
            {
               model.IsEditable = principal.Identity.Name == image.OwnerName;
               model.OriginalUrl = _binaryRepository.GetUrl(image.Key);
            }
            else if (principal.IsInRole(TadMapRoles.Administrator)) // administrator
            {
               model.OriginalUrl = _binaryRepository.GetUrl(image.Key);
            }
            else // guest
            {
               model.OriginalUrl = null;
            }

            model.PreviewUrl = _binaryRepository.GetUrl(image.ImageSet.Preview);

            model.IsPublic = image.IsPublic;

            if (principal.Identity.IsAuthenticated)
            {
               //UserOpenId openId = db.UserOpenIds.Single(i => i.OpenIdUrl == HttpContext.User.Identity.Name);

               //if (image.UserId == openId.UserId)
               //{
               //   // Owning user
               //   ViewData["CanEdit"] = true;
               //}
               //else
               //{
               //   // Other registered user
               //   if (image.Privacy == 0)
               //      if (!HttpContext.User.IsInRole(TadMapRoles.Administrator))
               //         throw new SecurityException("Only owner or administrator can view private image");
               //}
            }
            else if (!image.IsPublic)
            {
               throw new SecurityException("User must be authenticated to view a private image");
            }

            ViewData.Model = model;
         }
         catch (InvalidOperationException)
         {
            throw new ImageNotFoundException();
         }

         return View();
      }