Sửa Workflow trong MojoPortal


MojoPortal đã thiết kế sẵn trường “DraftEditOnlyRoles” của bảng Pages và “DraftEditRoles” của bảng Modules. Đây là 2 quyền cho phép User chỉ có quyền được viết Draft và sửa Draft của mình.

– Đầu tiên chúng ta cần sửa lại ModuleTile để cho phép những User có quyền được viết Draft có thể nhìn thấy Link Add/Edit.

– Cấu hình Cho phép người sử dụng vào phần thêm bài mới.

– Cho phép những User có quyền EditDraft được sửa các bài Draft của mình.

1. Cho phép Role Draft thấy link Add/Edit:

Ta sẽ sửa File CS: mojoPortal.Web\Controls\SiteModuleControl.cs .

<những phần màu đỏ là những phần thêm vào trong Code>

namespace mojoPortal.Web

{

#if !MONO

public abstract class SiteModuleControl : mojoUserControl, IWebPart

#else

public abstract class SiteModuleControl : UserControl

#endif

{

private Module moduleConfiguration;

private bool isEditable = false;

//sử dụng biến isAddNew để kiểm tra xem User có thuộc Roles có quyền //được viết Draft trong Page hoặc Module hay không.

private bool isAddNew = false;

private bool forbidModuleSettings = false;

private int siteID = -1;

private Hashtable settings;

private bool renderInWebPartMode = false;

private string imageSiteRoot = string.Empty;

private bool isSiteEditor = false;

private bool enableWorkflow = false;

private bool IsOnInitExecuted = false;

protected PageSettings currentPage;

protected SiteSettings siteSettings;

protected ScriptManager ScriptController;

protected override void OnInit(EventArgs e)

{

// Alexander Yushchenko: workaround to make old custom modules work

// Before 03.19.2007 this method was “new” and called from descendant classes

// To avoid multiple self-calls a boolean flag is used

if (IsOnInitExecuted) return;

IsOnInitExecuted = true;

base.OnInit(e);

if (HttpContext.Current == null) { return; }

siteSettings = CacheHelper.GetCurrentSiteSettings();

currentPage = CacheHelper.GetCurrentPage();

ScriptController = (ScriptManager)Page.Master.FindControl(“ScriptManager1”);

if (siteSettings != null)

{

this.siteID = siteSettings.SiteId;

if (!WebUser.IsAdminOrContentAdmin)

{

forbidModuleSettings = WebUser.IsInRoles(siteSettings.RolesNotAllowedToEditModuleSettings);

}

}

if (Page.Request.IsAuthenticated)

{

isSiteEditor = SiteUtils.UserIsSiteEditor();

if (WebUser.IsAdminOrContentAdmin || isSiteEditor || WebUser.IsInRoles(currentPage.EditRoles)

|| ((moduleConfiguration != null)

&& (WebUser.IsInRoles(moduleConfiguration.AuthorizedEditRoles))

)

)

{

isEditable = true;

}

// kiểm tra User có quyền được DraftEditRoles trong Page hoặc Module:

if (WebUser.IsInRoles(currentPage.DraftEditOnlyRoles)

|| ((moduleConfiguration != null)

&& (WebUser.IsInRoles(moduleConfiguration.DraftEditRoles))

)

)

{

isAddNew = true;

}

if (WebConfigSettings.EnableContentWorkflow && siteSettings.EnableContentWorkflow && (this is IWorkflow))

{

enableWorkflow = true;

if (!isEditable)

{

if ((WebUser.IsInRoles(currentPage.DraftEditOnlyRoles)) || (WebUser.IsInRoles(moduleConfiguration.DraftEditRoles)))

{

isEditable = true;

}

}

}

if (!isEditable && (moduleConfiguration != null) && (moduleConfiguration.EditUserId > 0))

{

SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

if (

(siteUser != null)

&&(moduleConfiguration.EditUserId == siteUser.UserId)

)

{

isEditable = true;

}

}

}

if (moduleConfiguration != null)

{

this.m_title = moduleConfiguration.ModuleTitle;

this.m_description = moduleConfiguration.FeatureName;

}

}

#if !MONO

[Personalizable(PersonalizationScope.Shared)]

#endif

public bool RenderInWebPartMode

{

get { return renderInWebPartMode; }

set { renderInWebPartMode = value; }

}

#if !MONO

[Personalizable(PersonalizationScope.Shared)]

#endif

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public int ModuleId

{

get { return moduleConfiguration == null ? 0 : moduleConfiguration.ModuleId; }

set

{

if (moduleConfiguration == null) moduleConfiguration = new Module(value);

moduleConfiguration.ModuleId = value;

}

}

public Guid ModuleGuid

{

get { return moduleConfiguration == null ? Guid.Empty : moduleConfiguration.ModuleGuid; }

set

{

if (moduleConfiguration == null) moduleConfiguration = new Module(value);

moduleConfiguration.ModuleGuid = value;

}

}

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public int PageId

{

get { return moduleConfiguration == null ? 0 : moduleConfiguration.PageId; }

}

public string SiteRoot

{

get

{

if ((siteSettings != null)

&&(siteSettings.SiteFolderName.Length > 0))

{

return siteSettings.SiteRoot;

}

return WebUtils.GetSiteRoot();

}

}

public string ImageSiteRoot

{

get

{

if (imageSiteRoot.Length == 0)

{

imageSiteRoot = WebUtils.GetSiteRoot();

}

return imageSiteRoot;

}

}

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public int SiteId

{

get { return siteID; }

set { siteID = value; }

}

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public bool IsEditable

{

get { return isEditable; }

}

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public bool IsAddNew

{

get { return isAddNew; }

}

public bool ForbidModuleSettings

{

get { return forbidModuleSettings; }

}

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public bool EnableWorkflow

{

get { return enableWorkflow; }

}

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public Module ModuleConfiguration

{

get { return moduleConfiguration; }

set { moduleConfiguration = value; }

}

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public Hashtable Settings

{

get

{

if (settings == null) settings = ModuleSettings.GetModuleSettings(ModuleId);

return settings;

}

}

#region IWebPart Members

private string m_title = String.Empty;

private string m_subTitle = String.Empty;

private string m_description = String.Empty;

private string m_titleUrl = String.Empty;

private string m_titleIconImageUrl = String.Empty;

private string m_catalogIconImageUrl = String.Empty;

// Title

public string Title

{

get

{

return m_title;

}

set

{

m_title = value;

}

}

// Subtitle

public string Subtitle

{

get

{

return m_subTitle;

}

set

{

m_subTitle = value;

}

}

// Description

public string Description

{

get

{

return m_description;

}

set

{

m_description = value;

}

}

// TitleUrl

public string TitleUrl

{

get

{

return m_titleUrl;

}

set

{

m_titleUrl = value;

}

}

// TitleIconImageUrl

public string TitleIconImageUrl

{

get

{

return m_titleIconImageUrl;

}

set

{

m_titleIconImageUrl = value;

}

}

// CatalogIconImageUrl

public string CatalogIconImageUrl

{

get

{

return m_catalogIconImageUrl;

}

set

{

m_catalogIconImageUrl = value;

}

}

#endregion

}

}

