コード例 #1
0
        void AccountGalleriesSettings_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            GallerySettings settings = new GallerySettings(core, Owner);

            settings.Update();

            this.SetInformation("Gallery Settings Saved");
        }
コード例 #2
0
        public static GallerySettings Create(Core core, Primitive owner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            InsertQuery iQuery = new InsertQuery(GetTable(typeof(GallerySettings)));
            iQuery.AddField("gallery_item_id", owner.Id);
            iQuery.AddField("gallery_item_type_id", owner.TypeId);
            iQuery.AddField("gallery_items", 0);
            iQuery.AddField("gallery_items_root", 0);
            iQuery.AddField("gallery_comments", 0);
            iQuery.AddField("gallery_bytes", 0);
            iQuery.AddField("gallery_allow_items_root", false);

            long settingsId = core.Db.Query(iQuery);

            GallerySettings settings = new GallerySettings(core, settingsId);

            if (owner is User)
            {
                Access.CreateAllGrantsForOwner(core, settings);
                settings.Access.CreateGrantForPrimitive(Friend.GetFriendsGroupKey(core), "VIEW", "VIEW_ITEMS", "COMMENT", "COMMENT_ITEMS", "RATE_ITEMS");
                settings.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW", "VIEW_ITEMS");
            }
            if (owner is UserGroup)
            {
                settings.Access.CreateAllGrantsForPrimitive(UserGroup.GetGroupOperatorsGroupKey(core));
                settings.Access.CreateGrantForPrimitive(UserGroup.GetGroupMembersGroupKey(core), "VIEW", "VIEW_ITEMS", "COMMENT", "COMMENT_ITEMS", "RATE_ITEMS", "CREATE_ITEMS");
                settings.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW", "VIEW_ITEMS");
            }
            if (owner is Musician.Musician)
            {
                settings.Access.CreateAllGrantsForPrimitive(Musician.Musician.GetMusicianMembersGroupKey(core));
                settings.Access.CreateGrantForPrimitive(Musician.Musician.GetMusicianFansGroupKey(core), "VIEW", "VIEW_ITEMS", "COMMENT", "COMMENT_ITEMS", "RATE_ITEMS", "CREATE_ITEMS");
                settings.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW", "VIEW_ITEMS");
            }
            if (owner is Network)
            {
                settings.Access.CreateGrantForPrimitive(Network.GetNetworkMembersGroupKey(core), "VIEW", "VIEW_ITEMS", "COMMENT", "COMMENT_ITEMS", "RATE_ITEMS", "CREATE_ITEMS");
                settings.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW", "VIEW_ITEMS");
            }
            if (owner is ApplicationEntry)
            {
                settings.Access.CreateAllGrantsForPrimitive(ApplicationEntry.GetApplicationDevelopersGroupKey(core));
                settings.Access.CreateGrantForPrimitive(User.GetRegisteredUsersGroupKey(core), "VIEW", "VIEW_ITEMS", "COMMENT", "COMMENT_ITEMS", "RATE_ITEMS");
                settings.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW", "VIEW_ITEMS");
            }

            return settings;
        }
コード例 #3
0
        void AccountGalleriesSettings_Show(object sender, EventArgs e)
        {
            SetTemplate("account_galleries_settings");

            Save(new EventHandler(AccountGalleriesSettings_Save));

            GallerySettings settings;
            try
            {
                settings = new GallerySettings(core, Owner);
            }
            catch (InvalidGallerySettingsException)
            {
                GallerySettings.Create(core, Owner);
                settings = new GallerySettings(core, Owner);
            }
        }
コード例 #4
0
ファイル: Gallery.cs プロジェクト: smithydll/boxsocial
        /// <summary>
        /// Initialises a new instance of the Gallery class.
        /// </summary>
        /// <param name="core">Core token</param>
        /// <param name="settings">Gallery Settings</param>
        public Gallery(Core core, GallerySettings settings)
            : base(core)
        {
            this.settings = settings;
            this.owner = settings.Owner;
            this.ownerKey = owner.ItemKey;

            galleryId = 0;
            path = "";
            parentPath = "";

            if (owner is User)
            {
                userId = owner.Id;
            }
        }
