/// <summary>
        /// No fancy authorization logic, just create the mod profile it it's the users first time & check they're not a bad egg (negative rep)
        /// </summary>
        void CreateLocationOutdoorAuthorization(LocationOutdoor obj)
        {
            if (obj.TypeID < 21 || obj.TypeID > 60)
            {
                var error = string.Format("Cannot create outdoor location {0} with type set to {1} as it's not a valid outdoor location type", obj.Name, obj.Type);
                throw new ArgumentException(error);
            }

            SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);
        }
Exemple #2
0
 public LocationOutdoorDetailDto(cf.Entities.LocationOutdoor l) : base(l)
 {
     Cautions       = l.Cautions;
     Approach       = l.Approach;
     Altitude       = l.Altitude;
     AccessIssues   = l.AccessIssues;
     AccessClosed   = l.AccessClosed;
     ShadeAfternoon = l.ShadeAfternoon;
     ShadeMidday    = l.ShadeMidday;
     ShadeMorning   = l.ShadeMorning;
 }
        ObjectModMeta DeleteLocationOutdoorAuthorization(LocationOutdoor obj)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);

            if (meta.CQR > 7 && !currentUser.IsInRole("ModAdmin"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: Only Admin Moderators can delete places with CQR higher than 7");
            }
            else if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: Only Senior Moderators can delete places with CQR higher than 1");
            }
            else if (!currentUser.IsInRole("ModAdmin,ModSenior,ModCommunity"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: You must be Moderator to delete places");
            }

            return meta;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public LocationOutdoor CreateLocationOutdoor(LocationOutdoor obj)
        {
            var user = CfPerfCache.GetClimber(CfIdentity.UserID);

            CreateLocationOutdoorAuthorization(obj);

            obj.NameUrlPart = obj.Name.ToUrlFriendlyString();

            locOutdoorRepo.Create(obj);
            var modPlaceDetail = objModMetaRepo.Create(new ObjectModMeta(obj, currentUser.UserID));

            //-- Update the cache
            AppLookups.AddIndexEntryToCache(obj.ToCacheIndexEntry());

            ClaimObject(obj);

            //-- Save post for the feed
            //PostService.CreateLocationCreatedPost(obj);

            var action = SaveModActionAndUpdateModProfile(ModActionType.LocationOutdoorAdd, null, obj, modPlaceDetail,
                 (m, actionID) => m.SetCreated(actionID), mp => mp.PlacesAdded++, "added {0} {1}", obj.Type, obj.Name);

            postSvc.CreateContentAddPost(action, obj.ID, user.PrivacyPostsDefaultIsPublic);

            //-- Shoot off a notification to moderators

            return obj;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="original"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        public LocationOutdoor UpdateLocationOutdoor(LocationOutdoor original, LocationOutdoor updated)
        {
            var meta = UpdateLocationOutdoorAuthorization(original, updated);

            if (!original.Equals(updated))
            {
                locOutdoorRepo.Update(updated);

                //-- Refresh the cache
                AppLookups.UpdateIndexEntryInCache(updated.ToCacheIndexEntry());

                var action = SaveModActionAndUpdateModProfile(ModActionType.LocationOutdoorEdit, original, updated, meta,
                    (m, actionID) => m.SetDetailsChanged(actionID),
                    null, "edited {0} {1}", updated.Type, updated.Name);

                postSvc.UpdateContentAddPost(action);
            }

            return updated;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        public void DeleteLocationOutdoor(LocationOutdoor obj)
        {
            var meta = DeleteLocationOutdoorAuthorization(obj);

            locOutdoorRepo.Delete(obj.ID);

            //-- Update the cache
            AppLookups.RemoveCacheIndexEntry(obj.ID);

            var modWhoAddedArea = modProfileRepo.GetByID(meta.CreatedByUserID);
            if (modWhoAddedArea.PlacesAdded > 0)
            {
                modWhoAddedArea.PlacesAdded--;
                modProfileRepo.Update(modWhoAddedArea);

                //-- Remove the points associated with this place
                var actionsWithPoints = modActionRepo.GetAll().Where(a => a.OnObjectID == meta.ID);
                ReverseActions(actionsWithPoints);
            }

            //-- update the principal details with the details we just updated (if they are the same person who deleted it)
            CfPrincipal.AttachModProfile(modProfileRepo.GetByID(currentUser.UserID));

            meta.Name = obj.VerboseDisplayName;

            var action = SaveModActionAndUpdateModProfile(ModActionType.LocationOutdoorDelete, obj, null, meta,
                     (m, actionID) => m.SetDeleted(actionID), null, "deleted {0} {1}", obj.Type, obj.Name);

            postSvc.DeleteContentAddPost(action);
        }
        ObjectModMeta UpdateLocationOutdoorAuthorization(LocationOutdoor original, LocationOutdoor updated)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(original);

            if ((original.ID != updated.ID) || (original.CountryID != updated.CountryID))
            {
                throw new ArgumentException(string.Format("Original outdoor location {0}[{1}][{2}] is not the same as updated {3}[{4}][{5}]",
                    original.Name, original.CountryID, original.ID, updated.Name, updated.CountryID, updated.ID));
            }

            if ((original.Latitude != updated.Latitude) || (original.Longitude != updated.Longitude))
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationOutdoor[" + original.ID + "]: Only Senior Moderators can change the position of a verified outdoor location.");
                }
            }

            if (original.Name != updated.Name)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationOutdoor[" + original.ID + "]: Only Senior Moderators can change the name of an outdoor location that has already been verified.");
                }
            }

            if ((original.Description != updated.Description) && meta.CQR > 6)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationOutdoor[" + original.ID + "]: Only Senior Moderators can change the description of an outdoor location that has been verified and has a high CQR.");
                }
            }

            return meta;
        }
        ObjectModMeta SaveLocationOutdoorAvatarAuthorization(LocationOutdoor obj, Stream stream, ImageCropOpts cropOpts)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);

            if (meta.VerifiedAvatar > 1 && !currentUser.IsInRole("ModAdmin,ModSenior"))
            {
                throw new AccessViolationException("SaveLocationOutdoorClimbingImage: Only Senior Moderators can change images that have already been verified by other users");
            }

            return meta;
        }