Sửa file CS: mojoPortal.Web\Controls\ModuleTitleControl.cs

<những phần màu đỏ là những phần thêm vào trong Code>

namespace mojoPortal.Web.UI

{

public class ModuleTitleControl : WebControl, INamingContainer

{

#region Constructors

public ModuleTitleControl()

{

//if (this.Site != null && this.Site.DesignMode)

//{

// this.Visible = false;

// return;

//}

if (HttpContext.Current == null) { return; }

EnsureChildControls();

}

#endregion

#region Control Declarations

protected Literal litModuleTitle;

protected HyperLink lnkModuleSettings;

protected HyperLink lnkModuleEdit;

protected ImageButton ibPostDraftContentForApproval;

protected ImageButton ibApproveContent;

protected HyperLink lnkRejectContent;

protected ImageButton ibCancelChanges;

protected ClueTipHelpLink statusLink;

#endregion

private string literalExtraMarkup = string.Empty;

private bool disabledModuleSettingsLink = false;

private Module module = null;

private string editUrl = string.Empty;

private string editText = string.Empty;

//private bool useHTag = true;

private bool canEdit = false;

//khai báo biến canAdd cho phép hiển thị Link Add/Edit

private bool canAdd = false;

private bool forbidModuleSettings = false;

private bool showEditLinkOverride = false;

private bool enableWorkflow = false;

private SiteModuleControl siteModule = null;

private ContentWorkflowStatus workflowStatus = ContentWorkflowStatus.None;

private string siteRoot = string.Empty;

private bool isAdminEditor = false;

private bool useHeading = true;

private string columnId = UIHelper.CenterColumnId;

private string artHeader = UIHelper.ArtisteerPostMetaHeader;

private string artHeadingCss = UIHelper.ArtPostHeader;

#region Public Properties

public Module ModuleInstance

{

get { return module; }

set { module = value; }

}

public string LiteralExtraMarkup

{

get { return literalExtraMarkup; }

set { literalExtraMarkup = value; }

}

public string EditUrl

{

get { return editUrl; }

set { editUrl = value; }

}

public string EditText

{

get { return editText; }

set { editText = value; }

}

public bool UseHeading

{

get { return useHeading; }

set { useHeading = value; }

}

public bool DisabledModuleSettingsLink

{

get { return disabledModuleSettingsLink; }

set { disabledModuleSettingsLink = value; }

}

public bool CanEdit

{

get { return canEdit; }

set { canEdit = value; }

}

public bool CanAdd

{

get { return canAdd; }

set { canAdd = value; }

}

public bool IsAdminEditor

{

get { return isAdminEditor; }

set { isAdminEditor = value; }

}

public bool ShowEditLinkOverride

{

get { return showEditLinkOverride; }

set { showEditLinkOverride = value; }

}

public ContentWorkflowStatus WorkflowStatus

{

get { return workflowStatus; }

set { workflowStatus = value; }

}

private bool renderArtisteer = false;

public bool RenderArtisteer

{

get { return renderArtisteer; }

set { renderArtisteer = value; }

}

private bool useLowerCaseArtisteerClasses = false;

public bool UseLowerCaseArtisteerClasses

{

get { return useLowerCaseArtisteerClasses; }

set { useLowerCaseArtisteerClasses = value; }

}

#endregion

private SiteModuleControl GetParentAsSiteModelControl(Control child)

{

if (HttpContext.Current == null) { return null; }

if (child.Parent == null)

{

return null;

}

else if (child.Parent is SiteModuleControl)

{

return child.Parent as SiteModuleControl;

}

else

{

return GetParentAsSiteModelControl(child.Parent);

}

}

protected override void Render(HtmlTextWriter writer)

{

if (HttpContext.Current == null)

{

writer.Write(“[” + this.ID + “]”);

return;

}

else

{

if ((useHeading)&&(renderArtisteer))

{

writer.Write(“<div class=\”” + artHeader + “\”>\n”);

if ((artHeader == UIHelper.ArtisteerBlockHeader)||(artHeader == UIHelper.ArtisteerBlockHeaderLower))

{

writer.Write(“<div class=\”l\”></div>”);

writer.Write(“<div class=\”r\”></div>”);

writer.Write(“<div class=\”art-header-tag-icon\”>”);

writer.Write(“<div class=\”t\”>”);

}

}

if (module != null)

{

writer.Write(“<a id=’module” + module.ModuleId.ToString(CultureInfo.InvariantCulture) + “‘></a>”);

}

string headingTag = WebConfigSettings.ModuleTitleTag;

if ((useHeading)&&(headingTag.Length > 0))

{

writer.WriteBeginTag(headingTag);

writer.WriteAttribute(“class”, artHeadingCss + ” moduletitle”);

writer.Write(HtmlTextWriter.TagRightChar);

}

litModuleTitle.RenderControl(writer);

if (CanEdit)

{

if (!forbidModuleSettings)

{

writer.Write(HtmlTextWriter.SpaceChar);

lnkModuleSettings.RenderControl(writer);

}

if (ibCancelChanges != null && ibCancelChanges.Visible)

{

writer.Write(HtmlTextWriter.SpaceChar);

ibCancelChanges.RenderControl(writer);

}

if (ibPostDraftContentForApproval != null && ibPostDraftContentForApproval.Visible)

{

writer.Write(HtmlTextWriter.SpaceChar);

ibPostDraftContentForApproval.RenderControl(writer);

}

if (lnkRejectContent != null && lnkRejectContent.Visible)

{

writer.Write(HtmlTextWriter.SpaceChar);

lnkRejectContent.RenderControl(writer);

}

if (ibApproveContent != null && ibApproveContent.Visible)

{

writer.Write(HtmlTextWriter.SpaceChar);

ibApproveContent.RenderControl(writer);

}

if (statusLink != null && statusLink.Visible)

{

writer.Write(HtmlTextWriter.SpaceChar);

statusLink.ToolTip = Resource.WorkflowStatus;

statusLink.RenderControl(writer);

}

}

if (

(lnkModuleEdit != null)

&& (EditUrl != null)

&& (EditText != null)

)

{

writer.Write(HtmlTextWriter.SpaceChar);

lnkModuleEdit.RenderControl(writer);

}

if (literalExtraMarkup.Length > 0)

{

writer.Write(literalExtraMarkup);

}

if ((useHeading)&&(headingTag.Length > 0))

{

writer.WriteEndTag(headingTag);

}

if ((useHeading) && (renderArtisteer))

{

writer.Write(“</div>”);

if ((artHeader == UIHelper.ArtisteerBlockHeader) || (artHeader == UIHelper.ArtisteerBlockHeaderLower))

{

writer.Write(“</div>”);

writer.Write(“</div>”);

}

}

}

}

void ibApproveContent_Click(object sender, ImageClickEventArgs e)

{

SiteModuleControl siteModule = GetParentAsSiteModelControl(this);

if (siteModule == null) { return; }

if (!(siteModule is IWorkflow)) { return; }

IWorkflow workflow = siteModule as IWorkflow;

workflow.Approve();

}

protected void ibPostDraftContentForApproval_Click(object sender, ImageClickEventArgs e)

{

SiteModuleControl siteModule = GetParentAsSiteModelControl(this);

if (siteModule == null) { return; }

if (!(siteModule is IWorkflow)) { return; }

IWorkflow workflow = siteModule as IWorkflow;

workflow.SubmitForApproval();

}

protected void ibCancelChanges_Click(object sender, ImageClickEventArgs e)

{

SiteModuleControl siteModule = GetParentAsSiteModelControl(this);

if (siteModule == null) { return; }

if (!(siteModule is IWorkflow)) { return; }

IWorkflow workflow = siteModule as IWorkflow;

workflow.CancelChanges();

}

protected override void OnPreRender(EventArgs e)

{

base.OnPreRender(e);

if (HttpContext.Current == null) { return; }

if ((useHeading) && (renderArtisteer))

{

columnId = this.GetColumnId();

if (useLowerCaseArtisteerClasses)

{

artHeader = UIHelper.ArtisteerPostMetaHeaderLower;

artHeadingCss = UIHelper.ArtPostHeaderLower;

}

switch (columnId)

{

case UIHelper.LeftColumnId:

case UIHelper.RightColumnId:

if (useLowerCaseArtisteerClasses)

{

if ((artHeader == UIHelper.ArtisteerPostMetaHeader)||(artHeader == UIHelper.ArtisteerPostMetaHeaderLower))

{

artHeader = UIHelper.ArtisteerBlockHeaderLower;

}

}

else

{

if (artHeader == UIHelper.ArtisteerPostMetaHeader)

{

artHeader = UIHelper.ArtisteerBlockHeader;

}

}

artHeadingCss = string.Empty;

break;

case UIHelper.CenterColumnId:

default:

break;

}

}

Initialize();

}

private void Initialize()

{

if (HttpContext.Current == null) { return; }

siteModule = GetParentAsSiteModelControl(this);

bool useTextLinksForFeatureSettings = true;

mojoBasePage basePage = Page as mojoBasePage;

if (basePage != null)

{

useTextLinksForFeatureSettings = basePage.UseTextLinksForFeatureSettings;

}

if (siteModule != null)

{

module = siteModule.ModuleConfiguration;

CanEdit = siteModule.IsEditable;

CanAdd = siteModule.IsAddNew;

enableWorkflow = siteModule.EnableWorkflow;

forbidModuleSettings = siteModule.ForbidModuleSettings;

}

if (module != null)

{

if (module.ShowTitle)

{

litModuleTitle.Text = Page.Server.HtmlEncode(module.ModuleTitle);

}

else

{

useHeading = false;

}

if (CanEdit)

{

if (!disabledModuleSettingsLink)

{

lnkModuleSettings.Visible = true;

lnkModuleSettings.Text = Resource.SettingsLink;

lnkModuleSettings.ToolTip = Resource.ModuleEditSettings;

if (!useTextLinksForFeatureSettings)

{

lnkModuleSettings.ImageUrl = Page.ResolveUrl(“~/Data/SiteImages/” + WebConfigSettings.EditPropertiesImage);

}

else

{

// if its a text link make it small like the edit link

lnkModuleSettings.CssClass = “ModuleEditLink”;

}

siteRoot = SiteUtils.GetNavigationSiteRoot();

lnkModuleSettings.NavigateUrl = siteRoot

+ “/Admin/ModuleSettings.aspx?mid=” + module.ModuleId.ToInvariantString()

+ “&pageid=” + module.PageId.ToInvariantString();

if ((enableWorkflow) && (siteModule != null) && (siteModule is IWorkflow))

{

SetupWorkflowControls();

}

}

}

// thêm CanAdd=true thì sẽ hiện Link Add/Edit

if (

((CanEdit) || (ShowEditLinkOverride) || (CanAdd))

&& ((EditText != null) && (EditUrl != null)))

{

lnkModuleEdit.Text = EditText;

if (this.ToolTip.Length > 0)

{

lnkModuleEdit.ToolTip = this.ToolTip;

}

else

{

lnkModuleEdit.ToolTip = EditText;

}

lnkModuleEdit.NavigateUrl = EditUrl

+ “?mid=” + module.ModuleId.ToInvariantString()

+ “&pageid=” + module.PageId.ToInvariantString();

if (!useTextLinksForFeatureSettings)

{

lnkModuleEdit.ImageUrl = Page.ResolveUrl(“~/Data/SiteImages/” + WebConfigSettings.EditContentImage);

}

}

}

}

private void SetupWorkflowControls()

{

if (HttpContext.Current == null) { return; }

if (siteModule == null) { return; }

if (module == null) { return; }

CmsPage cmsPage = this.Page as CmsPage;

if ((cmsPage != null) && (cmsPage.ViewMode == PageViewMode.WorkInProgress))

{

switch (workflowStatus)

{

case ContentWorkflowStatus.Draft:

ibPostDraftContentForApproval.ImageUrl = Page.ResolveUrl(WebConfigSettings.RequestApprovalImage);

ibPostDraftContentForApproval.ToolTip = Resource.RequestApprovalToolTip;

ibPostDraftContentForApproval.Visible = true;

statusLink.HelpKey = “workflowstatus-draft-help”;

break;

case ContentWorkflowStatus.AwaitingApproval:

//if (WebUser.IsAdminOrContentAdminOrContentPublisher)

if(

(cmsPage.CurrentPage != null)

&&(

(isAdminEditor || WebUser.IsInRoles(cmsPage.CurrentPage.EditRoles)) || (WebUser.IsInRoles(this.module.AuthorizedEditRoles))

)

)

{

//add in the reject and approve links:

ibApproveContent.ImageUrl = Page.ResolveUrl(WebConfigSettings.ApproveContentImage);

ibApproveContent.Visible = true;

ibApproveContent.ToolTip = Resource.ApproveContentToolTip;

lnkRejectContent.NavigateUrl =

siteRoot

+ “/Admin/RejectContent.aspx?mid=” + module.ModuleId.ToInvariantString()

+ “&pageid=” + module.PageId.ToInvariantString();

lnkRejectContent.ImageUrl = Page.ResolveUrl(WebConfigSettings.RejectContentImage);

lnkRejectContent.ToolTip = Resource.RejectContentToolTip;

lnkRejectContent.Visible = true;

}

statusLink.HelpKey = “workflowstatus-awaitingapproval-help”;

break;

case ContentWorkflowStatus.ApprovalRejected:

statusLink.HelpKey = “workflowstatus-rejected-help”;

break;

}

if (

(workflowStatus != ContentWorkflowStatus.Cancelled)

&& (workflowStatus != ContentWorkflowStatus.Approved)

&& (workflowStatus != ContentWorkflowStatus.None)

)

{

//allow changes to be cancelled:

ibCancelChanges.ImageUrl = Page.ResolveUrl(WebConfigSettings.CancelContentChangesImage);

ibCancelChanges.ToolTip = Resource.CancelChangesToolTip;

ibCancelChanges.Visible = true;

}

}

}

protected override void CreateChildControls()

{

if (HttpContext.Current == null) { return; }

litModuleTitle = new Literal();

//this.Controls.Add(litModuleTitle);

lnkModuleSettings = new HyperLink();

lnkModuleSettings.CssClass = “modulesettingslink”;

//this.Controls.Add(lnkModuleSettings);

lnkModuleEdit = new HyperLink();

//this.Controls.Add(lnkModuleEdit);

lnkModuleEdit.CssClass = “ModuleEditLink”;

lnkModuleEdit.SkinID = “plain”;

ibPostDraftContentForApproval = new ImageButton();

ibPostDraftContentForApproval.ID = “lbPostDraftContentForApproval”;

ibPostDraftContentForApproval.CssClass = “ModulePostDraftForApprovalLink”;

ibPostDraftContentForApproval.SkinID = “plain”;

ibPostDraftContentForApproval.Visible = false;

ibPostDraftContentForApproval.Click += new ImageClickEventHandler(ibPostDraftContentForApproval_Click);

this.Controls.Add(ibPostDraftContentForApproval);

ibApproveContent = new ImageButton();

ibApproveContent.ID = “ibApproveContent”;

ibApproveContent.CssClass = “ModuleApproveContentLink”;

ibApproveContent.SkinID = “plain”;

ibApproveContent.Visible = false;

ibApproveContent.Click += new ImageClickEventHandler(ibApproveContent_Click);

this.Controls.Add(ibApproveContent);

lnkRejectContent = new HyperLink();

lnkRejectContent.ID = “ibRejectContent”;

lnkRejectContent.CssClass = “ModuleRejectContentLink”;

lnkRejectContent.SkinID = “plain”;

lnkRejectContent.Visible = false;

ibCancelChanges = new ImageButton();

ibCancelChanges.ID = “ibCancelChanges”;

ibCancelChanges.CssClass = “ModuleCancelChangesLink”;

ibCancelChanges.SkinID = “plain”;

ibCancelChanges.Visible = false;

UIHelper.AddConfirmationDialog(ibCancelChanges, Resource.CancelContentChangesButtonWarning);

ibCancelChanges.Click += new ImageClickEventHandler(ibCancelChanges_Click);

this.Controls.Add(ibCancelChanges);

statusLink = new ClueTipHelpLink();

this.Controls.Add(statusLink);

}

}

}