コード例 #5
0
ファイル: Gallery.cs プロジェクト: smithydll/boxsocial
        /// <summary>
        /// Creates a new gallery for the logged in user.
        /// </summary>
        /// <param name="core">Core token</param>
        /// <param name="parent">Parent gallery</param>
        /// <param name="title">Gallery title</param>
        /// <param name="slug">Gallery slug</param>
        /// <param name="description">Gallery description</param>
        /// <param name="permissions">Gallery permission mask</param>
        /// <returns>An instance of the newly created gallery</returns>
        public static Gallery Create(Core core, Primitive owner, Gallery parent, string title, ref string slug, string description)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            GallerySettings settings = null;
            try
            {
                settings = new GallerySettings(core, owner);
            }
            catch (InvalidGallerySettingsException)
            {
                settings = GallerySettings.Create(core, owner);
            }

            string parents = "";
            // ensure we have generated a valid slug
            slug = Gallery.GetSlugFromTitle(title, slug);

            if (!Gallery.CheckGallerySlugValid(slug))
            {
                throw new GallerySlugNotValidException();
            }

            if (!Gallery.CheckGallerySlugUnique(core.Db, parent.owner, parent.FullPath, slug))
            {
                throw new GallerySlugNotUniqueException();
            }

            if (parent != null)
            {
                ParentTree parentTree = new ParentTree();

                if (parent.Parents != null)
                {
                    foreach (ParentTreeNode ptn in parent.Parents.Nodes)
                    {
                        parentTree.Nodes.Add(new ParentTreeNode(ptn.ParentTitle, ptn.ParentSlug, ptn.ParentId));
                    }
                }

                if (parent.Id > 0)
                {
                    parentTree.Nodes.Add(new ParentTreeNode(parent.GalleryTitle, parent.Path, parent.Id));
                }

                XmlSerializer xs = new XmlSerializer(typeof(ParentTree));
                StringBuilder sb = new StringBuilder();
                StringWriter stw = new StringWriter(sb);

                xs.Serialize(stw, parentTree);
                stw.Flush();
                stw.Close();

                parents = sb.ToString();
            }

            InsertQuery iQuery = new InsertQuery("user_galleries");
            iQuery.AddField("gallery_title", title);
            iQuery.AddField("gallery_abstract", description);
            iQuery.AddField("gallery_path", slug);
            iQuery.AddField("gallery_parent_path", parent.FullPath);
            iQuery.AddField("user_id", core.LoggedInMemberId);
            iQuery.AddField("settings_id", settings.Id);
            iQuery.AddField("gallery_item_id", owner.Id);
            iQuery.AddField("gallery_item_type_id", owner.TypeId);
            iQuery.AddField("gallery_parent_id", parent.GalleryId);
            iQuery.AddField("gallery_bytes", 0);
            iQuery.AddField("gallery_items", 0);
            iQuery.AddField("gallery_item_comments", 0);
            iQuery.AddField("gallery_visits", 0);
            iQuery.AddField("gallery_hierarchy", parents);

            long galleryId = core.Db.Query(iQuery);

            Gallery gallery = new Gallery(core, owner, galleryId);

            /* LOAD THE DEFAULT ITEM PERMISSIONS */
            Access.CreateAllGrantsForOwner(core, gallery);
            Access.CreateGrantForPrimitive(core, gallery, User.GetEveryoneGroupKey(core), "VIEW");
            Access.CreateGrantForPrimitive(core, gallery, Friend.GetFriendsGroupKey(core), "COMMENT");
            Access.CreateGrantForPrimitive(core, gallery, User.GetEveryoneGroupKey(core), "VIEW_ITEMS");
            Access.CreateGrantForPrimitive(core, gallery, Friend.GetFriendsGroupKey(core), "COMMENT_ITEMS");
            Access.CreateGrantForPrimitive(core, gallery, Friend.GetFriendsGroupKey(core), "RATE_ITEMS");

            return gallery;
        }