2. Cho phép những User có quyền Draft được vào thêm và sửa bài:

Sửa File CS: Web\Components\MojoBasePage.cs

<phần màu đỏ là được thêm vào>

//Ta sửa lại Method UserCanEditModule, Method này cho phép những User //có Roles Admin hoặc Edit Page và Mudole sẽ trả về true. Ta thêm những //User có Roles Draft của Page và Module cũng trả vè True.

public bool UserCanEditModule(int moduleId)

{

if(!Request.IsAuthenticated)return false;

if (WebUser.IsAdminOrContentAdmin) return true;

if (SiteUtils.UserIsSiteEditor()) { return true; }

if (CurrentPage == null) return false;

bool moduleFoundOnPage = false;

foreach (Module m in CurrentPage.Modules)

{

if (m.ModuleId == moduleId) moduleFoundOnPage = true;

}

if (!moduleFoundOnPage) return false;

if (WebUser.IsInRoles(CurrentPage.EditRoles)) return true;

//

if (WebUser.IsInRoles(CurrentPage.DraftEditOnlyRoles)) return true;

SiteUser currentUser = SiteUtils.GetCurrentSiteUser();

if (currentUser == null) return false;

foreach (Module m in CurrentPage.Modules)

{

if (m.ModuleId == moduleId)

{

if (m.EditUserId == currentUser.UserId) return true;

if (WebUser.IsInRoles(m.AuthorizedEditRoles)) return true;

if (WebUser.IsInRoles(m.DraftEditRoles)) return true;

}

}

return false;

}

//Thêm Method: kiểm tra xem những User có quyền được vào Thêm và Sửa bài có phải là User có Roles Draft hay không, nếu đúng tra về true.

public bool USerCanpublish(int moduleId)

{

if (WebUser.IsAdminOrContentAdmin) return true;

if (SiteUtils.UserIsSiteEditor()) { return true; }

if (WebUser.IsInRoles(CurrentPage.EditRoles)) return true;

//

if (WebUser.IsInRoles(CurrentPage.DraftEditOnlyRoles)) return false;

SiteUser currentUser = SiteUtils.GetCurrentSiteUser();

foreach (Module m in CurrentPage.Modules)

{

if (m.ModuleId == moduleId)

{

if (m.EditUserId == currentUser.UserId) return true;

if (WebUser.IsInRoles(m.AuthorizedEditRoles)) return true;

if (WebUser.IsInRoles(m.DraftEditRoles)) return false;

}

}

return false;

}

Sửa File : mojoPortal.Features.UI\Blog\EditPost.aspx.cs

<phần màu đỏ là được thêm vào>

//sửa trong Page_Load. Sử dụng USerDraft ở trang MojoBasePage.cs

private void Page_Load(object sender, EventArgs e)

{

if (!Request.IsAuthenticated)

{

SiteUtils.RedirectToLoginPage(this);

return;

}

//nếu những User có Roles Draft thì sẽ ẩn đi các control

if (!USerCanpublish(moduleId))

{

chkIsPublished.Visible = false;

chkIsPublished.Checked = false;

btnAddCategory.Visible = false;

txtCategory.Visible = false;

lnkEditCategories.Visible = false;

}

SecurityHelper.DisableBrowserCache();

LoadParams();

if (!UserCanEditModule(moduleId))

{

SiteUtils.RedirectToEditAccessDeniedPage();

return;

}

if (ScriptController != null)

{

ScriptController.RegisterAsyncPostBackControl(btnAddCategory);

}

else

{

log.Error(“ScriptController was null”);

}

LoadSettings();

PopulateLabels();

SetupScripts();

if ((!Page.IsPostBack) && (!Page.IsCallback))

{

if ((Request.UrlReferrer != null) && (hdnReturnUrl.Value.Length == 0))

{

hdnReturnUrl.Value = Request.UrlReferrer.ToString();

lnkCancel.NavigateUrl = Request.UrlReferrer.ToString();

lnkCancel2.NavigateUrl = lnkCancel.NavigateUrl;

lnkCancel3.NavigateUrl = lnkCancel.NavigateUrl;

}

PopulateControls();

PopulateCategories();

BindMeta();

BindMetaLinks();

}

}

//sửa Method LoadParams: những User chỉ có quyền viết Draft thì //sẽ chỉ sửa được các bài viết Draft của mình khi chưa được //publish. Còn nếu như cố gắng vào thì sẽ vào phần thêm mới chứ //không phải sửa.

private void LoadParams()

{

timeOffset = SiteUtils.GetUserTimeOffset();

pageId = WebUtils.ParseInt32FromQueryString(“pageid”, -1);

moduleId = WebUtils.ParseInt32FromQueryString(“mid”, -1);

itemId = WebUtils.ParseInt32FromQueryString(“ItemID”, -1);

restoreGuid = WebUtils.ParseGuidFromQueryString(“r”, restoreGuid);

cacheDependencyKey = “Module-” + moduleId.ToString(CultureInfo.InvariantCulture);

virtualRoot = WebUtils.GetApplicationRoot();

//txtCategory.Text = itemId.ToString();

if (itemId > -1)

{

blog = new Blog(itemId);

bool ispublish = blog.IsPublished;

Guid userGuidBlog;

Guid userGuidCurrent;

SiteUser siteUserCurrent = SiteUtils.GetCurrentSiteUser();

userGuidBlog = blog.UserGuid;

userGuidCurrent = siteUserCurrent.UserGuid;

if (!USerCanpublish(moduleId))

{

if (!userGuidCurrent.Equals(userGuidBlog) || ispublish)

{

itemId = -1;

blog = null;

}

}

}

if (moduleId > -1)

{

moduleSettings = ModuleSettings.GetModuleSettings(moduleId);

if (moduleSettings.Contains(“OdiogoFeedIDSetting”))

OdiogoFeedIDSetting = moduleSettings[“OdiogoFeedIDSetting”].ToString();

}

}

3. Cho phép những User có Roles Draft thì sẽ hiển thị Link EditDraft ở Module Blog khi có bài Draft của người đó, chỉ nhìn được các bài Draft của mình.

Phần này tôi sửa toàn bộ file Drafts.aspx trong: mojoPortal.Features.UI\Blog.

Bạn chạy file ProcedureDraftBlog.sql trong MSSQL

Import 2 file dll: hungtn.Business.dll và hungtn.Data.dll

Sửa lại code theo 3 file Drafts.aspx

Sửa file mojoPortal.Features.UI\Blog\ BlogModule.ascx.cs

Phần này cho phép hiện thị link EditDraft trong Module Blog.

Nếu những User có quyền Draft sẽ thấy link EditDraft nếu số bài trong Draft của người đó >0.

namespace mojoPortal.Web.BlogUI

{

public partial class BlogModule : SiteModuleControl

{

#region Properties

private static readonly ILog log = LogManager.GetLogger(typeof(BlogModule));

private int countOfDrafts = 0;

//đếm số bài Draft của User đăng nhập

private int countOfDraftsCreateByUser = 0;

private int pageNumber = 1;

private int totalPages = 1;

private int pageSize = 10;

private bool showPager = true;

private string instanceCssClass = string.Empty;

protected string addThisAccountId = string.Empty;

protected bool useAddThisMouseOverWidget = true;

protected string addThisCustomBrand = string.Empty;

protected string addThisButtonImageUrl = “~/Data/SiteImages/addthissharebutton.gif”;

protected string addThisCustomOptions = string.Empty;

protected string addThisCustomLogoUrl = string.Empty;

protected string addThisCustomLogoBackColor = string.Empty;

protected string addThisCustomLogoForeColor = string.Empty;

protected string feedburnerFeedUrl = string.Empty;

protected string EditContentImage = WebConfigSettings.EditContentImage;

protected string EditBlogAltText = “Edit”;

protected string BlogDateTimeFormat;

protected string FeedBackLabel;

protected bool ShowCalendar = false;

protected DateTime CalendarDate;

protected bool ShowCategories = false;

protected bool ShowArchives = false;

protected bool AllowComments = true;

protected bool NavigationOnRight = false;

protected bool ShowStatistics = true;

protected bool ShowFeedLinks = true;

protected bool ShowAddFeedLinks = true;

protected bool BlogUseLinkForHeading = true;

protected Double TimeOffset = 0;

protected string GmapApiKey = string.Empty;

protected int GoogleMapHeightSetting = 300;

protected int GoogleMapWidthSetting = 500;

protected bool GoogleMapEnableMapTypeSetting = false;

protected bool GoogleMapEnableZoomSetting = false;

protected bool GoogleMapShowInfoWindowSetting = false;

protected bool GoogleMapEnableLocalSearchSetting = false;

protected bool GoogleMapEnableDirectionsSetting = false;

protected int GoogleMapInitialZoomSetting = 13;

protected MapType mapType = MapType.G_SATELLITE_MAP;

protected string OdiogoFeedIDSetting = string.Empty;

protected bool UseExcerpt = false;

protected bool TitleOnly = false;

protected bool HideAddThisButton = false;

protected int ExcerptLength = 250;

protected string ExcerptSuffix = “…”;

protected string MoreLinkText = “read more”;

protected bool EnableContentRatingSetting = false;

protected bool EnableRatingCommentsSetting = false;

protected bool ShowPostAuthorSetting = false;

protected bool GoogleMapIncludeWithExcerptSetting = false;

protected bool ShowGoogleMap = true;

protected bool BlogUseTagCloudForCategoriesSetting = false;

protected string blogAuthor = string.Empty;

private string CommentSystem = “internal”;

private string DisqusSiteShortName = string.Empty;

protected string disqusFlag = string.Empty;

protected string IntenseDebateAccountId = string.Empty;

protected bool ShowCommentCounts = true;

protected string EditLinkText = BlogResources.BlogEditEntryLink;

protected string EditLinkTooltip = BlogResources.BlogEditEntryLink;

protected string EditLinkImageUrl = string.Empty;

#endregion

protected override void OnInit(EventArgs e)

{

base.OnInit(e);

this.Load += new EventHandler(Page_Load);

this.calBlogNav.SelectionChanged += new EventHandler(calBlogNav_SelectionChanged);

this.calBlogNav.VisibleMonthChanged += new MonthChangedEventHandler(CalBlogNavVisibleMonthChanged);

pgr.Command += new CommandEventHandler(pgr_Command);

this.EnableViewState = false;

}

protected virtual void Page_Load(object sender, EventArgs e)

{

LoadSettings();

SetupCss();

if (!RenderInWebPartMode)

{

SetupRssLink();

}

PopulateLabels();

if (!Page.IsPostBack)

{

PopulateControls();

}

}

private void PopulateControls()

{

BindBlogs();

PopulateNavigation();

}

private void BindBlogs()

{

using (IDataReader reader = Blog.GetPage(ModuleId, CalendarDate.Date.AddDays(1), pageNumber, pageSize, out totalPages))

{

rptBlogs.DataSource = reader;

rptBlogs.DataBind();

pgr.ShowFirstLast = true;

pgr.PageSize = pageSize;

pgr.PageCount = totalPages;

pgr.Visible = (totalPages > 1) && showPager;

}

}

void pgr_Command(object sender, CommandEventArgs e)

{

pageNumber = Convert.ToInt32(e.CommandArgument);

pgr.CurrentIndex = pageNumber;

PopulateControls();

updBlog.Update();

}

protected virtual void PopulateNavigation()

{

Feeds.ModuleSettings = Settings;

Feeds.PageId = PageId;

Feeds.ModuleId = ModuleId;

Feeds.Visible = ShowFeedLinks;

if(this.ShowCategories)

{

tags.CanEdit = IsEditable;

tags.PageId = PageId;

tags.ModuleId = ModuleId;

tags.SiteRoot = SiteRoot;

tags.RenderAsTagCloud = BlogUseTagCloudForCategoriesSetting;

}

else

{

tags.Visible = false;

this.pnlCategories.Visible = false;

}

if(this.ShowArchives)

{

archive.PageId = PageId;

archive.ModuleId = ModuleId;

archive.SiteRoot = SiteRoot;

}

else

{

archive.Visible = false;

this.pnlArchives.Visible = false;

}

stats.PageId = PageId;

stats.ModuleId = ModuleId;

stats.CountOfDrafts = countOfDrafts;

stats.Visible = ShowStatistics;

}

private void calBlogNav_SelectionChanged(object sender, EventArgs e)

{

System.Web.UI.WebControls.Calendar cal = (System.Web.UI.WebControls.Calendar)sender;

CalendarDate = cal.SelectedDate;

calBlogNav.VisibleDate = CalendarDate;

calBlogNav.SelectedDate = CalendarDate;

PopulateControls();

}

private void CalBlogNavVisibleMonthChanged(object sender, MonthChangedEventArgs e)

{

CalendarDate = e.NewDate;

calBlogNav.VisibleDate = CalendarDate;

calBlogNav.SelectedDate = CalendarDate;

PopulateControls();

}

protected virtual void PopulateLabels()

{

Title1.EditUrl = SiteRoot + “/Blog/EditPost.aspx”;

Title1.EditText = BlogResources.BlogAddPostLabel;

SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

//Title1.EditText = countOfDraftsCreateByUser.ToString();

if ((IsEditable) && (countOfDrafts > 0))

{

//BlogEditCategoriesLabel

Title1.LiteralExtraMarkup =

“&nbsp;<a href='”

+ SiteRoot

+ “/Blog/EditCategory.aspx?pageid=” + PageId.ToInvariantString()

+ “&amp;mid=” + ModuleId.ToInvariantString()

+ “‘ class=’ModuleEditLink’ title='” + BlogResources.BlogEditCategoriesLabel + “‘>” + BlogResources.BlogEditCategoriesLabel + “</a>”

+ “&nbsp;<a href='”

+ SiteRoot

+ “/Blog/Drafts.aspx?pageid=” + PageId.ToInvariantString()

+ “&amp;mid=” + ModuleId.ToInvariantString()

+ “‘ class=’ModuleEditLink’ title='” + BlogResources.BlogDraftsLink + “‘>” + BlogResources.BlogDraftsLink + “</a>”;

}

else if (IsEditable)

{

Title1.LiteralExtraMarkup =

“&nbsp;<a href='”

+ SiteRoot

+ “/Blog/EditCategory.aspx?pageid=” + PageId.ToInvariantString()

+ “&amp;mid=” + ModuleId.ToInvariantString()

+ “‘ class=’ModuleEditLink’ title='” + BlogResources.BlogEditCategoriesLabel + “‘>” + BlogResources.BlogEditCategoriesLabel + “</a>”;

}

//kiểm tra nếu những User có quyền Draft và số bài Draft >0 sẽ hiện Link //EditDraft.

if (IsAddNew && (countOfDraftsCreateByUser>0))

{

Title1.LiteralExtraMarkup =

“&nbsp;<a href='”

+ SiteRoot

+ “/Blog/Drafts.aspx?pageid=” + PageId.ToInvariantString()

+ “&amp;mid=” + ModuleId.ToInvariantString()

+ “‘ class=’ModuleEditLink’ title='” + BlogResources.BlogDraftsLink + “‘>” + BlogResources.BlogDraftsLink + “</a>”;

}

calBlogNav.UseAccessibleHeader = true;

EditBlogAltText = BlogResources.EditImageAltText;

FeedBackLabel = BlogResources.BlogFeedbackLabel;

mojoBasePage basePage = Page as mojoBasePage;

if (basePage != null)

{

if (!basePage.UseTextLinksForFeatureSettings)

{

EditLinkImageUrl = ImageSiteRoot + “/Data/SiteImages/” + EditContentImage;

}

}

}

protected string FormatPostAuthor(string authorName)

{

if (ShowPostAuthorSetting)

{

if (blogAuthor.Length > 0)

{

return string.Format(CultureInfo.InvariantCulture,

BlogResources.PostAuthorFormat, blogAuthor);

}

return string.Format(CultureInfo.InvariantCulture,

BlogResources.PostAuthorFormat, authorName);

}

return string.Empty;

}

protected string FormatBlogEntry(string blogHtml, string excerpt, string url, int itemId)

{

if (UseExcerpt)

{

if ((excerpt.Length > 0)&&(excerpt != “<p> </p>”))

{

return excerpt + ExcerptSuffix + ” <a href='” + FormatBlogUrl(url, itemId) + “‘>” + MoreLinkText + “</a><div>&nbsp;</div>”;

}

string result = string.Empty;

if ((blogHtml.Length > ExcerptLength)&&(MoreLinkText.Length > 0))

{

result = UIHelper.CreateExcerpt(blogHtml, ExcerptLength, ExcerptSuffix);

result += ” <a href='” + FormatBlogTitleUrl(url, itemId) + “‘>” + MoreLinkText + “</a><div>&nbsp;</div>”;

return result;

}

}

return blogHtml;

}

protected string FormatBlogUrl(string itemUrl, int itemId)

{

if (itemUrl.Length > 0)

return SiteRoot + itemUrl.Replace(“~”, string.Empty) + disqusFlag;

return SiteRoot + “/Blog/ViewPost.aspx?pageid=” + PageId.ToInvariantString()

+ “&ItemID=” + itemId.ToInvariantString()

+ “&mid=” + ModuleId.ToInvariantString()

+ disqusFlag;

}

protected string FormatBlogTitleUrl(string itemUrl, int itemId)

{

if (itemUrl.Length > 0)

return SiteRoot + itemUrl.Replace(“~”, string.Empty);

return SiteRoot + “/Blog/ViewPost.aspx?pageid=” + PageId.ToInvariantString()

+ “&ItemID=” + itemId.ToInvariantString()

+ “&mid=” + ModuleId.ToInvariantString();

}

private string GetRssUrl()

{

if (feedburnerFeedUrl.Length > 0) return feedburnerFeedUrl;

return SiteRoot + “/blog” + ModuleId.ToInvariantString() + “rss.aspx”;

}

protected virtual void SetupRssLink()

{

if (this.ModuleConfiguration != null)

{

if (Page.Master != null)

{

Control head = Page.Master.FindControl(“Head1”);

if (head != null)

{

Literal rssLink = new Literal();

rssLink.Text = “<link rel=\”alternate\” type=\”application/rss+xml\” title=\””

+ this.ModuleConfiguration.ModuleTitle + “\” href=\””

+ GetRssUrl() + “\” />”;

head.Controls.Add(rssLink);

}

}

}

}

protected virtual void SetupCss()

{

// older skins have this

StyleSheet stylesheet = (StyleSheet)Page.Master.FindControl(“StyleSheet”);

if (stylesheet != null)

{

if (stylesheet.FindControl(“blogcss”) == null)

{

Literal cssLink = new Literal();

cssLink.ID = “blogcss”;

cssLink.Text = “\n<link href='”

+ SiteUtils.GetSkinBaseUrl()

+ “blogmodule.css’ type=’text/css’ rel=’stylesheet’ media=’screen’ />”;

stylesheet.Controls.Add(cssLink);

}

if (stylesheet.FindControl(“aspcalendar”) == null)

{

Literal cssLink = new Literal();

cssLink.ID = “aspcalendar”;

cssLink.Text = “\n<link href='”

+ SiteUtils.GetSkinBaseUrl()

+ “aspcalendar.css’ type=’text/css’ rel=’stylesheet’ media=’screen’ />”;

stylesheet.Controls.Add(cssLink);

}

}

}

protected virtual void LoadSettings()

{

TimeOffset = SiteUtils.GetUserTimeOffset();

GmapApiKey = SiteUtils.GetGmapApiKey();

addThisAccountId = siteSettings.AddThisDotComUsername;

try

{

// this keeps the action from changing during ajax postback in folder based sites

SiteUtils.SetFormAction(Page, Request.RawUrl);

}

catch (MissingMethodException)

{

//this method was introduced in .NET 3.5 SP1

}

pnlContainer.ModuleId = this.ModuleId;

if (this.ModuleConfiguration != null)

{

this.Title = this.ModuleConfiguration.ModuleTitle;

this.Description = this.ModuleConfiguration.FeatureName;

}

if (Page.Request.Params.Get(“blogdate”) != null)

{

//calendarDate = DateTime.Parse(Page.Request.Params.Get(“blogdate”));

DateTimeFormatInfo dtfi = CultureInfo.InvariantCulture.DateTimeFormat;

if (!DateTime.TryParse(Page.Request.Params.Get(“blogdate”), dtfi, DateTimeStyles.AdjustToUniversal, out CalendarDate))

{

CalendarDate = DateTime.UtcNow.Date;

}

}

else

{

CalendarDate = DateTime.UtcNow.Date;

}

if (CalendarDate > DateTime.UtcNow.Date)

{

CalendarDate = DateTime.UtcNow.Date;

}

UseExcerpt = WebUtils.ParseBoolFromHashtable(

Settings, “BlogUseExcerptSetting”, UseExcerpt);

TitleOnly = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowTitleOnlySetting”, TitleOnly);

showPager = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowPagerInListSetting”, showPager);

GoogleMapIncludeWithExcerptSetting = WebUtils.ParseBoolFromHashtable(

Settings, “GoogleMapIncludeWithExcerptSetting”, GoogleMapIncludeWithExcerptSetting);

if ((UseExcerpt) && (!GoogleMapIncludeWithExcerptSetting)) { ShowGoogleMap = false; }

EnableContentRatingSetting = WebUtils.ParseBoolFromHashtable(

Settings, “EnableContentRatingSetting”, EnableContentRatingSetting);

EnableRatingCommentsSetting = WebUtils.ParseBoolFromHashtable(

Settings, “EnableRatingCommentsSetting”, EnableRatingCommentsSetting);

if (UseExcerpt) { EnableContentRatingSetting = false; }

HideAddThisButton = WebUtils.ParseBoolFromHashtable(

Settings, “BlogHideAddThisButtonSetting”, HideAddThisButton);

ExcerptLength = WebUtils.ParseInt32FromHashtable(

Settings, “BlogExcerptLengthSetting”, ExcerptLength);

if (Settings.Contains(“BlogExcerptSuffixSetting”))

{

ExcerptSuffix = Settings[“BlogExcerptSuffixSetting”].ToString();

}

if (Settings.Contains(“BlogMoreLinkText”))

{

MoreLinkText = Settings[“BlogMoreLinkText”].ToString();

}

if (Settings.Contains(“BlogAuthorSetting”))

{

blogAuthor = Settings[“BlogAuthorSetting”].ToString();

}

if (Settings.Contains(“CustomCssClassSetting”))

{

instanceCssClass = Settings[“CustomCssClassSetting”].ToString();

}

if (instanceCssClass.Length > 0) { pnlWrapper.CssClass += ” ” + instanceCssClass; }

BlogDateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern;

if (Settings.Contains(“BlogDateTimeFormat”))

{

BlogDateTimeFormat = Settings[“BlogDateTimeFormat”].ToString().Trim();

if (BlogDateTimeFormat.Length > 0)

{

try

{

string d = DateTime.Now.ToString(BlogDateTimeFormat, CultureInfo.CurrentCulture);

}

catch (FormatException)

{

BlogDateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern;

}

}

else

{

BlogDateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern;

}

}

ShowCalendar = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowCalendarSetting”, false);

ShowCategories = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowCategoriesSetting”, false);

BlogUseTagCloudForCategoriesSetting = WebUtils.ParseBoolFromHashtable(

Settings, “BlogUseTagCloudForCategoriesSetting”, false);

ShowArchives = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowArchiveSetting”, false);

NavigationOnRight = WebUtils.ParseBoolFromHashtable(

Settings, “BlogNavigationOnRightSetting”, false);

ShowStatistics = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowStatisticsSetting”, true);

ShowFeedLinks = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowFeedLinksSetting”, true);

ShowAddFeedLinks = WebUtils.ParseBoolFromHashtable(

Settings, “BlogShowAddFeedLinksSetting”, true);

AllowComments = WebUtils.ParseBoolFromHashtable(

Settings, “BlogAllowComments”, true);

BlogUseLinkForHeading = WebUtils.ParseBoolFromHashtable(

Settings, “BlogUseLinkForHeading”, true);

ShowPostAuthorSetting = WebUtils.ParseBoolFromHashtable(

Settings, “ShowPostAuthorSetting”, ShowPostAuthorSetting);

if (Settings.Contains(“GoogleMapInitialMapTypeSetting”))

{

string gmType = Settings[“GoogleMapInitialMapTypeSetting”].ToString();

try

{

mapType = (MapType)Enum.Parse(typeof(MapType), gmType);

}

catch (ArgumentException) { }

}

GoogleMapHeightSetting = WebUtils.ParseInt32FromHashtable(

Settings, “GoogleMapHeightSetting”, GoogleMapHeightSetting);

GoogleMapWidthSetting = WebUtils.ParseInt32FromHashtable(

Settings, “GoogleMapWidthSetting”, GoogleMapWidthSetting);

GoogleMapEnableMapTypeSetting = WebUtils.ParseBoolFromHashtable(

Settings, “GoogleMapEnableMapTypeSetting”, false);

GoogleMapEnableZoomSetting = WebUtils.ParseBoolFromHashtable(

Settings, “GoogleMapEnableZoomSetting”, false);

GoogleMapShowInfoWindowSetting = WebUtils.ParseBoolFromHashtable(

Settings, “GoogleMapShowInfoWindowSetting”, false);

GoogleMapEnableLocalSearchSetting = WebUtils.ParseBoolFromHashtable(

Settings, “GoogleMapEnableLocalSearchSetting”, false);

GoogleMapEnableDirectionsSetting = WebUtils.ParseBoolFromHashtable(

Settings, “GoogleMapEnableDirectionsSetting”, false);

GoogleMapInitialZoomSetting = WebUtils.ParseInt32FromHashtable(

Settings, “GoogleMapInitialZoomSetting”, GoogleMapInitialZoomSetting);

pageSize = WebUtils.ParseInt32FromHashtable(

Settings, “BlogEntriesToShowSetting”, pageSize);

if (Settings.Contains(“OdiogoFeedIDSetting”))

OdiogoFeedIDSetting = Settings[“OdiogoFeedIDSetting”].ToString();

string altAddThisAccount = string.Empty;

if (Settings.Contains(“BlogAddThisDotComUsernameSetting”))

altAddThisAccount = Settings[“BlogAddThisDotComUsernameSetting”].ToString().Trim();

if (altAddThisAccount.Length > 0)

addThisAccountId = altAddThisAccount;

useAddThisMouseOverWidget = WebUtils.ParseBoolFromHashtable(

Settings, “BlogAddThisDotComUseMouseOverWidgetSetting”, useAddThisMouseOverWidget);

if (Settings.Contains(“BlogAddThisButtonImageUrlSetting”))

addThisButtonImageUrl = Settings[“BlogAddThisButtonImageUrlSetting”].ToString().Trim();

if (addThisButtonImageUrl.Length == 0)

addThisButtonImageUrl = “~/Data/SiteImages/addthissharebutton.gif”;

if (Settings.Contains(“BlogAddThisCustomBrandSetting”))

addThisCustomBrand = Settings[“BlogAddThisCustomBrandSetting”].ToString().Trim();

if (addThisCustomBrand.Length == 0)

addThisCustomBrand = siteSettings.SiteName;

if (Settings.Contains(“BlogAddThisCustomOptionsSetting”))

addThisCustomOptions = Settings[“BlogAddThisCustomOptionsSetting”].ToString().Trim();

if (Settings.Contains(“BlogAddThisCustomLogoUrlSetting”))

addThisCustomLogoUrl = Settings[“BlogAddThisCustomLogoUrlSetting”].ToString().Trim();

if (Settings.Contains(“BlogAddThisCustomLogoBackColorSetting”))

addThisCustomLogoBackColor = Settings[“BlogAddThisCustomLogoBackColorSetting”].ToString().Trim();

if (Settings.Contains(“BlogAddThisCustomLogoForeColorSetting”))

addThisCustomLogoForeColor = Settings[“BlogAddThisCustomLogoForeColorSetting”].ToString().Trim();

if (Settings.Contains(“BlogFeedburnerFeedUrl”))

feedburnerFeedUrl = Settings[“BlogFeedburnerFeedUrl”].ToString().Trim();

if (Settings.Contains(“DisqusSiteShortName”))

{

DisqusSiteShortName = Settings[“DisqusSiteShortName”].ToString();

}

if (Settings.Contains(“CommentSystemSetting”))

{

CommentSystem = Settings[“CommentSystemSetting”].ToString();

}

if (Settings.Contains(“IntenseDebateAccountId”))

{

IntenseDebateAccountId = Settings[“IntenseDebateAccountId”].ToString();

}

if (AllowComments)

{

if ((DisqusSiteShortName.Length > 0) && (CommentSystem == “disqus”))

{

disqusFlag = “#disqus_thread”;

disqus.SiteShortName = DisqusSiteShortName;

disqus.RenderCommentCountScript = true;

stats.ShowCommentCount = false;

}

if ((IntenseDebateAccountId.Length > 0) && (CommentSystem == “intensedebate”))

{

ShowCommentCounts = false;

stats.ShowCommentCount = false;

}

}

if (!this.NavigationOnRight)

{

this.divNav.CssClass = “blognavleft”;

this.divblog.CssClass = “blogcenter-leftnav”;

}

if (ShowCalendar)

{

this.calBlogNav.Visible = true;

try

{

calBlogNav.FirstDayOfWeek = (FirstDayOfWeek)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;

}

catch (ArgumentNullException) { }

catch (ArgumentOutOfRangeException) { }

catch (InvalidOperationException) { }

catch (InvalidCastException) { }

if (!Page.IsPostBack)

{

this.calBlogNav.SelectedDate = CalendarDate;

this.calBlogNav.VisibleDate = CalendarDate;

}

}

else

{

this.calBlogNav.Visible = false;

}

if (Settings.Contains(“BlogCopyrightSetting”))

{

lblCopyright.Text = Settings[“BlogCopyrightSetting”].ToString();

}

pnlStatistics.Visible = ShowStatistics;

divNav.Visible = false;

if (ShowCalendar

|| ShowArchives

|| ShowAddFeedLinks

|| ShowCategories

|| ShowFeedLinks

|| ShowStatistics)

{

divNav.Visible = true;

}

if (!divNav.Visible)

{

divblog.CssClass = “blogcenter-nonav”;

}

if (IsEditable)

{

countOfDrafts = Blog.CountOfDrafts(ModuleId);

}

//

if (IsAddNew)

{

Guid userGuid;

hnt_Blog htn_blog = new hnt_Blog();

SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

userGuid = siteUser.UserGuid;

countOfDraftsCreateByUser = htn_blog.CountOfDraftsCreateByUser(ModuleId, userGuid);

}

}

}

}

Sửa file mojoPortal.Business.WebHelpers\ WebUser.cs:

Thêm 1 Method:

//kiem tra quyen được sửa bài nháp

public static bool HasEditDraftPermissions(int siteId, int moduleId, int pageId)

{

if (HttpContext.Current == null || HttpContext.Current.User == null) return false;

if (!HttpContext.Current.Request.IsAuthenticated) return false;

if (IsAdmin || IsContentAdmin) return true;

Module module = new Module(moduleId, pageId);

PageSettings pageSettings = new PageSettings(siteId, module.PageId);

if (pageSettings == null) return false;

if (pageSettings.PageId < 0) return false;

if (IsInRoles(pageSettings.EditRoles) || IsInRoles(module.AuthorizedEditRoles))

{

return true;

}

if (IsInRoles(pageSettings.DraftEditOnlyRoles) || IsInRoles(module.DraftEditRoles))

{

return true;

}

if (module.EditUserId > 0)

{

SiteSettings siteSettings = (SiteSettings)HttpContext.Current.Items[“SiteSettings”];

SiteUser siteUser = new SiteUser(siteSettings, HttpContext.Current.User.Identity.Name);

if (module.EditUserId == siteUser.UserId)

{

return true;

}

}

return false;

}

About thangletoan

Hallo Aloha

Posted on 08/06/2011, in Công nghệ và Giáo dục, Chính sách CNTT, LOB - Lập trình - Phát triển phần mềm, Microsoft, MojoPortal, Programming, Workflow and tagged , . Bookmark the permalink. Để lại bình luận.

Gửi phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

%d bloggers like this: